role.slt 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. mode cockroach
  10. reset-server
  11. # Verify initial roles.
  12. query TTB rowsort
  13. SELECT id, name, inherit FROM mz_roles WHERE id LIKE 's%' OR id LIKE 'g%'
  14. ----
  15. s1 mz_system true
  16. s2 mz_support true
  17. s3 mz_analytics true
  18. g1 mz_monitor true
  19. g2 mz_monitor_redacted true
  20. query TB
  21. SELECT name, inherit FROM mz_roles WHERE id LIKE 'u%'
  22. ----
  23. materialize true
  24. simple conn=mz_support,user=mz_support
  25. SELECT mz_catalog.mz_is_superuser()
  26. ----
  27. f
  28. COMPLETE 1
  29. simple conn=mz_system,user=mz_system
  30. SELECT mz_catalog.mz_is_superuser()
  31. ----
  32. t
  33. COMPLETE 1
  34. # Give materialize the CREATEROLE attribute.
  35. simple conn=mz_system,user=mz_system
  36. GRANT CREATEROLE ON SYSTEM TO materialize
  37. ----
  38. COMPLETE 0
  39. statement error non inherit roles not yet supported
  40. CREATE ROLE foo NOINHERIT
  41. statement error db error: ERROR: SUPERUSER, PASSWORD, and LOGIN attributes is not supported in this environment. For more information consult the documentation at https://materialize.com/docs/sql/create-role/#details
  42. CREATE ROLE foo LOGIN
  43. simple
  44. CREATE ROLE foo SUPERUSER
  45. ----
  46. db error: ERROR: permission denied to create superuser role
  47. DETAIL: You must be a superuser to create superuser role
  48. statement error conflicting or redundant options
  49. CREATE ROLE foo INHERIT INHERIT
  50. statement error CREATEDB attribute is not supported
  51. CREATE ROLE foo CREATEDB
  52. statement error CREATEROLE attribute is not supported
  53. CREATE ROLE foo CREATEROLE
  54. statement error CREATECLUSTER attribute is not supported
  55. CREATE ROLE foo CREATECLUSTER
  56. # Create role and verify its existence.
  57. statement ok
  58. CREATE ROLE rj
  59. statement error CREATE USER is not supported, for more information consult the documentation at
  60. CREATE USER fms
  61. query TB rowsort
  62. SELECT name, inherit FROM mz_roles
  63. ----
  64. materialize true
  65. mz_analytics true
  66. mz_monitor true
  67. mz_monitor_redacted true
  68. mz_support true
  69. mz_system true
  70. rj true
  71. # Dropping multiple roles should not have any effect if one of the role names
  72. # is bad...
  73. statement error unknown role 'bad'
  74. DROP ROLE rj, bad
  75. query T rowsort
  76. SELECT name FROM mz_roles
  77. ----
  78. materialize
  79. mz_analytics
  80. mz_monitor
  81. mz_monitor_redacted
  82. mz_support
  83. mz_system
  84. rj
  85. # ...unless IF EXISTS is specified.
  86. statement ok
  87. DROP ROLE IF EXISTS rj, bad
  88. query T rowsort
  89. SELECT name FROM mz_roles
  90. ----
  91. materialize
  92. mz_analytics
  93. mz_monitor
  94. mz_monitor_redacted
  95. mz_support
  96. mz_system
  97. # Verify that the single name version of DROP ROLE works too.
  98. statement ok
  99. CREATE ROLE nlb
  100. query T rowsort
  101. SELECT name FROM mz_roles
  102. ----
  103. materialize
  104. mz_analytics
  105. mz_monitor
  106. mz_monitor_redacted
  107. mz_support
  108. mz_system
  109. nlb
  110. statement ok
  111. DROP ROLE nlb
  112. query T rowsort
  113. SELECT name FROM mz_roles
  114. ----
  115. mz_system
  116. mz_monitor
  117. mz_support
  118. materialize
  119. mz_analytics
  120. mz_monitor_redacted
  121. statement ok
  122. DROP ROLE IF EXISTS nlb
  123. # No dropping the current role.
  124. statement error current role cannot be dropped
  125. DROP ROLE materialize
  126. # No creating roles that already exist.
  127. statement error role 'materialize' already exists
  128. CREATE ROLE materialize
  129. # No creating roles that look like system roles.
  130. statement error role name "mz_system" is reserved
  131. CREATE ROLE mz_system
  132. statement error role name "mz_foo" is reserved
  133. CREATE ROLE mz_foo
  134. # Create role
  135. statement ok
  136. CREATE ROLE foo
  137. query TB rowsort
  138. SELECT name, inherit FROM mz_roles WHERE name = 'foo'
  139. ----
  140. foo true
  141. statement error non inherit roles not yet supported
  142. ALTER ROLE foo NOINHERIT
  143. statement error role name "mz_system" is reserved
  144. ALTER ROLE mz_system INHERIT
  145. statement error conflicting or redundant options
  146. ALTER ROLE foo INHERIT INHERIT
  147. statement error CREATEDB attribute is not supported
  148. ALTER ROLE foo CREATEDB
  149. statement error CREATEROLE attribute is not supported
  150. ALTER ROLE foo CREATEROLE
  151. statement error CREATECLUSTER attribute is not supported
  152. ALTER ROLE foo CREATECLUSTER
  153. # Prevent creating, dropping, and altering PUBLIC role
  154. statement error role name "public" is reserved
  155. CREATE ROLE puBLic
  156. statement error role name "public" is reserved
  157. DROP ROLE PUBLIC
  158. statement error role name "public" is reserved
  159. ALTER ROLE public INHERIT
  160. query T
  161. SELECT pg_get_userbyid((SELECT oid FROM mz_roles WHERE name = 'materialize'))
  162. ----
  163. materialize
  164. query T
  165. SELECT pg_get_userbyid((SELECT oid FROM mz_roles WHERE name = 'foo'))
  166. ----
  167. foo
  168. query T
  169. SELECT pg_get_userbyid(NULL)
  170. ----
  171. NULL
  172. query T
  173. SELECT pg_get_userbyid(4294967295);
  174. ----
  175. unknown (OID=4294967295)
  176. # Test concurrently dropped role
  177. simple conn=foo,user=foo
  178. SELECT current_user();
  179. ----
  180. foo
  181. COMPLETE 1
  182. statement ok
  183. DROP ROLE foo
  184. simple conn=foo,user=foo
  185. SELECT current_user();
  186. ----
  187. db error: ERROR: role u4 was concurrently dropped
  188. DETAIL: Please disconnect and re-connect with a valid role.
  189. simple conn=mz_system,user=mz_system
  190. DROP CLUSTER mz_system CASCADE;
  191. ----
  192. db error: ERROR: system cluster 'mz_system' cannot be modified
  193. simple conn=mz_system,user=mz_system
  194. DROP CLUSTER mz_catalog_server CASCADE;
  195. ----
  196. db error: ERROR: system cluster 'mz_catalog_server' cannot be modified
  197. statement error role name "external_foo" is reserved
  198. CREATE ROLE external_foo
  199. # Test SHOW ROLES
  200. query TT
  201. SHOW ROLES
  202. ----
  203. materialize (empty)
  204. statement ok
  205. CREATE ROLE foo
  206. query TT
  207. SHOW ROLES
  208. ----
  209. foo (empty)
  210. materialize (empty)
  211. query TT
  212. SHOW ROLES WHERE name = 'foo'
  213. ----
  214. foo (empty)
  215. query TT
  216. SHOW ROLES LIKE 'f%'
  217. ----
  218. foo (empty)