singlereplica_audit_log.slt 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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. # Test expected population of mz_audit_events after some DDL statements.
  10. mode cockroach
  11. # Start from a pristine server
  12. reset-server
  13. statement ok
  14. CREATE DATABASE test
  15. statement ok
  16. CREATE SCHEMA test.sc1
  17. statement ok
  18. CREATE SCHEMA test.sc2
  19. statement ok
  20. DROP SCHEMA test.sc1
  21. statement ok
  22. DROP DATABASE test
  23. statement ok
  24. CREATE ROLE foo
  25. statement ok
  26. DROP ROLE foo
  27. statement ok
  28. CREATE CLUSTER foo REPLICAS (r (SIZE '1'));
  29. statement ok
  30. CREATE MATERIALIZED VIEW v2 AS SELECT 1
  31. statement ok
  32. CREATE VIEW unmat AS SELECT 1
  33. statement ok
  34. CREATE TABLE t ()
  35. statement ok
  36. CREATE DEFAULT INDEX ON t
  37. statement ok
  38. ALTER VIEW unmat RENAME TO renamed
  39. statement ok
  40. CREATE OR REPLACE MATERIALIZED VIEW v2 AS SELECT 2
  41. statement ok
  42. CREATE DEFAULT INDEX ON renamed
  43. statement ok
  44. DROP VIEW renamed
  45. statement ok
  46. CREATE SOURCE s FROM LOAD GENERATOR COUNTER;
  47. statement ok
  48. DROP SOURCE s;
  49. statement ok
  50. CREATE SOURCE multiplex FROM LOAD GENERATOR AUCTION;
  51. statement ok
  52. CREATE TABLE accounts FROM SOURCE multiplex (REFERENCE accounts);
  53. statement ok
  54. CREATE TABLE auctions FROM SOURCE multiplex (REFERENCE auctions);
  55. statement ok
  56. CREATE TABLE bids FROM SOURCE multiplex (REFERENCE bids);
  57. statement ok
  58. CREATE TABLE organizations FROM SOURCE multiplex (REFERENCE organizations);
  59. statement ok
  60. CREATE TABLE users FROM SOURCE multiplex (REFERENCE users);
  61. statement ok
  62. ALTER CLUSTER REPLICA foo.r RENAME TO s;
  63. statement ok
  64. COMMENT ON CLUSTER foo IS 'test comment'
  65. statement ok
  66. COMMENT ON CLUSTER foo IS NULL
  67. statement ok
  68. ALTER CLUSTER foo RENAME TO bar;
  69. statement ok
  70. DROP CLUSTER REPLICA bar.s;
  71. statement ok
  72. DROP CLUSTER bar;
  73. statement ok
  74. ALTER MATERIALIZED VIEW v2 SET (RETAIN HISTORY FOR '5m');
  75. statement ok
  76. ALTER MATERIALIZED VIEW v2 RESET (RETAIN HISTORY);
  77. statement ok
  78. COMMENT ON MATERIALIZED VIEW v2 IS 'test comment'
  79. statement ok
  80. CREATE CONNECTION conn TO SSH TUNNEL (HOST 'host', PORT 22, USER 'materialize')
  81. statement ok
  82. ALTER CONNECTION conn ROTATE KEYS
  83. simple conn=mz_system,user=mz_system
  84. ALTER SYSTEM SET max_aws_privatelink_connections = '10'
  85. ----
  86. COMPLETE 0
  87. simple conn=mz_system,user=mz_system
  88. ALTER SYSTEM RESET max_aws_privatelink_connections
  89. ----
  90. COMPLETE 0
  91. simple conn=mz_system,user=mz_system
  92. ALTER SYSTEM RESET ALL
  93. ----
  94. COMPLETE 0
  95. query ITTTT
  96. SELECT id, event_type, object_type, details, user FROM mz_audit_events ORDER BY id
  97. ----
  98. 1 create role {"id":"u1","name":"materialize"} NULL
  99. 2 grant cluster {"database_id":null,"grantee_id":"s2","privileges":"U","role_id":"p","schema_id":null} NULL
  100. 3 grant database {"database_id":null,"grantee_id":"s2","privileges":"U","role_id":"p","schema_id":null} NULL
  101. 4 grant schema {"database_id":null,"grantee_id":"s2","privileges":"U","role_id":"p","schema_id":null} NULL
  102. 5 grant type {"database_id":null,"grantee_id":"p","privileges":"U","role_id":"p","schema_id":null} NULL
  103. 6 create database {"id":"u1","name":"materialize"} NULL
  104. 7 grant database {"grantee_id":"p","grantor_id":"s1","object_id":"Du1","privileges":"U"} NULL
  105. 8 grant database {"grantee_id":"u1","grantor_id":"s1","object_id":"Du1","privileges":"UC"} NULL
  106. 9 create schema {"database_name":"materialize","id":"3","name":"public"} NULL
  107. 10 grant schema {"grantee_id":"u1","grantor_id":"s1","object_id":"Su1.u3","privileges":"UC"} NULL
  108. 11 create network-policy {"id":"u1","name":"default"} NULL
  109. 12 create cluster {"id":"u1","name":"quickstart"} NULL
  110. 13 grant cluster {"grantee_id":"p","grantor_id":"s1","object_id":"Cu1","privileges":"U"} NULL
  111. 14 grant cluster {"grantee_id":"u1","grantor_id":"s1","object_id":"Cu1","privileges":"UC"} NULL
  112. 15 create cluster-replica {"billed_as":null,"cluster_id":"u1","cluster_name":"quickstart","disk":false,"internal":false,"logical_size":"2","reason":"system","replica_id":"u1","replica_name":"r1"} NULL
  113. 16 grant system {"grantee_id":"s1","grantor_id":"s1","object_id":"SYSTEM","privileges":"RBNP"} NULL
  114. 17 grant system {"grantee_id":"u1","grantor_id":"s1","object_id":"SYSTEM","privileges":"RBNP"} NULL
  115. 18 alter system {"name":"enable_reduce_mfp_fusion","value":"on"} mz_system
  116. 19 alter system {"name":"unsafe_enable_unsafe_functions","value":"on"} mz_system
  117. 20 create database {"id":"u2","name":"test"} materialize
  118. 21 create schema {"database_name":"test","id":"u9","name":"public"} materialize
  119. 22 create schema {"database_name":"test","id":"u10","name":"sc1"} materialize
  120. 23 create schema {"database_name":"test","id":"u11","name":"sc2"} materialize
  121. 24 drop schema {"database_name":"test","id":"u10","name":"sc1"} materialize
  122. 25 drop schema {"database_name":"test","id":"u9","name":"public"} materialize
  123. 26 drop schema {"database_name":"test","id":"u11","name":"sc2"} materialize
  124. 27 drop database {"id":"u2","name":"test"} materialize
  125. 28 create role {"id":"u2","name":"foo"} materialize
  126. 29 drop role {"id":"u2","name":"foo"} materialize
  127. 30 create cluster {"id":"u2","name":"foo"} materialize
  128. 31 create cluster-replica {"billed_as":null,"cluster_id":"u2","cluster_name":"foo","disk":true,"internal":false,"logical_size":"1","reason":"manual","replica_id":"u2","replica_name":"r"} materialize
  129. 32 create materialized-view {"cluster_id":"u1","database":"materialize","id":"u1","item":"v2","schema":"public"} materialize
  130. 33 create view {"database":"materialize","id":"u2","item":"unmat","schema":"public"} materialize
  131. 34 create table {"database":"materialize","id":"u3","item":"t","schema":"public"} materialize
  132. 35 create index {"cluster_id":"u1","database":"materialize","id":"u4","item":"t_primary_idx","schema":"public"} materialize
  133. 36 alter view {"id":"u2","new_name":{"database":"materialize","item":"renamed","schema":"public"},"old_name":{"database":"materialize","item":"unmat","schema":"public"}} materialize
  134. 37 drop materialized-view {"database":"materialize","id":"u1","item":"v2","schema":"public"} materialize
  135. 38 create materialized-view {"cluster_id":"u1","database":"materialize","id":"u5","item":"v2","schema":"public"} materialize
  136. 39 create index {"cluster_id":"u1","database":"materialize","id":"u6","item":"renamed_primary_idx","schema":"public"} materialize
  137. 40 drop index {"database":"materialize","id":"u6","item":"renamed_primary_idx","schema":"public"} materialize
  138. 41 drop view {"database":"materialize","id":"u2","item":"renamed","schema":"public"} materialize
  139. 42 create source {"cluster_id":null,"database":"materialize","id":"u7","item":"s_progress","schema":"public","type":"progress"} materialize
  140. 43 create source {"cluster_id":"u1","database":"materialize","id":"u8","item":"s","schema":"public","type":"load-generator"} materialize
  141. 44 drop source {"database":"materialize","id":"u8","item":"s","schema":"public"} materialize
  142. 45 drop source {"database":"materialize","id":"u7","item":"s_progress","schema":"public"} materialize
  143. 46 create source {"cluster_id":null,"database":"materialize","id":"u9","item":"multiplex_progress","schema":"public","type":"progress"} materialize
  144. 47 create source {"cluster_id":"u1","database":"materialize","id":"u10","item":"multiplex","schema":"public","type":"load-generator"} materialize
  145. 48 create table {"database":"materialize","id":"u11","item":"accounts","schema":"public"} materialize
  146. 49 create table {"database":"materialize","id":"u12","item":"auctions","schema":"public"} materialize
  147. 50 create table {"database":"materialize","id":"u13","item":"bids","schema":"public"} materialize
  148. 51 create table {"database":"materialize","id":"u14","item":"organizations","schema":"public"} materialize
  149. 52 create table {"database":"materialize","id":"u15","item":"users","schema":"public"} materialize
  150. 53 alter cluster-replica {"cluster_id":"u2","new_name":"s","old_name":"r","replica_id":"u2"} materialize
  151. 54 comment cluster {"id":"Cluster(User(2))","name":"foo"} materialize
  152. 55 comment cluster {"id":"Cluster(User(2))","name":"foo"} materialize
  153. 56 alter cluster {"id":"u2","new_name":"bar","old_name":"foo"} materialize
  154. 57 drop cluster-replica {"cluster_id":"u2","cluster_name":"bar","reason":"manual","replica_id":"u2","replica_name":"s"} materialize
  155. 58 drop cluster {"id":"u2","name":"bar"} materialize
  156. 59 alter materialized-view {"id":"u5","new_history":"'5m'","old_history":null} materialize
  157. 60 alter materialized-view {"id":"u5","new_history":null,"old_history":"FOR␠'5m'"} materialize
  158. 61 comment materialized-view {"id":"MaterializedView(User(5))","name":"materialize.public.v2"} materialize
  159. 62 create connection {"database":"materialize","id":"u16","item":"conn","schema":"public"} materialize
  160. 63 alter connection {"database":"materialize","id":"u16","item":"conn","schema":"public"} materialize
  161. 64 alter system {"name":"max_aws_privatelink_connections","value":"10"} mz_system
  162. 65 alter system {"name":"max_aws_privatelink_connections","value":null} mz_system
  163. 66 alter system null mz_system
  164. simple conn=mz_system,user=mz_system
  165. ALTER SYSTEM SET unsafe_mock_audit_event_timestamp = 666
  166. ----
  167. COMPLETE 0
  168. statement ok
  169. CREATE TABLE tt ()
  170. query ITTTTT
  171. SELECT id, event_type, object_type, details, user, occurred_at FROM mz_audit_events ORDER BY id DESC LIMIT 1
  172. ----
  173. 68 create table {"database":"materialize","id":"u17","item":"tt","schema":"public"} materialize 1970-01-01␠00:00:00.666+00
  174. simple conn=mz_system,user=mz_system
  175. ALTER SYSTEM RESET unsafe_mock_audit_event_timestamp
  176. ----
  177. COMPLETE 0
  178. statement ok
  179. DROP TABLE tt
  180. query B
  181. SELECT occurred_at::text = '1970-01-01 00:00:00.666+00' FROM mz_audit_events ORDER BY id DESC LIMIT 1
  182. ----
  183. false
  184. query TTTTBBBT
  185. SELECT replica_id, cluster_name, replica_name, size, created_at IS NOT NULL, dropped_at IS NOT NULL, created_at < dropped_at, credits_per_hour FROM mz_internal.mz_cluster_replica_history ORDER BY created_at
  186. ----
  187. u1 quickstart r1 2 true false NULL 1
  188. u2 foo r 1 true true true 1
  189. simple conn=mz_system,user=mz_system
  190. CREATE ROLE r1;
  191. ----
  192. COMPLETE 0
  193. simple conn=mz_system,user=mz_system
  194. GRANT SELECT ON t TO r1;
  195. ----
  196. COMPLETE 0
  197. query ITTTT
  198. SELECT id, event_type, object_type, details, user FROM mz_audit_events ORDER BY id DESC LIMIT 1
  199. ----
  200. 72 grant table {"grantee_id":"u3","grantor_id":"u1","object_id":"Iu3","privileges":"r"} mz_system
  201. simple conn=mz_system,user=mz_system
  202. REVOKE SELECT ON t FROM r1;
  203. ----
  204. COMPLETE 0
  205. query ITTTT
  206. SELECT id, event_type, object_type, details, user FROM mz_audit_events ORDER BY id DESC LIMIT 1
  207. ----
  208. 73 revoke table {"grantee_id":"u3","grantor_id":"u1","object_id":"Iu3","privileges":"r"} mz_system
  209. simple conn=mz_system,user=mz_system
  210. ALTER DEFAULT PRIVILEGES FOR ROLE r1 IN SCHEMA public GRANT SELECT ON TABLES to PUBLIC;
  211. ----
  212. COMPLETE 0
  213. query ITTTT
  214. SELECT id, event_type, object_type, details, user FROM mz_audit_events ORDER BY id DESC LIMIT 1
  215. ----
  216. 74 grant table {"database_id":"u1","grantee_id":"p","privileges":"r","role_id":"u3","schema_id":"u3"} mz_system
  217. simple conn=mz_system,user=mz_system
  218. ALTER DEFAULT PRIVILEGES FOR ROLE r1 IN SCHEMA public REVOKE SELECT ON TABLES FROM PUBLIC;
  219. ----
  220. COMPLETE 0
  221. query ITTTT
  222. SELECT id, event_type, object_type, details, user FROM mz_audit_events ORDER BY id DESC LIMIT 1
  223. ----
  224. 75 revoke table {"database_id":"u1","grantee_id":"p","privileges":"r","role_id":"u3","schema_id":"u3"} mz_system
  225. statement ok
  226. CREATE TABLE t1 (a INT);
  227. simple conn=mz_system,user=mz_system
  228. ALTER TABLE t1 OWNER to r1;
  229. ----
  230. COMPLETE 0
  231. query ITTTT
  232. SELECT id, event_type, object_type, details, user FROM mz_audit_events ORDER BY id DESC LIMIT 1
  233. ----
  234. 77 alter table {"new_owner_id":"u3","object_id":"Iu18","old_owner_id":"u1"} mz_system
  235. # Test events for auto-created users, which have the username only in the event details, but not the user column.
  236. simple conn=c,user=new_user
  237. SELECT 1
  238. ----
  239. 1
  240. COMPLETE 1
  241. query ITTTT
  242. SELECT id, event_type, object_type, details, user FROM mz_audit_events ORDER BY id DESC LIMIT 1
  243. ----
  244. 78 create role {"id":"u4","name":"new_user"} NULL