File: system_user_priv.result

package info (click to toggle)
mysql-8.0 8.0.43-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 1,273,924 kB
  • sloc: cpp: 4,684,605; ansic: 412,450; pascal: 108,398; java: 83,641; perl: 30,221; cs: 27,067; sql: 26,594; sh: 24,181; python: 21,816; yacc: 17,169; php: 11,522; xml: 7,388; javascript: 7,076; makefile: 2,194; lex: 1,075; awk: 670; asm: 520; objc: 183; ruby: 97; lisp: 86
file content (420 lines) | stat: -rw-r--r-- 19,783 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
#------------------------------------------------------------------------
# 1. Create the Users and Roles. Grant/REVOKE the SYSTEM_USER
#    privilege from them.
#------------------------------------------------------------------------

# 1.1 User is granted SYSTEM_USER priv only if it is granted explictly
CREATE USER sys_usr IDENTIFIED BY 'pwd';
SHOW GRANTS FOR sys_usr;
Grants for sys_usr@%
GRANT USAGE ON *.* TO `sys_usr`@`%`
GRANT SYSTEM_USER ON *.* TO sys_usr WITH GRANT OPTION;
SHOW GRANTS FOR sys_usr;
Grants for sys_usr@%
GRANT USAGE ON *.* TO `sys_usr`@`%`
GRANT SYSTEM_USER ON *.* TO `sys_usr`@`%` WITH GRANT OPTION

# 1.2 Revoke the SYSTEM_USER privilege from user;
CREATE USER non_sys_usr IDENTIFIED BY 'pwd';
GRANT ALL ON *.* TO non_sys_usr;
REVOKE SYSTEM_USER ON *.* FROM non_sys_usr;
REVOKE UPDATE ON *.* FROM non_sys_usr;
SHOW GRANTS FOR non_sys_usr;
Grants for non_sys_usr@%
GRANT SELECT, INSERT, DELETE, CREATE, DROP, RELOAD, SHUTDOWN, PROCESS, FILE, REFERENCES, INDEX, ALTER, SHOW DATABASES, SUPER, CREATE TEMPORARY TABLES, LOCK TABLES, EXECUTE, REPLICATION SLAVE, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE, CREATE ROLE, DROP ROLE ON *.* TO `non_sys_usr`@`%`
GRANT APPLICATION_PASSWORD_ADMIN,AUDIT_ABORT_EXEMPT,AUDIT_ADMIN,AUTHENTICATION_POLICY_ADMIN,BACKUP_ADMIN,BINLOG_ADMIN,BINLOG_ENCRYPTION_ADMIN,CLONE_ADMIN,CONNECTION_ADMIN,ENCRYPTION_KEY_ADMIN,FIREWALL_EXEMPT,FLUSH_OPTIMIZER_COSTS,FLUSH_STATUS,FLUSH_TABLES,FLUSH_USER_RESOURCES,GROUP_REPLICATION_ADMIN,GROUP_REPLICATION_STREAM,INNODB_REDO_LOG_ARCHIVE,INNODB_REDO_LOG_ENABLE,PASSWORDLESS_USER_ADMIN,PERSIST_RO_VARIABLES_ADMIN,REPLICATION_APPLIER,REPLICATION_SLAVE_ADMIN,RESOURCE_GROUP_ADMIN,RESOURCE_GROUP_USER,ROLE_ADMIN,SENSITIVE_VARIABLES_OBSERVER,SERVICE_CONNECTION_ADMIN,SESSION_VARIABLES_ADMIN,SET_USER_ID,SHOW_ROUTINE,SYSTEM_VARIABLES_ADMIN,TABLE_ENCRYPTION_ADMIN,TELEMETRY_LOG_ADMIN,XA_RECOVER_ADMIN ON *.* TO `non_sys_usr`@`%`

# 1.3 Role is granted SYSTEM_USER priv only if it is granted explictly
CREATE ROLE sys_role;
SHOW GRANTS FOR sys_role;
Grants for sys_role@%
GRANT USAGE ON *.* TO `sys_role`@`%`
GRANT SYSTEM_USER ON *.* TO sys_role WITH GRANT OPTION;
SHOW GRANTS FOR sys_role;
Grants for sys_role@%
GRANT USAGE ON *.* TO `sys_role`@`%`
GRANT SYSTEM_USER ON *.* TO `sys_role`@`%` WITH GRANT OPTION

# 1.4 Revoke the SYSTEM_USER privilege from user;
CREATE USER non_sys_role;
GRANT ALL ON *.* TO non_sys_role;
REVOKE SYSTEM_USER ON *.* FROM non_sys_role;
SHOW GRANTS FOR non_sys_role;
Grants for non_sys_role@%
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, REPLICATION CLIENT, CREATE VIEW, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, CREATE USER, EVENT, TRIGGER, CREATE TABLESPACE, CREATE ROLE, DROP ROLE ON *.* TO `non_sys_role`@`%`
GRANT APPLICATION_PASSWORD_ADMIN,AUDIT_ABORT_EXEMPT,AUDIT_ADMIN,AUTHENTICATION_POLICY_ADMIN,BACKUP_ADMIN,BINLOG_ADMIN,BINLOG_ENCRYPTION_ADMIN,CLONE_ADMIN,CONNECTION_ADMIN,ENCRYPTION_KEY_ADMIN,FIREWALL_EXEMPT,FLUSH_OPTIMIZER_COSTS,FLUSH_STATUS,FLUSH_TABLES,FLUSH_USER_RESOURCES,GROUP_REPLICATION_ADMIN,GROUP_REPLICATION_STREAM,INNODB_REDO_LOG_ARCHIVE,INNODB_REDO_LOG_ENABLE,PASSWORDLESS_USER_ADMIN,PERSIST_RO_VARIABLES_ADMIN,REPLICATION_APPLIER,REPLICATION_SLAVE_ADMIN,RESOURCE_GROUP_ADMIN,RESOURCE_GROUP_USER,ROLE_ADMIN,SENSITIVE_VARIABLES_OBSERVER,SERVICE_CONNECTION_ADMIN,SESSION_VARIABLES_ADMIN,SET_USER_ID,SHOW_ROUTINE,SYSTEM_VARIABLES_ADMIN,TABLE_ENCRYPTION_ADMIN,TELEMETRY_LOG_ADMIN,XA_RECOVER_ADMIN ON *.* TO `non_sys_role`@`%`
#------------------------------------------------------------------------
# 2. sys_usr cannot modify the other users properties unless the former
#    is granted the relevant properties to do so
#------------------------------------------------------------------------
CREATE USER test_usr;
ERROR 42000: Access denied; you need (at least one of) the CREATE USER privilege(s) for this operation
ALTER USER non_sys_usr IDENTIFIED BY 'pwd';
ERROR 42000: Access denied; you need (at least one of) the CREATE USER privilege(s) for this operation
RENAME USER non_sys_usr TO power_usr;
ERROR 42000: Access denied; you need (at least one of) the CREATE USER privilege(s) for this operation
DROP USER non_sys_usr;
ERROR 42000: Access denied; you need (at least one of) the CREATE USER privilege(s) for this operation
#------------------------------------------------------------------------
# 3. non_sys_usr cannot modify the other sys_usr even if former is
#    granted global privileges
#------------------------------------------------------------------------
CREATE USER test_user;
ALTER USER test_user IDENTIFIED BY 'pwd';
RENAME USER test_user TO temp_user;
DROP USER temp_user;
ALTER USER sys_usr IDENTIFIED BY 'pwd';
ERROR 42000: Access denied; you need (at least one of) the SYSTEM_USER privilege(s) for this operation
RENAME USER sys_usr TO power_usr;
ERROR 42000: Access denied; you need (at least one of) the SYSTEM_USER privilege(s) for this operation
DROP USER sys_usr;
ERROR 42000: Access denied; you need (at least one of) the SYSTEM_USER privilege(s) for this operation
#------------------------------------------------------------------------
# 4. non_sys_usr cannot grant/revoke SYSTEM_USER privilege to /from
#    other users/roles
#------------------------------------------------------------------------
CREATE USER test_user;
GRANT SYSTEM_USER ON *.* TO test_user;
ERROR 42000: Access denied; you need (at least one of) the GRANT OPTION privilege(s) for this operation
REVOKE SYSTEM_USER FROM sys_usr;
ERROR 42000: Access denied; you need (at least one of) the SYSTEM_USER privilege(s) for this operation
GRANT SYSTEM_USER ON *.* TO sys_role;
ERROR 42000: Access denied; you need (at least one of) the SYSTEM_USER privilege(s) for this operation
GRANT SYSTEM_USER ON *.* TO non_sys_role;
ERROR 42000: Access denied; you need (at least one of) the GRANT OPTION privilege(s) for this operation
REVOKE SYSTEM_USER ON *.* FROM sys_role;
ERROR 42000: Access denied; you need (at least one of) the SYSTEM_USER privilege(s) for this operation
GRANT sys_role to test_user;
ERROR 42000: Access denied; you need (at least one of) the SYSTEM_USER privilege(s) for this operation
GRANT sys_role TO test_user;
SHOW GRANTS FOR test_user;
Grants for test_user@%
GRANT USAGE ON *.* TO `test_user`@`%`
GRANT `sys_role`@`%` TO `test_user`@`%`
REVOKE sys_role FROM test_user;
ERROR 42000: Access denied; you need (at least one of) the SYSTEM_USER privilege(s) for this operation
DROP USER test_user;
#------------------------------------------------------------------------
# 5. Mandatory Roles
#------------------------------------------------------------------------

# 5.1 Check with root user
SET @@GLOBAL.MANDATORY_ROLES='sys_role,non_sys_role';
ERROR HY000: Cannot set mandatory_roles: AuthId `sys_role`@`%` has 'SYSTEM_USER' privilege.
SET @@GLOBAL.MANDATORY_ROLES='sys_role';
ERROR HY000: Cannot set mandatory_roles: AuthId `sys_role`@`%` has 'SYSTEM_USER' privilege.
SET @@GLOBAL.MANDATORY_ROLES='non_sys_role';

# 5.2 Check with user who does not have system user privilege
SET @@GLOBAL.MANDATORY_ROLES='sys_role,non_sys_role';
ERROR HY000: Cannot set mandatory_roles: AuthId `sys_role`@`%` has 'SYSTEM_USER' privilege.
SET @@GLOBAL.MANDATORY_ROLES='sys_role';
ERROR HY000: Cannot set mandatory_roles: AuthId `sys_role`@`%` has 'SYSTEM_USER' privilege.
SET @@GLOBAL.MANDATORY_ROLES='non_sys_role';

# 5.3 Check with user who has system user privilege
SET @@GLOBAL.MANDATORY_ROLES='sys_role,non_sys_role';
ERROR 42000: Access denied; you need (at least one of) the SUPER or SYSTEM_VARIABLES_ADMIN privilege(s) for this operation
SET @@GLOBAL.MANDATORY_ROLES='sys_role';
ERROR 42000: Access denied; you need (at least one of) the SUPER or SYSTEM_VARIABLES_ADMIN privilege(s) for this operation

# 5.4 Non existing mandatory_role which is granted the SYSTEM_USER priv
#     later
SET @@GLOBAL.MANDATORY_ROLES='test_role';
CREATE ROLE test_role;
GRANT SYSTEM_USER ON *.* TO 'test_role';
ERROR HY000: AuthId `test_role`@`%` is set as mandatory_roles. Cannot grant the 'SYSTEM_USER' privilege.
GRANT SYSTEM_USER ON *.* TO 'test_role';
ERROR HY000: AuthId `test_role`@`%` is set as mandatory_roles. Cannot grant the 'SYSTEM_USER' privilege.
GRANT SYSTEM_USER ON *.* TO 'test_role';
ERROR 42000: Access denied; you need (at least one of) the GRANT OPTION privilege(s) for this operation
SET @@GLOBAL.MANDATORY_ROLES='';
DROP ROLE test_role;

# 5.5 None of the roles in the role's hierarchy should have SYSTEM_USER
#     privilege if former is set as mandatory_role.
CREATE ROLE r1, r2;
GRANT r1 TO r2;
GRANT sys_role TO r1;
SET @@GLOBAL.MANDATORY_ROLES='r2';
ERROR HY000: Cannot set mandatory_roles: AuthId `r2`@`%` has 'SYSTEM_USER' privilege.
# 5.6 Set persist should fail too.
SET PERSIST MANDATORY_ROLES = 'r2';
ERROR HY000: Cannot set mandatory_roles: AuthId `r2`@`%` has 'SYSTEM_USER' privilege.
# 5.6 Set persist should fail too.
SET PERSIST MANDATORY_ROLES = 'r2';
ERROR HY000: Cannot set mandatory_roles: AuthId `r2`@`%` has 'SYSTEM_USER' privilege.
# 5.7 We do not check the SET PERSIST_ONLY, should succeed.
SET PERSIST_ONLY MANDATORY_ROLES = 'r2';
# 5.8 On Server restart there should be a warning in the log file
# Restart server.
include/assert_grep.inc [Found the expected warning line in the server log.]
# System variable should not have been set.
SELECT @@mandatory_roles;
@@mandatory_roles

SET PERSIST mandatory_roles = '';
# 5.9 Set the system variable at the command line.
# Restart server.
include/assert_grep.inc [Found the expected warning line in the server log.]
# System variable should not have been set.
SELECT @@mandatory_roles;
@@mandatory_roles

# 5.10 Set the system variable in the cnf file. Warning should be logged.
include/assert_grep.inc [Found the expected warning line in the server log.]
# System variable should not have been set.
SELECT @@mandatory_roles;
@@mandatory_roles

DROP ROLE r1, r2;
#------------------------------------------------------------------------
# 6. If the definer has SYSTEM_USER privilege then owner must also have
#    the SYSTEM_USER privilege.
#------------------------------------------------------------------------
CREATE TABLE test.t1 (c1 INT);
CREATE DATABASE restricted;
CREATE TABLE restricted.t1 (c1 int, restricted int);
INSERT INTO restricted.t1 VALUES (1,2);
GRANT SET_USER_ID ON *.* TO sys_usr;

# 6.1 Stored procedure and functions
SELECT CURRENT_USER();
CURRENT_USER()
sys_usr@%
SELECT * FROM restricted.t1;
ERROR 42000: SELECT command denied to user 'sys_usr'@'localhost' for table 't1'
USE test;
CREATE DEFINER=root@localhost PROCEDURE p1() SELECT * FROM restricted.t1;
# With the SET_USER_ID privilege we can escalate the authorization
CALL p1();
c1	restricted
1	2
CREATE DEFINER=root@localhost FUNCTION f1(i INT) RETURNS INT(10) DETERMINISTIC
RETURN i*10;
# With the SET_USER_ID privilege we can escalate the authorization
SELECT f1(2);
f1(2)
20

SELECT CURRENT_USER();
CURRENT_USER()
non_sys_usr@%
USE test;
CREATE DEFINER=root@localhost PROCEDURE p2() SELECT * FROM restricted.t1;
ERROR 42000: Access denied; you need (at least one of) the SYSTEM_USER privilege(s) for this operation
CREATE DEFINER=root@localhost FUNCTION f2(i INT) RETURNS INT(10) DETERMINISTIC
RETURN i*10;
ERROR 42000: Access denied; you need (at least one of) the SYSTEM_USER privilege(s) for this operation
# Invoker has EXECUTE privilege but not SYSTEM_USER privilege
CALL p1();
c1	restricted
1	2
ALTER PROCEDURE test.p1 SQL SECURITY INVOKER;
ERROR 42000: Access denied; you need (at least one of) the SYSTEM_USER privilege(s) for this operation
DROP PROCEDURE test.p1;
ERROR 42000: Access denied; you need (at least one of) the SYSTEM_USER privilege(s) for this operation
ALTER FUNCTION test.f1 SQL SECURITY INVOKER;
ERROR 42000: Access denied; you need (at least one of) the SYSTEM_USER privilege(s) for this operation
DROP FUNCTION test.f1;
ERROR 42000: Access denied; you need (at least one of) the SYSTEM_USER privilege(s) for this operation

# 6.2 Create trigger
SELECT CURRENT_USER();
CURRENT_USER()
sys_usr@%
CREATE DEFINER=root@localhost TRIGGER test.tr1 BEFORE INSERT ON test.t1
FOR EACH ROW INSERT INTO restricted.t1 VALUES (1,1);
# Use trigger to escalate privileges
INSERT INTO test.t1 VALUES (1);
SELECT * FROM restricted.t1;
c1	restricted
1	2
1	1
CREATE DEFINER=root@localhost TRIGGER test.tr2 BEFORE INSERT ON test.t1
FOR EACH ROW INSERT INTO restricted.t1 VALUES (1,1);
ERROR 42000: Access denied; you need (at least one of) the SYSTEM_USER privilege(s) for this operation

# 6.3 Create View
# We need some privilege on the column for CREATE VIEW to work
GRANT INSERT(restricted) ON restricted.t1 TO sys_usr;
SHOW GRANTS FOR CURRENT_USER();
Grants for sys_usr@%
GRANT USAGE ON *.* TO `sys_usr`@`%`
GRANT SET_USER_ID ON *.* TO `sys_usr`@`%`
GRANT SYSTEM_USER ON *.* TO `sys_usr`@`%` WITH GRANT OPTION
GRANT INSERT (`restricted`) ON `restricted`.`t1` TO `sys_usr`@`%`
GRANT EXECUTE, ALTER ROUTINE ON PROCEDURE `test`.`p1` TO `sys_usr`@`%`
GRANT EXECUTE, ALTER ROUTINE ON FUNCTION `test`.`f1` TO `sys_usr`@`%`
CREATE DEFINER=root@localhost SQL SECURITY DEFINER VIEW v1 AS
SELECT a.restricted FROM restricted.t1 as a;
# Use escalated privileges to read restricted column.
SELECT * FROM v1;
restricted
2
1
CREATE DEFINER=root@localhost SQL SECURITY DEFINER VIEW v2 AS
SELECT a.restricted FROM restricted.t1 as a;
ERROR 42000: Access denied; you need (at least one of) the SYSTEM_USER privilege(s) for this operation
ALTER ALGORITHM=MERGE VIEW v1 AS SELECT a.restricted FROM restricted.t1 as a;
ERROR 42000: Access denied; you need (at least one of) the SYSTEM_USER privilege(s) for this operation
DROP VIEW v1;
ERROR 42000: Access denied; you need (at least one of) the SYSTEM_USER privilege(s) for this operation

# 6.4 Create Event
CREATE DEFINER=root@localhost EVENT test.eve1 ON SCHEDULE AT
CURRENT_TIMESTAMP + INTERVAL 2 HOUR
DO BEGIN
INSERT INTO restricted.t1 VALUES (5,5);
END ;$$
CREATE DEFINER=root@localhost EVENT test.eve2 ON SCHEDULE AT
CURRENT_TIMESTAMP + INTERVAL 2 SECOND
DO BEGIN
INSERT INTO restricted.t1 VALUES (5,5);
END ;$$
ERROR 42000: Access denied; you need (at least one of) the SYSTEM_USER privilege(s) for this operation
ALTER EVENT test.eve1 RENAME TO test.eve2;
ERROR 42000: Access denied; you need (at least one of) the SYSTEM_USER privilege(s) for this operation
DROP EVENT test.eve1;
ERROR 42000: Access denied; you need (at least one of) the SYSTEM_USER privilege(s) for this operation
# Cleanup
DROP TRIGGER test.tr1;
DROP PROCEDURE p1;
DROP FUNCTION f1;
DROP DATABASE restricted;
DROP VIEW test.v1;
DROP TABLE test.t1;
DROP EVENT test.eve1;
#------------------------------------------------------------------------
# 7. If SYSTEM_USER privilege is granted to definer and invoker
#    through roles
#------------------------------------------------------------------------
USE test;
CREATE TABLE test.t1 (c1 int, c2 int);
INSERT INTO test.t1 VALUES(1,2);
CREATE USER test_user@localhost;
GRANT sys_role TO test_user@localhost;
GRANT ALL ON test.* TO test_user@localhost;
GRANT EXECUTE ON *.*  TO test_user@localhost;

#  7.1 Invoker is not granted SYSTEM_USER priv through roles
#  7.1.1 ALTER AND DROP STORED PROCEDURE
CREATE DEFINER=test_user@localhost PROCEDURE p1() SELECT * FROM test.t1;
SHOW GRANTS FOR test_user@localhost;
Grants for test_user@localhost
GRANT EXECUTE ON *.* TO `test_user`@`localhost`
GRANT ALL PRIVILEGES ON `test`.* TO `test_user`@`localhost`
GRANT `sys_role`@`%` TO `test_user`@`localhost`
CALL p1();
c1	c2
1	2
ALTER PROCEDURE test.p1 SQL SECURITY INVOKER;
ERROR 42000: Access denied; you need (at least one of) the SYSTEM_USER privilege(s) for this operation
DROP PROCEDURE test.p1;
ERROR 42000: Access denied; you need (at least one of) the SYSTEM_USER privilege(s) for this operation
# 7.1.2 ALTER and DROP FUNCTIONS
CREATE DEFINER=test_user@localhost FUNCTION f1(i INT) RETURNS INT(10) DETERMINISTIC
RETURN i*10;
Warnings:
Warning	1681	Integer display width is deprecated and will be removed in a future release.
SELECT f1(2);
f1(2)
20
ALTER FUNCTION test.f1 SQL SECURITY INVOKER;
ERROR 42000: Access denied; you need (at least one of) the SYSTEM_USER privilege(s) for this operation
DROP FUNCTION test.f1;
ERROR 42000: Access denied; you need (at least one of) the SYSTEM_USER privilege(s) for this operation
# 7.1.3 ALTER and DROP View
CREATE DEFINER=test_user@localhost SQL SECURITY DEFINER VIEW v1 AS
SELECT a.c1 FROM test.t1 as a;
SELECT * FROM v1;
c1
1
ALTER VIEW v1 AS SELECT a.c1 FROM test.t1 as a;
ERROR 42000: Access denied; you need (at least one of) the SYSTEM_USER privilege(s) for this operation
DROP VIEW v1;
ERROR 42000: Access denied; you need (at least one of) the SYSTEM_USER privilege(s) for this operation

# 7.1.4 ALTER and DROP EVENT
CREATE DEFINER=test_user@localhost EVENT test.eve1 ON SCHEDULE AT
CURRENT_TIMESTAMP + INTERVAL 2 HOUR
DO BEGIN
INSERT INTO test.t1 VALUES (5,5);
END ;$$
ALTER EVENT test.eve1 RENAME TO test.eve2;
ERROR 42000: Access denied; you need (at least one of) the SYSTEM_USER privilege(s) for this operation
DROP EVENT test.eve1;
ERROR 42000: Access denied; you need (at least one of) the SYSTEM_USER privilege(s) for this operation

#  7.2 Invoker is also granted SYSTEM_USER priv through roles
CREATE ROLE r1, r2;
GRANT SYSTEM_USER ON *.* TO r1;
GRANT r1 TO r2;
GRANT r2 TO non_sys_usr;
#  7.2.1 ALTER and DROP PROCEDURE
CALL p1();
c1	c2
1	2
ALTER PROCEDURE test.p1 SQL SECURITY INVOKER;
ERROR 42000: Access denied; you need (at least one of) the SYSTEM_USER privilege(s) for this operation
DROP PROCEDURE test.p1;
ERROR 42000: Access denied; you need (at least one of) the SYSTEM_USER privilege(s) for this operation
# Activate the role to get the SYSTEM_USER priv
SET ROLE r2;
ALTER PROCEDURE test.p1 SQL SECURITY INVOKER;
CALL p1();
c1	c2
1	2
DROP PROCEDURE test.p1;
SET ROLE NONE;
# 7.2.2 ALTER and DROP FUNCTIONS
SELECT f1(2);
f1(2)
20
ALTER FUNCTION test.f1 SQL SECURITY INVOKER;
ERROR 42000: Access denied; you need (at least one of) the SYSTEM_USER privilege(s) for this operation
DROP FUNCTION test.f1;
ERROR 42000: Access denied; you need (at least one of) the SYSTEM_USER privilege(s) for this operation
SELECT f1(2);
f1(2)
20
# Activate the role to  get the SYSTEM_USER priv
SET ROLE r2;
ALTER FUNCTION test.f1 SQL SECURITY INVOKER;
DROP FUNCTION test.f1;
SET ROLE NONE;
# 7.2.3 ALTER and DROP VIEW
ALTER ALGORITHM=MERGE VIEW v1 AS SELECT a.c1 FROM test.t1 as a;
ERROR 42000: Access denied; you need (at least one of) the SYSTEM_USER privilege(s) for this operation
DROP VIEW v1;
ERROR 42000: Access denied; you need (at least one of) the SYSTEM_USER privilege(s) for this operation
# Activate the role to get the SYSTEM_USER priv
SET ROLE r2;
ALTER ALGORITHM=MERGE VIEW v1 AS SELECT a.c1 FROM test.t1 as a;
DROP VIEW v1;
SET ROLE NONE;

# 7.2.4 ALTER and DROP EVENT
ALTER EVENT test.eve1 RENAME TO test.eve2;
ERROR 42000: Access denied; you need (at least one of) the SYSTEM_USER privilege(s) for this operation
DROP EVENT test.eve1;
ERROR 42000: Access denied; you need (at least one of) the SYSTEM_USER privilege(s) for this operation
# Activate the role to get the SYSTEM_USER priv
SET ROLE r2;
ALTER EVENT test.eve1 RENAME TO test.eve2;
DROP EVENT test.eve2;
SET ROLE NONE;
# Cleanup
DROP USER test_user@localhost;
DROP ROLE r1, r2;
DROP TABLE test.t1;
#
# Global clean up
#
DROP USER sys_usr;
DROP USER non_sys_usr;
DROP USER sys_role;
DROP USER non_sys_role;
call mtr.add_suppression(".*Cannot set mandatory_roles: AuthId.* privilege.");
RESET PERSIST mandatory_roles;
# restart: