Hi serg,
I am not sure I agree. SHOW GRANTS is supposed to show grants, not whether a role is set by default or not.
I agree that it is not a perfect fit for SHOW GRANTS, because you do not use GRANT to set the default role. However, in my opinion, SET DEFAULT ROLE x FOR y is so closely related to GRANT x TO y that it would be logical to add it to the output of SHOW GRANTS.
SHOW CREATE USER looks more appropriate, but it always used to return just one statement, it feels like a big step to change that.
On the other hand, if one wants to recreate the user by replaying SHOW CREATE USER and SHOW GRANTS, a default role has to be set after grants, so it cannot be in SHOW CREATE USER.
Yeah, I agree that it would be problematic to add SET DEFAULT ROLE to the output of SHOW CREATE USER.
A default role is seen in INFORMATION_SCHEMA.APPLICABLE_ROLES, is it not good enough?
It is "good enough" in the sense that the information is available somewhere. However, it is not ideal for the use case that I am analyzing. Let me provide some background.
I am currently working on "data loading" and "migration" procedures that rely on mysqldump. mysqldump backs up user accounts and roles as a series of INSERT statements into the privilege tables. This is not ideal in our environment for various reasons (limited privileges, possibility of accidentally dropping internal user accounts, etc.).
Therefore, mysqldump has to be executed with --all-databases --ignore-database=mysql, and user accounts and roles have to be backed up separately. There are some limitations in MariaDB that make this a bit harder than it needs to be, in my opinion. Here is what I currently need to do:
1.) To create user accounts:
WITH mariadb_users AS (
|
SELECT User, Host, default_role
|
FROM mysql.user
|
WHERE is_role='N'
|
AND User NOT LIKE 'internal_%'
|
AND Super_priv != 'Y'
|
)
|
SELECT CONCAT(
|
'SHOW CREATE USER ''',
|
mariadb_users.User,
|
'''@''',
|
mariadb_users.Host,
|
''';'
|
)
|
FROM mariadb_users
|
This is fine, but not entirely ideal, because:
- Semicolons need to be added to each line of the output.
- The output needs to be re-executed.
2.) To create roles:
WITH mariadb_roles AS (
|
SELECT User
|
FROM mysql.user
|
WHERE is_role='Y'
|
)
|
SELECT CONCAT(
|
'SELECT ''CREATE ROLE ''''',
|
mariadb_roles.User,
|
''''''';'
|
)
|
FROM mariadb_roles
|
This would be a bit cleaner if we had SHOW CREATE ROLE. I reported that as MDEV-22311.
I only wrapped it in the inner SELECT, so that the whole script output can be re-executed, to match the limitations of creating user accounts (#1).
3.) To grant user privileges:
WITH mariadb_users AS (
|
SELECT User, Host, default_role
|
FROM mysql.user
|
WHERE is_role='N'
|
AND User NOT LIKE 'internal_%'
|
AND Super_priv != 'Y'
|
)
|
SELECT CONCAT(
|
'SHOW GRANTS FOR ''',
|
mariadb_users.User,
|
'''@''',
|
mariadb_users.Host,
|
''';'
|
)
|
This has the same draw-backs as creating user accounts (#1):
- Semicolons need to be added to each line of the output.
- The output needs to be re-executed.
3.) To grant role privileges:
WITH mariadb_roles AS (
|
SELECT User
|
FROM mysql.user
|
WHERE is_role='Y'
|
)
|
SELECT CONCAT(
|
'SHOW GRANTS FOR ''',
|
mariadb_roles.User,
|
''';'
|
)
|
This has the same draw-backs as creating user accounts (#1):
- Semicolons need to be added to each line of the output.
- The output needs to be re-executed.
4.) To set default roles:
WITH mariadb_users AS (
|
SELECT User, Host, default_role
|
FROM mysql.user
|
WHERE is_role='N'
|
AND User NOT LIKE 'internal_%'
|
AND Super_priv != 'Y'
|
)
|
SELECT CONCAT (
|
'SELECT ''SET DEFAULT ROLE ''''',
|
mariadb_users.default_role,
|
''''' FOR ''''',
|
mariadb_users.User,
|
'''''@''''',
|
mariadb_users.Host,
|
''''''';'
|
)
|
FROM mariadb_users
|
WHERE mariadb_users.default_role != '';
|
In my opinion, this step just seems a bit unnecessary, since it could be wrapped into granting user privileges (#3), so that's why I submitted this Jira.
What do you expect to be showed?
Why GRANT test_role TO 'test_user'@'%' is not good enough?
How should be different from SHOW GRANTS for 'test_role; ?
Also SHOW CREATE USER is added in `10.2`, so update in MDEV version or example is needed.