-
Notifications
You must be signed in to change notification settings - Fork 90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mysql_user: Grant all privileges result in missing dynamic privileges in every second run in MySQL 8 #120
Comments
@bigo8525 thanks for the issue! |
also you can install the latest version of the collection from Galaxy using |
yes is saw this today. The last time i looked into the code was more than a year ago. But beside If my fix is in the next release i definitly switch to the newest version of this collection. but befor that i got a problem when the cluster admin user is not able to create a cluster after a config deployment. |
Just for information, this link can be interesting: https://dev.mysql.com/doc/refman/8.0/en/privilege-changes.html From this docs I understand that we shouldn't need a FLUSH PRIVILEGES command when using GRANT or REVOKE to manage privileges. We should verify that we always do that. I'm not a mysql expert but FLUSH PRIVILEGES command seems to reload privileges on memory, it doesn't look dangerous to me. |
i find it a bit difficult to describe the problem. From docs i would agree with you. But the dynamic privileges are not really described in the docs at this specific point. After a successful run of the mysql_user module the dynamic privileges are set to community.mysql/plugins/module_utils/user.py Line 616 in 4aab8ac
*.*:ALL,GRANT is not evaluated to ALL in the mysql. Instead every privilege is used.
I tried to get a list of the privileges created or used with this line community.mysql/plugins/module_utils/user.py Line 323 in 4aab8ac
msg = priv_diff This is the result: ['ALL', 'ALTER', 'ALTER ROUTINE', 'APPLICATION_PASSWORD_ADMIN', 'AUDIT_ABORT_EXEMPT', 'AUDIT_ADMIN', 'AUTHENTICATION_POLICY_ADMIN', 'BACKUP_ADMIN', 'BINLOG_ADMIN', 'BINLOG_ENCRYPTION_ADMIN', 'CLONE_ADMIN', 'CONNECTION_ADMIN', 'CREATE', 'CREATE ROLE', 'CREATE ROUTINE', 'CREATE TABLESPACE', 'CREATE TEMPORARY TABLES', 'CREATE USER', 'CREATE VIEW', 'DELETE', 'DROP', 'DROP ROLE', 'ENCRYPTION_KEY_ADMIN', 'EVENT', 'EXECUTE', 'FILE', 'FLUSH_OPTIMIZER_COSTS', 'FLUSH_STATUS', 'FLUSH_TABLES', 'FLUSH_USER_RESOURCES', 'GROUP_REPLICATION_ADMIN', 'GROUP_REPLICATION_STREAM', 'INDEX', 'INNODB_REDO_LOG_ARCHIVE', 'INNODB_REDO_LOG_ENABLE', 'INSERT', 'LOCK TABLES', 'PASSWORDLESS_USER_ADMIN', 'PERSIST_RO_VARIABLES_ADMIN', 'PROCESS', 'REFERENCES', 'RELOAD', 'REPLICATION CLIENT', 'REPLICATION SLAVE', 'REPLICATION_APPLIER', 'REPLICATION_SLAVE_ADMIN', 'RESOURCE_GROUP_ADMIN', 'RESOURCE_GROUP_USER', 'ROLE_ADMIN', 'SELECT', 'SERVICE_CONNECTION_ADMIN', 'SESSION_VARIABLES_ADMIN', 'SET_USER_ID', 'SHOW DATABASES', 'SHOW VIEW', 'SHOW_ROUTINE', 'SHUTDOWN', 'SUPER', 'SYSTEM_USER', 'SYSTEM_VARIABLES_ADMIN', 'TABLE_ENCRYPTION_ADMIN', 'TRIGGER', 'UPDATE', 'XA_RECOVER_ADMIN'] Some of these privileges are static and some dynamic. Because this list is different to *.*:ALL,GRANT all these privileges are revoked.If the mysql is not restarted all is dynamic privileges are assigned to the user but the mysql.global_grants is emtpy. This means that the privileges are not present after restart of mysql. but this also means, that each run of ansible does not affect the dynamic privileges.
as visable in the example above
After the I actualy do not understand whether this is a possible misbehaviour in mysql or a tricky point of the mysql_user module. But the |
* added flush privileges to write dynamic privs into db Fixes #120 * added changelog fragment * Update changelogs/fragments/338-mysql_user_fix_missing_dynamic_privileges.yml Co-authored-by: Andrew Klychkov <[email protected]> Co-authored-by: Andrew Klychkov <[email protected]>
* added flush privileges to write dynamic privs into db Fixes #120 * added changelog fragment * Update changelogs/fragments/338-mysql_user_fix_missing_dynamic_privileges.yml Co-authored-by: Andrew Klychkov <[email protected]> Co-authored-by: Andrew Klychkov <[email protected]> (cherry picked from commit 1dcc5ec)
…) (#339) * added flush privileges to write dynamic privs into db Fixes #120 * added changelog fragment * Update changelogs/fragments/338-mysql_user_fix_missing_dynamic_privileges.yml Co-authored-by: Andrew Klychkov <[email protected]> Co-authored-by: Andrew Klychkov <[email protected]> (cherry picked from commit 1dcc5ec) Co-authored-by: bigo8525 <[email protected]>
SUMMARY
In MySQL 8 are dynamic privileges new. The
GRANT ALL
includes per default these dynamic privileges. The dynamic privileges are stored inmysql.global_grants
. At restart the dynamic privileges are assigned to the user by reading themysql.global_grants
table.dynamic privileges docs
As in #77 mentioned a
priv: "*.*:ALL,GRANT"
results in a change for the user. TheALL
is executed with the following SQL statementsThe main problem is that the dynamic privileges need a
FLUSH PRIVILEGES
. Now the dynmaic privileges are only on every second run available. This happens because theREVOKE
cleans the dynmaic privileges inmysql.global_grants
the direct followingGRANT ALL
does not affect the table because of a missingFLUSH PRIVILEGES
. TheSHOW GRANTS FOR 'testing_admin'@'localhost'
is correct to the next restart. After the restart mysql assign the dynamic privileges frommysql.global_grants
and this does not work because the table is empty for the specific user.After many test I assume the main reason should be the
GRANT
without it all workes even without theFLUSH PRIVILEGES
This is a issue because the dynamic privileges are needed for a user who should be able to maintain a InnoDB Cluster. By playing around with the cluster I mentioned this behavior because on every second deployment my user was not able to run the mysqlsh cluster commands because of missing privileges.
I hope I described the problem good enough for understanding it. A
FLUSH PRIVILEGES
at the end in the privilege_revoke method could fix this issue. But I´m not sure if this could have a negative effect on other parts of the module.ISSUE TYPE
COMPONENT NAME
mysql_user
ANSIBLE VERSION
CONFIGURATION
OS / ENVIRONMENT
mysql_user.py from main branch copied into the collaction path.
Original found this on RHEL8 with MySQL 8.0.23 Commercial, Testing was on Fedora 33 with MySQL 8.0.23 community
STEPS TO REPRODUCE
The behavor can be proofed by only execute the following SQL comands:
After the first
SELECT * FROM mysql.global_grants;
the result should beAfter both
REVOKE
and theGRANT ALL
the output ofSELECT * FROM mysql.global_grants;
sould be exactly as above but its empty. After a restart of the MySQL the user is missing all this dynamic privileges to the nextGRANT ALL
.EXPECTED RESULTS
normale i would expect to have every time the
ALL,GRANT
for the user.ACTUAL RESULTS
As explaind earlier every second run of the playbook the user testing_admin as no dynamic privileges.
I hope this was all correct and is understandable and reproducable. My local fix would be a
cursor.execute("FLUSH PRIVILEGES")
at the end of the privileges_revoke method. But i need more testing time at some different OS and MySQL versions. Need to verify RHEL 7 and MySQL 5.7.21 and also RHEL 8 with MySQL 8.0.23 that nothing unexpected is happening in production. I Also tired a different workaround by not usingALL
and list every needed privileg. But this is not working because theVALID_PRIVS
do not have all privileges assigned by theGRANT ALL
. The idea was that theSHOW GRANTS
has the same result like thepriv: "*.*:..."
so theREVOKE
is not needed.The text was updated successfully, but these errors were encountered: