-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
Copy pathrole
1312 lines (961 loc) · 27.1 KB
/
role
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
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# LogicTest: local
statement error a role/user named admin already exists
CREATE ROLE admin
statement error a role/user named root already exists
CREATE ROLE root
statement ok
CREATE ROLE IF NOT EXISTS root
statement ok
CREATE ROLE IF NOT EXISTS admin
statement error pq: cannot drop role/user admin: grants still exist on .*
DROP ROLE admin
statement error pq: cannot drop role/user root: grants still exist on .*
DROP ROLE root
statement error pq: cannot drop roles/users admin, root: grants still exist on .*
DROP ROLE admin, root
statement ok
CREATE ROLE myrole
query TTT colnames
SHOW ROLES
----
username options member_of
admin CREATEROLE, SETPASSWORD {}
myrole NOLOGIN {}
root CREATEROLE, SETPASSWORD {admin}
testuser · {}
statement error a role/user named myrole already exists
CREATE ROLE myrole
statement ok
CREATE ROLE IF NOT EXISTS myrole
statement error a role/user named myrole already exists
CREATE USER myrole
statement ok
DROP USER myrole
statement ok
CREATE ROLE myrole
statement ok
CREATE USER IF NOT EXISTS myrole
statement error pq: cannot drop roles/users admin, myrole: grants still exist on .*
DROP ROLE admin, myrole
query TTT colnames
SHOW ROLES
----
username options member_of
admin CREATEROLE, SETPASSWORD {}
myrole NOLOGIN {}
root CREATEROLE, SETPASSWORD {admin}
testuser · {}
statement ok
DROP ROLE myrole
query TTT colnames
SHOW ROLES
----
username options member_of
admin CREATEROLE, SETPASSWORD {}
root CREATEROLE, SETPASSWORD {admin}
testuser · {}
statement error pq: role/user myrole does not exist
DROP ROLE myrole
statement ok
DROP ROLE IF EXISTS myrole
statement ok
CREATE ROLE rolea
statement ok
CREATE ROLE roleb
statement ok
CREATE ROLE rolec
statement ok
CREATE ROLE roled
statement error pq: role/user rolee does not exist
DROP ROLE rolea, roleb, rolec, roled, rolee
statement ok
DROP ROLE IF EXISTS rolec, roled, rolee
statement ok
DROP ROLE rolea, roleb
query TTT colnames
SHOW ROLES
----
username options member_of
admin CREATEROLE, SETPASSWORD {}
root CREATEROLE, SETPASSWORD {admin}
testuser · {}
statement ok
CREATE USER testuser2
statement ok
CREATE ROLE testrole
query TTB colnames
SHOW GRANTS ON ROLE
----
role_name member is_admin
admin root true
query TTT colnames,rowsort
SELECT * FROM information_schema.administrable_role_authorizations
----
grantee role_name is_grantable
root admin YES
query TTT colnames,rowsort
SELECT * FROM information_schema.applicable_roles
----
grantee role_name is_grantable
root admin YES
query T colnames,rowsort
SELECT * FROM information_schema.enabled_roles
----
role_name
admin
root
statement error pq: role/user unknownuser does not exist
GRANT testrole TO unknownuser
statement error pq: role/user unknownrole does not exist
GRANT unknownrole TO testuser
# Test role "grant" and WITH ADMIN option.
user testuser
statement error pq: testuser is not a superuser or role admin for role testrole
GRANT testrole TO testuser2
user root
statement ok
GRANT testrole TO testuser
query TTB colnames
SELECT * FROM system.role_members
----
role member isAdmin
admin root true
testrole testuser false
query TTB colnames
SHOW GRANTS ON ROLE
----
role_name member is_admin
admin root true
testrole testuser false
user testuser
statement error pq: testuser is not a superuser or role admin for role testrole
GRANT testrole TO testuser2
user root
statement ok
GRANT testrole TO testuser WITH ADMIN OPTION
query TTB colnames
SELECT * FROM system.role_members
----
role member isAdmin
admin root true
testrole testuser true
user testuser
statement ok
GRANT testrole TO testuser2 WITH ADMIN OPTION
query TTT colnames,rowsort
SELECT * FROM information_schema.administrable_role_authorizations
----
grantee role_name is_grantable
testuser testrole YES
query TTT colnames,rowsort
SELECT * FROM information_schema.applicable_roles
----
grantee role_name is_grantable
testuser testrole YES
query T colnames,rowsort
SELECT * FROM information_schema.enabled_roles
----
role_name
testrole
testuser
user root
statement ok
GRANT admin TO testuser
# Verify that is_admin reports the right value.
query B
SELECT crdb_internal.is_admin()
----
true
# Dropping users/roles deletes all their memberships.
query TTB colnames
SELECT * FROM system.role_members
----
role member isAdmin
admin root true
admin testuser false
testrole testuser true
testrole testuser2 true
query TTB colnames
SHOW GRANTS ON ROLE
----
role_name member is_admin
admin root true
admin testuser false
testrole testuser true
testrole testuser2 true
query TTB colnames
SHOW GRANTS ON ROLE admin
----
role_name member is_admin
admin root true
admin testuser false
query TTB colnames
SHOW GRANTS ON ROLE FOR testuser
----
role_name member is_admin
admin testuser false
testrole testuser true
query TTB colnames
SHOW GRANTS ON ROLE testrole FOR testuser2
----
role_name member is_admin
testrole testuser2 true
query TTB colnames
SHOW GRANTS ON ROLE foo,testrole
----
role_name member is_admin
testrole testuser true
testrole testuser2 true
query TTB colnames
SHOW GRANTS ON ROLE FOR testuser, testuser2
----
role_name member is_admin
admin testuser false
testrole testuser true
testrole testuser2 true
query TTB colnames
SHOW GRANTS ON ROLE admin, testrole FOR root, testuser2
----
role_name member is_admin
admin root true
testrole testuser2 true
statement ok
DROP USER testuser
statement ok
CREATE USER testuser
query TTB colnames
SELECT * FROM system.role_members
----
role member isAdmin
admin root true
testrole testuser2 true
statement ok
DROP ROLE testrole
query TTB colnames
SELECT * FROM system.role_members
----
role member isAdmin
admin root true
# Test cycle detection.
statement error pq: admin cannot be a member of itself
GRANT admin TO admin
statement ok
CREATE ROLE rolea
statement ok
CREATE ROLE roleb
statement ok
CREATE ROLE rolec
statement ok
CREATE ROLE roled
statement ok
GRANT rolea TO roleb
statement error pq: making rolea a member of roleb would create a cycle
GRANT roleb TO rolea
statement ok
GRANT roleb TO rolec
statement ok
GRANT rolec TO roled
statement error pq: rolea cannot be a member of itself
GRANT rolea TO rolea
statement error pq: making rolea a member of roleb would create a cycle
GRANT roleb TO rolea
statement error pq: making rolea a member of rolec would create a cycle
GRANT rolec TO rolea
statement error pq: making rolea a member of roled would create a cycle
GRANT roled TO rolea
statement ok
CREATE ROLE rolee
# Test inherited ADMIN OPTION.
statement ok
GRANT roled TO testuser
statement ok
GRANT rolea TO roleb WITH ADMIN OPTION
user testuser
query TTT colnames,rowsort
SELECT * FROM information_schema.administrable_role_authorizations
----
grantee role_name is_grantable
testuser rolea YES
query TTT colnames,rowsort
SELECT * FROM information_schema.applicable_roles
----
grantee role_name is_grantable
testuser roled NO
testuser rolec NO
testuser roleb NO
testuser rolea YES
query T colnames,rowsort
SELECT * FROM information_schema.enabled_roles
----
role_name
rolea
roleb
rolec
roled
testuser
statement error pq: testuser is not a superuser or role admin for role roled
GRANT roled TO rolee
statement error pq: testuser is not a superuser or role admin for role rolec
GRANT rolec TO rolee
statement error pq: testuser is not a superuser or role admin for role roleb
GRANT roleb TO rolee
statement ok
GRANT rolea TO rolee
query TTT colnames,rowsort
SELECT * FROM information_schema.administrable_role_authorizations
----
grantee role_name is_grantable
testuser rolea YES
query TTT colnames,rowsort
SELECT * FROM information_schema.applicable_roles
----
grantee role_name is_grantable
testuser rolec NO
testuser roleb NO
testuser rolea YES
testuser roled NO
query T colnames,rowsort
SELECT * FROM information_schema.enabled_roles
----
role_name
rolea
roleb
rolec
roled
testuser
user root
query TTB colnames
SELECT * FROM system.role_members
----
role member isAdmin
admin root true
rolea roleb true
rolea rolee false
roleb rolec false
rolec roled false
roled testuser false
statement ok
DROP ROLE rolea
statement ok
DROP ROLE rolec
query TTB colnames
SELECT * FROM system.role_members
----
role member isAdmin
admin root true
roled testuser false
query TTT
SHOW ROLES
----
admin CREATEROLE, SETPASSWORD {}
roleb NOLOGIN {}
roled NOLOGIN {}
rolee NOLOGIN {}
root CREATEROLE, SETPASSWORD {admin}
testuser · {roled}
testuser2 · {}
statement ok
DROP ROLE roleb
statement ok
DROP ROLE roled
statement ok
DROP ROLE rolee
statement error pq: role/user root cannot be removed from role admin or lose the ADMIN OPTION
REVOKE admin FROM root
statement error pq: role/user root cannot be removed from role admin or lose the ADMIN OPTION
REVOKE ADMIN OPTION FOR admin FROM root
statement error pq: role/user unknownuser does not exist
REVOKE ADMIN OPTION FOR admin FROM unknownuser
statement error pq: role/user unknownrole does not exist
REVOKE ADMIN OPTION FOR unknownrole FROM root
statement ok
CREATE ROLE rolea
statement ok
CREATE ROLE roleb
statement ok
GRANT rolea,roleb TO testuser WITH ADMIN OPTION
query TTB colnames
SELECT * FROM system.role_members
----
role member isAdmin
admin root true
rolea testuser true
roleb testuser true
user testuser
statement ok
GRANT rolea,roleb TO root WITH ADMIN OPTION
user root
query TTB colnames
SELECT * FROM system.role_members
----
role member isAdmin
admin root true
rolea root true
rolea testuser true
roleb root true
roleb testuser true
query TTT colnames,rowsort
SELECT * FROM information_schema.administrable_role_authorizations
----
grantee role_name is_grantable
root admin YES
root rolea YES
root roleb YES
query TTT colnames,rowsort
SELECT * FROM information_schema.applicable_roles
----
grantee role_name is_grantable
root admin YES
root rolea YES
root roleb YES
query T colnames,rowsort
SELECT * FROM information_schema.enabled_roles
----
role_name
admin
rolea
roleb
root
user testuser
query TTT colnames,rowsort
SELECT * FROM information_schema.administrable_role_authorizations
----
grantee role_name is_grantable
testuser rolea YES
testuser roleb YES
query TTT colnames,rowsort
SELECT * FROM information_schema.applicable_roles
----
grantee role_name is_grantable
testuser rolea YES
testuser roleb YES
query T colnames,rowsort
SELECT * FROM information_schema.enabled_roles
----
role_name
rolea
roleb
testuser
statement ok
REVOKE ADMIN OPTION FOR rolea FROM testuser
statement error pq: testuser is not a superuser or role admin for role rolea
REVOKE ADMIN OPTION FOR rolea FROM root
statement ok
REVOKE roleb FROM root
user root
query TTB colnames
SELECT * FROM system.role_members
----
role member isAdmin
admin root true
rolea root true
rolea testuser false
roleb testuser true
statement ok
REVOKE rolea, roleb FROM testuser, root
query TTB colnames
SELECT * FROM system.role_members
----
role member isAdmin
admin root true
# Test privilege checks.
statement ok
CREATE DATABASE db1
user testuser
statement error only users with the admin role are allowed to CREATE DATABASE
CREATE DATABASE db2
statement error user testuser does not have DROP privilege on database db1
DROP DATABASE db1
statement error testuser is not a role admin for role admin
GRANT admin TO testuser
user root
statement ok
CREATE ROLE newgroup
statement ok
GRANT newgroup TO testuser
statement ok
GRANT admin TO newgroup
user testuser
query TTB colnames
SELECT * FROM system.role_members
----
role member isAdmin
admin newgroup false
admin root true
newgroup testuser false
statement ok
CREATE DATABASE db2
statement ok
DROP DATABASE db1
# Revoke admin privileges. 'newgroup' does not have any privileges.
user root
statement ok
REVOKE admin FROM newgroup
user testuser
statement error user testuser does not have SELECT privilege on relation role_members
SELECT * FROM system.role_members
statement error user testuser does not have CREATE privilege on database db2
CREATE TABLE db2.foo (k int);
user root
query TTB colnames
SELECT * FROM system.role_members
----
role member isAdmin
admin root true
newgroup testuser false
statement ok
GRANT ALL ON DATABASE db2 TO newgroup
user testuser
query TTTT colnames
SHOW GRANTS ON DATABASE db2
----
database_name schema_name grantee privilege_type
db2 crdb_internal admin ALL
db2 crdb_internal newgroup ALL
db2 crdb_internal root ALL
db2 information_schema admin ALL
db2 information_schema newgroup ALL
db2 information_schema root ALL
db2 pg_catalog admin ALL
db2 pg_catalog newgroup ALL
db2 pg_catalog root ALL
db2 pg_extension admin ALL
db2 pg_extension newgroup ALL
db2 pg_extension root ALL
db2 public admin ALL
db2 public newgroup ALL
db2 public root ALL
statement ok
CREATE TABLE db2.foo (k int);
statement ok
INSERT INTO db2.foo VALUES (1),(2),(3);
statement ok
SELECT * FROM db2.foo
# We may be in the 'newgroup', but we don't have the admin option.
statement error testuser is not a superuser or role admin for role newgroup
GRANT newgroup TO testuser2
statement error testuser is not a superuser or role admin for role newgroup
REVOKE newgroup FROM testuser
statement error testuser is not a superuser or role admin for role newgroup
GRANT newgroup TO testuser WITH ADMIN OPTION
# Regression for #31784
user root
# grant admin to testuser without ADMIN OPTION
statement ok
CREATE USER user1;
GRANT admin TO testuser
user testuser
statement error pq: testuser is not a role admin for role admin
GRANT admin TO user1
statement error pq: testuser is not a role admin for role admin
REVOKE admin FROM user1
user root
# WITH ADMIN OPTION means that testuser now has permission to add to the admin role
statement ok
GRANT admin TO testuser WITH ADMIN OPTION
user testuser
statement ok
GRANT admin TO user1
statement ok
REVOKE admin FROM user1
user root
statement ok
DROP USER user1
user root
# The user does not have direct privileges on anything, so we can drop it.
statement ok
DROP USER testuser
query TTB colnames
SELECT * FROM system.role_members
----
role member isAdmin
admin root true
statement error cannot drop role/user newgroup: grants still exist on db2, db2.public.foo
DROP ROLE newgroup
statement ok
REVOKE ALL ON db2.* FROM newgroup
statement ok
REVOKE ALL ON DATABASE db2 FROM newgroup
statement ok
DROP ROLE newgroup
# Test the "public" pseudo-role.
statement error role name "public" is reserved
CREATE USER public
statement error role name "public" is reserved
CREATE ROLE public
statement error cannot drop role/user public: grants still exist on system.public.comments
DROP USER public
statement error cannot drop role/user public: grants still exist on system.public.comments
DROP ROLE public
statement error role/user public does not exist
GRANT public TO testuser
statement error role/user public does not exist
GRANT admin TO public
statement error role/user public does not exist
REVOKE public FROM testuser
statement error role/user public does not exist
REVOKE admin FROM public
# Test "WITH CREATEROLE" option
statement ok
CREATE USER testuser
query TTB colnames
SELECT * FROM system.role_members
----
role member isAdmin
admin root true
user testuser
statement error pq: user testuser does not have CREATEROLE privilege
CREATE ROLE rolef
user root
statement ok
ALTER ROLE testuser CREATEROLE
user testuser
statement ok
CREATE ROLE rolef
statement ok
ALTER ROLE rolef LOGIN
statement ok
DROP ROLE rolef
# Testing invalid CREATEROLE combinations
user root
statement ok
ALTER ROLE testuser NOCREATEROLE
statement error pq: conflicting role options
CREATE ROLE rolewithcreate WITH NOCREATEROLE CREATEROLE
statement error pq: conflicting role options
CREATE ROLE rolewithcreate NOCREATEROLE CREATEROLE
statement error pq: conflicting role options
ALTER ROLE testrole WITH CREATEROLE NOCREATEROLE
statement error pq: conflicting role options
ALTER ROLE testrole CREATEROLE NOCREATEROLE
statement error pq: redundant role options
CREATE ROLE rolewithcreate WITH CREATEROLE CREATEROLE
statement error pq: redundant role options
CREATE ROLE rolewithcreate WITH NOCREATEROLE NOCREATEROLE
statement error pq: redundant role options
ALTER ROLE testrole WITH CREATEROLE CREATEROLE
statement error pq: redundant role options
ALTER ROLE testrole WITH NOCREATEROLE NOCREATEROLE
statement ok
CREATE ROLE rolewithcreate WITH CREATEROLE
statement ok
CREATE ROLE anotherrolewithcreate CREATEROLE
statement ok
CREATE ROLE rolewithoutcreate WITH NOCREATEROLE
statement ok
CREATE ROLE IF NOT EXISTS rolewithcreate2 WITH CREATEROLE
statement ok
CREATE ROLE IF NOT EXISTS anotherrolewithcreate2 CREATEROLE
statement ok
CREATE ROLE IF NOT EXISTS rolewithoutcreate2 WITH NOCREATEROLE
query TTB colnames
SELECT * FROM system.role_members
----
role member isAdmin
admin root true
user testuser
# User should not have permissions to CREATE / ALTER role without CREATEROLE privilege
statement error pq: user testuser does not have CREATEROLE privilege
CREATE ROLE rolewithcreate3 WITH CREATEROLE
statement error pq: user testuser does not have CREATEROLE privilege
ALTER ROLE rolewithcreate WITH NOCREATEROLE
user root
statement ok
GRANT rolewithcreate TO testuser
user testuser
statement ok
CREATE ROLE roleg WITH CREATEROLE
statement ok
ALTER ROLE roleg WITH NOCREATEROLE
statement ok
DROP ROLE roleg
statement ok
CREATE ROLE IF NOT EXISTS roleg
statement ok
CREATE ROLE IF NOT EXISTS roleg
# Need Admin option to GRANT role, CREATEROLE should not give GRANT role privilege for other roles
statement ok
CREATE USER testuser3
statement error pq: testuser is not a role admin for role admin
GRANT admin to testuser3
statement error pq: testuser is not a superuser or role admin for role roleg
GRANT roleg to testuser3
user root
statement ok
ALTER ROLE rolewithcreate WITH NOCREATEROLE
statement ok
ALTER ROLE rolewithcreate NOCREATEROLE
statement error pq: cannot edit admin role
ALTER ROLE admin with NOCREATEROLE
query TTB colnames
SELECT * FROM system.role_members
----
role member isAdmin
admin root true
rolewithcreate testuser false
# testuser should no longer have CREATEROLE privileges
user testuser
statement error pq: user testuser does not have CREATEROLE privilege
CREATE ROLE roleh WITH CREATEROLE
statement error pq: user testuser does not have CREATEROLE privilege
ALTER ROLE roleg with NOCREATEROLE
statement error pq: user testuser does not have CREATEROLE privilege
DROP ROLE roleg
statement error pq: user testuser does not have CREATEROLE privilege
CREATE ROLE IF NOT EXISTS rolewithcreate WITH CREATEROLE
statement error pq: user testuser does not have CREATEROLE privilege
CREATE USER testuser4
statement error pq: user testuser does not have CREATEROLE privilege
ALTER USER testuser3 WITH PASSWORD 'ilov3beefjerky'
user root
statement error pq: role/user rolek does not exist
ALTER ROLE rolek CREATEROLE
statement ok
ALTER ROLE IF EXISTS rolek CREATEROLE
statement ok
ALTER USER IF EXISTS rolek NOCREATEROLE
statement ok
ALTER USER rolewithcreate WITH NOCREATEROLE
statement ok
ALTER ROLE rolewithcreate CREATEROLE
user testuser
statement ok
CREATE ROLE IF NOT EXISTS rolei WITH NOCREATEROLE
statement ok
DROP ROLE rolewithcreate
statement error pq: user testuser does not have CREATEROLE privilege
CREATE ROLE rolewithcreate
statement error pq: user testuser does not have CREATEROLE privilege
CREATE ROLE IF NOT EXISTS roleh WITH CREATEROLE
# Testing nested role privilege
user root
statement ok
CREATE USER childrole WITH NOCREATEROLE
statement ok
CREATE ROLE parentrole WITH CREATEROLE
statement ok
GRANT parentrole TO childrole
statement ok
GRANT childrole to testuser