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
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
|
--source include/not_embedded.inc
#
# This test covers show databases command interacting with DENY command.
# A user is able to see a database in `show databases` if:
# 1. They have globally granted any of the *DB_ACLS* (see privilege sets)
# or they have SHOW DATABASES privilege
# 2. They have on the database level granted any privilege.
# 3. They have grants on any of the underlying database objects:
# a. Tables
# b. Columns
# c. Stored Procedures
# A deny masking rights should affect all levels of this chain.
#
create user foo;
create database some_db;
create table some_db.t1 (a int, secret int);
show databases;
grant select on *.* to foo;
show grants for foo;
--echo #############################
--echo # Test global level denies. #
--echo #############################
--echo #
--echo # Test masking global level denies.
--echo #
--connect (con1,localhost,foo,,)
show databases;
disconnect con1;
connection default;
--echo #
--echo # Mask all rigths.
--echo #
deny select on *.* to foo;
--connect (con1,localhost,foo,,)
show databases;
disconnect con1;
connection default;
--echo #
--echo # Not all rights masked.
--echo #
grant insert on *.* to foo;
--echo #
--echo # some_db should now show up in the list because insert is not masked.
--echo #
--connect (con1,localhost,foo,,)
show databases;
disconnect con1;
connection default;
deny insert on *.* to foo;
--echo #
--echo # some_db should not be present now.
--echo #
--connect (con1,localhost,foo,,)
show databases;
disconnect con1;
connection default;
grant show databases on *.* to foo;
--connect (con1,localhost,foo,,)
show databases;
disconnect con1;
connection default;
deny show databases on *.* to foo;
--connect (con1,localhost,foo,,)
show databases;
disconnect con1;
connection default;
--echo #
--echo # Test masking database level grants with global denies.
--echo #
grant select on some_db.* to foo;
--connect (con1,localhost,foo,,)
show databases;
disconnect con1;
connection default;
grant update on some_db.* to foo;
--connect (con1,localhost,foo,,)
--echo #
--echo # Update not masked via global deny, some_db should show up.
--echo #
show databases;
disconnect con1;
connection default;
deny update on *.* to foo;
--connect (con1,localhost,foo,,)
--echo #
--echo # Now it should show up.
--echo #
show databases;
disconnect con1;
connection default;
--echo #
--echo # Test masking table level grants with global denies.
--echo #
connection default;
grant insert on some_db.t1 to foo;
show grants for foo;
--connect (con1,localhost,foo,,)
show databases;
disconnect con1;
connection default;
grant delete on some_db.t1 to foo;
show grants for foo;
--connect (con1,localhost,foo,,)
--echo #
--echo # some_db should show up because we have delete rights on t1.
--echo #
show databases;
disconnect con1;
connection default;
deny delete on *.* to foo;
--connect (con1,localhost,foo,,)
show databases;
disconnect con1;
connection default;
--echo #
--echo # Test masking column level grants with global denies.
--echo #
grant references (a) on some_db.t1 to foo;
show grants for foo;
--connect (con1,localhost,foo,,)
show databases;
disconnect con1;
connection default;
deny references on *.* to foo;
show grants for foo;
--connect (con1,localhost,foo,,)
show databases;
disconnect con1;
connection default;
delimiter |;
--echo #
--echo # Test masking procedure / function / package level grants with global
--echo # denies.
--echo #
create procedure some_db.proc_1()
begin
select 1;
end|
create function some_db.func_1() returns int
begin
return 3;
end|
set @old_sql_mode=@@sql_mode|
set sql_mode=ORACLE|
create package some_db.util_functions as
function f1(id int) return int;
end|
create package body some_db.util_functions as
function f1(id int) return int as result int;
begin
return 10;
end;
end|
delimiter ;|
grant execute on procedure some_db.proc_1 to foo;
grant execute on function some_db.func_1 to foo;
grant execute on package some_db.util_functions to foo;
set sql_mode=@old_sql_mode;
--connect (con1,localhost,foo,,)
show databases;
disconnect con1;
connection default;
deny execute on *.* to foo;
--connect (con1,localhost,foo,,)
show databases;
disconnect con1;
connection default;
drop user foo;
drop database some_db;
let $REGEX_VERSION_ID=/$mysql_get_server_version/VERSION_ID/;
--echo ###############################
--echo # Test database level denies. #
--echo ###############################
create user foo;
grant select on *.* to foo;
--echo #
--echo # Test masking database level denies.
--echo #
--connect (con1,localhost,foo,,)
show databases;
disconnect con1;
connection default;
--echo #
--echo # Mask all rights.
--echo #
deny select on mysql.* to foo;
--connect (con1,localhost,foo,,)
show databases;
disconnect con1;
connection default;
--echo #
--echo # Not all rights masked.
--echo #
grant insert on *.* to foo;
grant insert on mysql.* to foo;
--echo #
--echo # mysql db should now show up in the list because insert is not masked.
--echo #
--connect (con1,localhost,foo,,)
show databases;
disconnect con1;
connection default;
deny insert on mysql.* to foo;
--echo #
--echo # mysql db should not be present now.
--echo #
--connect (con1,localhost,foo,,)
show databases;
disconnect con1;
connection default;
grant show databases on *.* to foo;
--connect (con1,localhost,foo,,)
show databases;
disconnect con1;
connection default;
deny show databases on *.* to foo;
--connect (con1,localhost,foo,,)
show databases;
disconnect con1;
connection default;
show grants for foo;
grant update on mysql.* to foo;
--connect (con1,localhost,foo,,)
--echo #
--echo # Update not masked via database deny, mysql should show up.
--echo #
show databases;
disconnect con1;
connection default;
deny update on mysql.* to foo;
--connect (con1,localhost,foo,,)
--echo #
--echo # Now it should not show up.
--echo #
show grants;
show databases;
disconnect con1;
connection default;
--echo #
--echo # Test masking table level grants with global denies.
--echo #
create table mysql.t1 (a int);
connection default;
grant insert on mysql.t1 to foo;
show grants for foo;
--connect (con1,localhost,foo,,)
show databases;
disconnect con1;
connection default;
grant delete on mysql.t1 to foo;
show grants for foo;
--connect (con1,localhost,foo,,)
--echo #
--echo # mysql should show up because we have delete rights on t1.
--echo #
show databases;
disconnect con1;
connection default;
deny delete on mysql.* to foo;
--connect (con1,localhost,foo,,)
show databases;
disconnect con1;
connection default;
--echo #
--echo # Test masking column level grants with global denies.
--echo #
grant references (a) on mysql.t1 to foo;
show grants for foo;
--connect (con1,localhost,foo,,)
show databases;
disconnect con1;
connection default;
deny references on mysql.* to foo;
show grants for foo;
--connect (con1,localhost,foo,,)
show databases;
disconnect con1;
connection default;
delimiter |;
--echo #
--echo # Test masking procedure / function / package level grants with global
--echo # denies.
--echo #
create procedure mysql.proc_1()
begin
select 1;
end|
create function mysql.func_1() returns int
begin
return 3;
end|
set @old_sql_mode=@@sql_mode|
set sql_mode=ORACLE|
create package mysql.util_functions as
function f1(id int) return int;
end|
create package body mysql.util_functions as
function f1(id int) return int as result int;
begin
return 10;
end;
end|
delimiter ;|
grant execute on procedure mysql.proc_1 to foo;
grant execute on function mysql.func_1 to foo;
grant execute on package mysql.util_functions to foo;
set sql_mode=@old_sql_mode;
--connect (con1,localhost,foo,,)
show databases;
disconnect con1;
connection default;
deny execute on mysql.* to foo;
--connect (con1,localhost,foo,,)
show databases;
disconnect con1;
connection default;
--replace_regex $REGEX_VERSION_ID
select user, host, JSON_EXTRACT(priv, '$.deny') from mysql.global_priv
where user = 'foo';
show grants for foo;
create database some_db;
grant all on some_db.* to foo;
--connect (con1,localhost,foo,,)
show databases;
disconnect con1;
connection default;
deny all on some_db.* to foo;
--connect (con1,localhost,foo,,)
show databases;
disconnect con1;
connection default;
--echo #
--echo # Removing a deny for show databases globaly should make some_db show up.
--echo #
revoke deny all on *.* from foo;
--connect (con1,localhost,foo,,)
show databases;
disconnect con1;
connection default;
drop database some_db;
drop table mysql.t1;
drop procedure mysql.proc_1;
drop function mysql.func_1;
set @old_sql_mode=@@sql_mode;
set sql_mode=ORACLE;
drop package body mysql.util_functions;
drop package mysql.util_functions;
set sql_mode=@old_sql_mode;
drop user foo;
--echo #
--echo # Test table level denies interacting with show databases
--echo #
--echo # If a user gets access to a database via a higher level grant,
--echo # but has all the resources in that database denied individually,
--echo # the user should still be able to see the database, empty.
--echo #
create database some_db;
create user foo;
create table some_db.t1 (a int);
grant select on *.* to foo;
deny select on some_db.t1 to foo;
--connect (con1,localhost,foo,,)
--echo #
--echo # some_db should still be visible, but it should show up as empty.
--echo #
show databases;
show tables from some_db;
disconnect con1;
connection default;
drop user foo;
drop database some_db;
--echo #
--echo # Test table level denies masking table and column level grants.
--echo #
connection default;
create user foo;
create database some_db;
create table some_db.t1 (a int, b int);
grant select on some_db.t1 to foo;
grant insert(a) on some_db.t1 to foo;
--connect (con1,localhost,foo,,)
use some_db;
show tables;
show full columns from some_db.t1;
disconnect con1;
connection default;
deny select on some_db.t1 to foo;
--connect (con1,localhost,foo,,)
use some_db;
show tables from some_db;
show full columns from some_db.t1;
disconnect con1;
connection default;
deny insert on some_db.t1 to foo;
--echo #
--echo # Now all rights for t1 are denied.
--echo #
--connect (con1,localhost,foo,,)
--error ER_DBACCESS_DENIED_ERROR
use some_db;
--error ER_DBACCESS_DENIED_ERROR
show tables from some_db;
disconnect con1;
connection default;
drop user foo;
drop database some_db;
--echo #
--echo # Test column level denies masking column level grants.
--echo #
connection default;
create user foo;
create database some_db;
create table some_db.t1 (a int, b int);
grant insert(a) on some_db.t1 to foo;
deny select(a) on some_db.t1 to foo;
--connect (con1,localhost,foo,,)
show databases;
use some_db;
show tables from some_db;
show full columns from some_db.t1;
disconnect con1;
connection default;
deny insert(a) on some_db.t1 to foo;
--connect (con1,localhost,foo,,)
show databases;
--error ER_DBACCESS_DENIED_ERROR
use some_db;
--error ER_DBACCESS_DENIED_ERROR
show tables from some_db;
--error ER_TABLEACCESS_DENIED_ERROR
show full columns from some_db.t1;
disconnect con1;
connection default;
grant select(b) on some_db.t1 to foo;
--connect (con1,localhost,foo,,)
show databases;
use some_db;
show tables from some_db;
show full columns from some_db.t1;
disconnect con1;
connection default;
connection default;
deny select(b) on some_db.t1 to foo;
--connect (con1,localhost,foo,,)
show databases;
--error ER_DBACCESS_DENIED_ERROR
use some_db;
--error ER_DBACCESS_DENIED_ERROR
show tables from some_db;
--error ER_TABLEACCESS_DENIED_ERROR
show full columns from some_db.t1;
disconnect con1;
connection default;
drop user foo;
drop database some_db;
|