Skip to content

Commit 53a359c

Browse files
committed
MDEV-33554 Upgrade from 11.2 to 11.3 changes root's privileges
let ALL PRIVILEGES to always mean ALL PRIVILEGES over all upgrades, no matter what new privileges were added in later versions.
1 parent ec3d9da commit 53a359c

8 files changed

+84
-10
lines changed

mysql-test/main/grant_slave_monitor.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ insert mysql.global_priv values ('bar', 'foo7', '{"access":274877906943,"version
4646
flush privileges;
4747
show grants for foo7@bar;
4848
Grants for foo7@bar
49-
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, BINLOG MONITOR, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE, DELETE HISTORY, SET USER, FEDERATED ADMIN, CONNECTION ADMIN, READ_ONLY ADMIN, REPLICATION SLAVE ADMIN, REPLICATION MASTER ADMIN, BINLOG ADMIN, BINLOG REPLAY, SLAVE MONITOR ON *.* TO `foo7`@`bar` WITH GRANT OPTION
49+
GRANT ALL PRIVILEGES ON *.* TO `foo7`@`bar` WITH GRANT OPTION
5050
show grants for foo8@bar;
5151
Grants for foo8@bar
5252
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, BINLOG MONITOR, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE, DELETE HISTORY, SET USER, FEDERATED ADMIN, CONNECTION ADMIN, READ_ONLY ADMIN, REPLICATION SLAVE ADMIN, REPLICATION MASTER ADMIN, BINLOG ADMIN, BINLOG REPLAY, SLAVE MONITOR ON *.* TO `foo8`@`bar` WITH GRANT OPTION

mysql-test/main/mysql_upgrade.result

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,15 +1906,15 @@ SET DEFAULT ROLE aRole;
19061906
SHOW GRANTS;
19071907
Grants for root@localhost
19081908
GRANT `aRole` TO `root`@`localhost` WITH ADMIN OPTION
1909-
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, BINLOG MONITOR, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE, DELETE HISTORY, SET USER, FEDERATED ADMIN, CONNECTION ADMIN, READ_ONLY ADMIN, REPLICATION SLAVE ADMIN, REPLICATION MASTER ADMIN, BINLOG ADMIN, BINLOG REPLAY, SLAVE MONITOR ON *.* TO `root`@`localhost` WITH GRANT OPTION
1909+
GRANT ALL PRIVILEGES ON *.* TO `root`@`localhost` WITH GRANT OPTION
19101910
GRANT PROXY ON ''@'%' TO 'root'@'localhost' WITH GRANT OPTION
19111911
GRANT USAGE ON *.* TO `aRole`
19121912
SET DEFAULT ROLE `aRole` FOR `root`@`localhost`
19131913
SET DEFAULT ROLE NONE;
19141914
SHOW GRANTS;
19151915
Grants for root@localhost
19161916
GRANT `aRole` TO `root`@`localhost` WITH ADMIN OPTION
1917-
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, BINLOG MONITOR, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE, DELETE HISTORY, SET USER, FEDERATED ADMIN, CONNECTION ADMIN, READ_ONLY ADMIN, REPLICATION SLAVE ADMIN, REPLICATION MASTER ADMIN, BINLOG ADMIN, BINLOG REPLAY, SLAVE MONITOR ON *.* TO `root`@`localhost` WITH GRANT OPTION
1917+
GRANT ALL PRIVILEGES ON *.* TO `root`@`localhost` WITH GRANT OPTION
19181918
GRANT PROXY ON ''@'%' TO 'root'@'localhost' WITH GRANT OPTION
19191919
GRANT USAGE ON *.* TO `aRole`
19201920
DROP ROLE `aRole`;
@@ -2135,7 +2135,7 @@ SET GLOBAL alter_algorithm=DEFAULT;
21352135
SHOW GLOBAL VARIABLES LIKE 'alter_algorithm';
21362136
Variable_name Value
21372137
alter_algorithm DEFAULT
2138-
End of 10.3 tests
2138+
# End of 10.3 tests
21392139
# switching from mysql.global_priv to mysql.user
21402140
drop view mysql.user_bak;
21412141
create user 'user3'@'localhost' identified with mysql_native_password as password('a_password');
@@ -2588,3 +2588,29 @@ mysql.user has data
25882588
SELECT COUNT(*) > 0 AS `mysql.user has data` FROM mysql.user;
25892589
mysql.user has data
25902590
1
2591+
# End of 10.5 tests
2592+
#
2593+
# MDEV-33554 Upgrade from 11.2 to 11.3 changes root's privileges
2594+
#
2595+
alter table mysql.db drop column show_create_routine_priv;
2596+
flush privileges;
2597+
create user foo@bar;
2598+
grant all privileges on mysql.* to foo@bar;
2599+
show grants for foo@bar;
2600+
Grants for foo@bar
2601+
GRANT USAGE ON *.* TO `foo`@`bar`
2602+
GRANT ALL PRIVILEGES ON `mysql`.* TO `foo`@`bar`
2603+
flush privileges;
2604+
show grants for foo@bar;
2605+
Grants for foo@bar
2606+
GRANT USAGE ON *.* TO `foo`@`bar`
2607+
GRANT ALL PRIVILEGES ON `mysql`.* TO `foo`@`bar`
2608+
select show_create_routine_priv from mysql.db where user='foo';
2609+
show_create_routine_priv
2610+
Y
2611+
show grants for foo@bar;
2612+
Grants for foo@bar
2613+
GRANT USAGE ON *.* TO `foo`@`bar`
2614+
GRANT ALL PRIVILEGES ON `mysql`.* TO `foo`@`bar`
2615+
drop user foo@bar;
2616+
# End of 11.3 tests

mysql-test/main/mysql_upgrade.test

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ SET GLOBAL alter_algorithm=DEFAULT;
418418
SHOW GLOBAL VARIABLES LIKE 'alter_algorithm';
419419
--remove_file $MYSQLD_DATADIR/mariadb_upgrade_info
420420

421-
--echo End of 10.3 tests
421+
--echo # End of 10.3 tests
422422

423423
--source include/switch_to_mysql_user.inc
424424
drop view mysql.user_bak;
@@ -561,3 +561,25 @@ call mtr.add_suppression("Column count of mysql.proc is wrong. Expected 21, foun
561561

562562
--let $old_version= 10.4
563563
--source include/load_dump_and_upgrade.inc
564+
565+
--echo # End of 10.5 tests
566+
567+
--echo #
568+
--echo # MDEV-33554 Upgrade from 11.2 to 11.3 changes root's privileges
569+
--echo #
570+
alter table mysql.db drop column show_create_routine_priv;
571+
flush privileges;
572+
create user foo@bar;
573+
grant all privileges on mysql.* to foo@bar;
574+
show grants for foo@bar;
575+
flush privileges;
576+
show grants for foo@bar;
577+
578+
--exec $MYSQL_UPGRADE --force --silent 2>&1
579+
--remove_file $MYSQLD_DATADIR/mariadb_upgrade_info
580+
581+
select show_create_routine_priv from mysql.db where user='foo';
582+
show grants for foo@bar;
583+
drop user foo@bar;
584+
585+
--echo # End of 11.3 tests

mysql-test/main/mysql_upgrade_to_100502.result

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ CREATE USER user_all@localhost;
88
GRANT ALL PRIVILEGES ON *.* TO user_all@localhost WITH GRANT OPTION;
99
SHOW GRANTS FOR user_all@localhost;
1010
Grants for user_all@localhost
11-
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, BINLOG MONITOR, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE, DELETE HISTORY, SET USER, FEDERATED ADMIN, CONNECTION ADMIN, READ_ONLY ADMIN, REPLICATION SLAVE ADMIN, REPLICATION MASTER ADMIN, BINLOG ADMIN, BINLOG REPLAY, SLAVE MONITOR ON *.* TO `user_all`@`localhost` WITH GRANT OPTION
11+
GRANT ALL PRIVILEGES ON *.* TO `user_all`@`localhost` WITH GRANT OPTION
1212
CREATE USER user_super@localhost;
1313
GRANT SUPER ON *.* TO user_super@localhost;
1414
SHOW GRANTS FOR user_super@localhost;
@@ -56,7 +56,7 @@ FLUSH PRIVILEGES;
5656
#
5757
SHOW GRANTS FOR user_all@localhost;
5858
Grants for user_all@localhost
59-
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, BINLOG MONITOR, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE, DELETE HISTORY, SET USER, FEDERATED ADMIN, CONNECTION ADMIN, READ_ONLY ADMIN, REPLICATION SLAVE ADMIN, REPLICATION MASTER ADMIN, BINLOG ADMIN, BINLOG REPLAY, SLAVE MONITOR ON *.* TO `user_all`@`localhost` WITH GRANT OPTION
59+
GRANT ALL PRIVILEGES ON *.* TO `user_all`@`localhost` WITH GRANT OPTION
6060
#
6161
# Should automatically get all new 10.5.2 priveleges that were splitted from SUPER
6262
#

mysql-test/main/system_mysql_db_error_log.result

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ host='localhost' and user='good_version_id_100400';
9090
FLUSH PRIVILEGES;
9191
SHOW GRANTS FOR good_version_id_100400@localhost;
9292
Grants for good_version_id_100400@localhost
93-
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, BINLOG MONITOR, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE, DELETE HISTORY, SET USER, FEDERATED ADMIN, CONNECTION ADMIN, READ_ONLY ADMIN, REPLICATION SLAVE ADMIN, REPLICATION MASTER ADMIN, BINLOG ADMIN, BINLOG REPLAY, SLAVE MONITOR ON *.* TO `good_version_id_100400`@`localhost` WITH GRANT OPTION
93+
GRANT ALL PRIVILEGES ON *.* TO `good_version_id_100400`@`localhost` WITH GRANT OPTION
9494
GRANT REPLICATION MASTER ADMIN ON *.* TO good_version_id_100400@localhost;
9595
SHOW GRANTS FOR good_version_id_100400@localhost;
9696
Grants for good_version_id_100400@localhost
97-
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, BINLOG MONITOR, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE, DELETE HISTORY, SET USER, FEDERATED ADMIN, CONNECTION ADMIN, READ_ONLY ADMIN, REPLICATION SLAVE ADMIN, REPLICATION MASTER ADMIN, BINLOG ADMIN, BINLOG REPLAY, SLAVE MONITOR ON *.* TO `good_version_id_100400`@`localhost` WITH GRANT OPTION
97+
GRANT ALL PRIVILEGES ON *.* TO `good_version_id_100400`@`localhost` WITH GRANT OPTION
9898
DROP USER good_version_id_100400@localhost;
9999
CREATE USER good_version_id_100500@localhost;
100100
GRANT SUPER ON *.* to good_version_id_100500@localhost;

scripts/mariadb_system_tables_fix.sql

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -705,6 +705,9 @@ ALTER TABLE db change Truncate_versioning_priv Delete_history_priv enum('N','Y')
705705
SET @had_user_delete_history_priv := 0;
706706
SELECT @had_user_delete_history_priv :=1 FROM user WHERE Delete_history_priv IS NOT NULL;
707707

708+
SET @had_show_create_routine := 0;
709+
SELECT @had_show_create_routine:=1 FROM db WHERE Show_create_routine_priv IS NOT NULL;
710+
708711
ALTER TABLE user add Delete_history_priv enum('N','Y') COLLATE utf8mb3_general_ci NOT NULL DEFAULT 'N' after Create_tablespace_priv;
709712
ALTER TABLE user modify Delete_history_priv enum('N','Y') COLLATE utf8mb3_general_ci NOT NULL DEFAULT 'N';
710713
ALTER TABLE db add Delete_history_priv enum('N','Y') COLLATE utf8mb3_general_ci NOT NULL DEFAULT 'N' after Trigger_priv;
@@ -715,6 +718,15 @@ UPDATE user SET Delete_history_priv = Super_priv WHERE @had_user_delete_history_
715718
ALTER TABLE db ADD Show_create_routine_priv enum('N','Y') COLLATE utf8mb3_general_ci NOT NULL DEFAULT 'N' AFTER Delete_history_priv;
716719
ALTER TABLE db MODIFY Show_create_routine_priv enum('N','Y') COLLATE utf8mb3_general_ci NOT NULL DEFAULT 'N';
717720

721+
UPDATE db SET Show_create_routine_priv='Y' WHERE @had_show_create_routine=0
722+
AND Drop_priv='Y' AND Index_priv='Y' AND Alter_priv='Y'
723+
AND Event_priv='Y' AND Select_priv='Y' AND Insert_priv='Y'
724+
AND Update_priv='Y' AND Delete_priv='Y' AND Create_priv='Y'
725+
AND Execute_priv='Y' AND Trigger_priv='Y' AND Show_view_priv='Y'
726+
AND References_priv='Y' AND Lock_tables_priv='Y' AND Create_view_priv='Y'
727+
AND Alter_routine_priv='Y' AND Create_routine_priv='Y'
728+
AND Delete_history_priv='Y' AND Create_tmp_table_priv='Y';
729+
718730
ALTER TABLE user ADD plugin char(64) CHARACTER SET latin1 DEFAULT '' NOT NULL AFTER max_user_connections,
719731
ADD authentication_string TEXT NOT NULL AFTER plugin;
720732
ALTER TABLE user CHANGE auth_string authentication_string TEXT NOT NULL;

sql/privilege.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ constexpr privilege_t ALL_KNOWN_ACL_100508= ALL_KNOWN_BITS(LAST_100508_ACL);
128128
constexpr privilege_t ALL_KNOWN_ACL_100509= ALL_KNOWN_ACL_100508;
129129

130130
// A combination of all bits defined in 11.3.0
131-
constexpr privilege_t ALL_KNOWN_ACL_110300= ALL_KNOWN_BITS(LAST_110300_ACL);;
131+
constexpr privilege_t ALL_KNOWN_ACL_110300= ALL_KNOWN_BITS(LAST_110300_ACL);
132132

133133
// A combination of all bits defined as of the current version
134134
constexpr privilege_t ALL_KNOWN_ACL= ALL_KNOWN_BITS(LAST_CURRENT_ACL);

sql/sql_acl.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,6 +1071,9 @@ class User_table_tabular: public User_table
10711071
if (access & REPL_SLAVE_ACL)
10721072
access|= SLAVE_MONITOR_ACL;
10731073

1074+
if ((access & ALL_KNOWN_ACL_100304) == ALL_KNOWN_ACL_100304)
1075+
access|= SHOW_CREATE_ROUTINE_ACL;
1076+
10741077
return access & GLOBAL_ACLS;
10751078
}
10761079

@@ -1584,6 +1587,11 @@ class User_table_json: public User_table
15841587
print_warning_bad_access(version_id, mask, orig_access);
15851588
return NO_ACL;
15861589
}
1590+
1591+
// ALL PRIVILEGES always means ALL PRIVILEGES
1592+
if ((orig_access & mask) == mask)
1593+
access= ALL_KNOWN_ACL;
1594+
15871595
return access & ALL_KNOWN_ACL;
15881596
}
15891597

@@ -2785,6 +2793,9 @@ static bool acl_load(THD *thd, const Grant_tables& tables)
27852793
db.access|=REFERENCES_ACL | INDEX_ACL | ALTER_ACL;
27862794
}
27872795
#endif
2796+
if (db_table.num_fields() <= 23)
2797+
if ((db.access | SHOW_CREATE_ROUTINE_ACL | GRANT_ACL) == DB_ACLS)
2798+
db.access|= SHOW_CREATE_ROUTINE_ACL;
27882799
acl_dbs.push(db);
27892800
}
27902801
end_read_record(&read_record_info);
@@ -5039,6 +5050,9 @@ static int replace_db_table(TABLE *table, const char *db,
50395050
}
50405051
rights=get_access(table,3);
50415052
rights=fix_rights_for_db(rights);
5053+
if (table->s->fields <= 23)
5054+
if ((rights | SHOW_CREATE_ROUTINE_ACL | GRANT_ACL) == DB_ACLS)
5055+
rights|= SHOW_CREATE_ROUTINE_ACL;
50425056

50435057
if (old_row_exists)
50445058
{

0 commit comments

Comments
 (0)