Bug #104339 mysqlshell loadDump() needs to load roles before users
Submitted: 16 Jul 2021 13:23 Modified: 2 Oct 2021 16:58
Reporter: IGG t Email Updates:
Status: Closed Impact on me:
None 
Category:Shell Dump & Load Severity:S2 (Serious)
Version:8.0.24, 8.0.25 OS:Windows
Assigned to: CPU Architecture:Any
Tags: roles, users

[16 Jul 2021 13:23] IGG t
Description:
I started to use the util.dumpxxx() and dumpload() features of MySQLShell but when I tried to restore the dump, I got an error that prevented my users being restored.

I believe this is due to incorrect handling of roles in the @.users.sql file.

Looking in here I see all the roles are created using "CREATE USER .." statements and listed in alphabetical order alongside the actual users.

My first user is "andyb@'1.2.3.4' with a default role of "role_dev".

As "a" comes before "r" it fails to create the user as the role doesn't yet exist. 

As this is the first user, no users are created.

How to repeat:
Create a test database containing users and roles, ensuring the roles have names starting (alphabetically) after the users.

e.g. 
create role 'role_dev';
grant select on *.* to 'role_dev';
create user 'alpha'@'%' identified by '123ABC#' DEFAULT ROLE 'role_dev';

Take a dump of the database using

util.dumpInstance("/dbbackups/, {users: true, consistent:true})

on a clean database restore the dump using:

util.loadDump("c:\\dbbackups",{loadUsers: true})

At the end of the restore process you should get the error:

ERROR: While executing user accounts SQL: MySQL Error 3162 (HY000): Authorization ID `role_beta`@`%` does not exist.: CREATE USER IF NOT EXISTS 'alpha'@'1.2.3.4' IDENTIFIED WITH 'mysql_native_password' AS '*******************************' DEFAULT ROLE `role_name`@`%` . . . . .
Util.loadDump: Authorization ID `role_dev`@`%` does not exist. (MYSQLSH 3162)

Suggested fix:
Roles need to be Identified and created before any users are created
[19 Jul 2021 7:25] MySQL Verification Team
Hello!

Thank you for the report and feedback.

Thanks,
Umesh
[2 Oct 2021 16:58] Margaret Fisher
Posted by developer:
 
Changelog entry added for MySQL Shell 8.0.27:

MySQL Shell's dump loading utility util.loadDump() now sets default roles for users after loading GRANT statements, to ensure that all the roles have been created and the appropriate grants have been granted.