You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
151472: sql: fix DROP USER to detect default privilege dependencies r=rafiss a=spilchen
Prior to this fix, DROP USER would succeed even when a role had created default privilege rules, leaving orphaned default privilege entries that referenced non-existent roles.
The issue occurred because the dependency detection logic only checked for roles that had privileges granted to them, but missed the case where a role was the creator of default privileges through REVOKE operations. When default privileges are created with REVOKE (e.g., "ALTER DEFAULT PRIVILEGES FOR ROLE user REVOKE EXECUTE ON ROUTINES FROM public"), the grantee list becomes empty, so the original logic didn't detect the dependency.
This fix adds explicit detection of creator dependencies for default privileges, ensuring that roles cannot be dropped if they own default privilege rules.
Fixes#150543.
Release note (bug fix): Fixed DROP USER succeeding when a role owned default privileges, which could leave invalid privilege entries in the system.
Epic: None
Co-authored-by: Matt Spilchen <[email protected]>
Copy file name to clipboardExpand all lines: pkg/sql/logictest/testdata/logic_test/drop_user
+75Lines changed: 75 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -215,3 +215,78 @@ statement error role schema_owner cannot be dropped because some objects depend
215
215
DROP ROLE schema_owner
216
216
217
217
subtest end
218
+
219
+
# Regression test for #150543. Ensure that DROP USER is blocked when role has
220
+
# default privileges.
221
+
subtest default_privileges_dependency
222
+
223
+
statement ok
224
+
CREATE USER default_priv_user
225
+
226
+
# Create default privileges with REVOKE. Target routines and types initially. These undo
227
+
# the implicitly created default privileges for new roles.
228
+
statement ok
229
+
ALTER DEFAULT PRIVILEGES FOR ROLE default_priv_user REVOKE EXECUTE ON ROUTINES FROM public
230
+
231
+
statement ok
232
+
ALTER DEFAULT PRIVILEGES FOR ROLE default_priv_user REVOKE USAGE ON TYPES FROM public
233
+
234
+
# The next threes REVOKE's are essentially no-op since they don't change anything
235
+
# as nothing was implicitly granted for them.
236
+
statement ok
237
+
ALTER DEFAULT PRIVILEGES FOR ROLE default_priv_user REVOKE USAGE ON SEQUENCES FROM public
238
+
239
+
statement ok
240
+
ALTER DEFAULT PRIVILEGES FOR ROLE default_priv_user REVOKE ALL ON TABLES FROM public
241
+
242
+
statement ok
243
+
ALTER DEFAULT PRIVILEGES FOR ROLE default_priv_user REVOKE ALL ON SCHEMAS FROM public
244
+
245
+
statement error role default_priv_user cannot be dropped because some objects depend on it\nowner of default privileges that revokes privileges of routines from public in database test\nowner of default privileges that revokes privileges of types from public in database test\nHINT: USE test; ALTER DEFAULT PRIVILEGES FOR ROLE default_priv_user GRANT EXECUTE ON ROUTINES TO public;\nUSE test; ALTER DEFAULT PRIVILEGES FOR ROLE default_priv_user GRANT USAGE ON TYPES TO public;
246
+
DROP USER default_priv_user
247
+
248
+
# Test with GRANT case
249
+
statement ok
250
+
CREATE USER default_priv_user2
251
+
252
+
statement ok
253
+
ALTER DEFAULT PRIVILEGES FOR ROLE default_priv_user2 GRANT ALL ON TABLES TO public
254
+
255
+
statement ok
256
+
ALTER DEFAULT PRIVILEGES FOR ROLE default_priv_user2 GRANT ALL ON SCHEMAS TO public
257
+
258
+
statement ok
259
+
ALTER DEFAULT PRIVILEGES FOR ROLE default_priv_user2 GRANT USAGE ON SEQUENCES TO public
260
+
261
+
statement error role default_priv_user2 cannot be dropped because some objects depend on it\nowner of default privileges on new relations belonging to role default_priv_user2 in database test\nowner of default privileges on new schemas belonging to role default_priv_user2 in database test\nowner of default privileges on new sequences belonging to role default_priv_user2 in database test\nHINT: USE test; ALTER DEFAULT PRIVILEGES FOR ROLE default_priv_user2 REVOKE ALL ON TABLES FROM public;\nUSE test; ALTER DEFAULT PRIVILEGES FOR ROLE default_priv_user2 REVOKE ALL ON SCHEMAS FROM public;\nUSE test; ALTER DEFAULT PRIVILEGES FOR ROLE default_priv_user2 REVOKE ALL ON SEQUENCES FROM public;
262
+
DROP USER default_priv_user2
263
+
264
+
# Clean up for successful drop
265
+
statement ok
266
+
ALTER DEFAULT PRIVILEGES FOR ROLE default_priv_user GRANT EXECUTE ON FUNCTIONS TO public
267
+
268
+
statement ok
269
+
ALTER DEFAULT PRIVILEGES FOR ROLE default_priv_user GRANT USAGE ON TYPES TO public
270
+
271
+
statement ok
272
+
ALTER DEFAULT PRIVILEGES FOR ROLE default_priv_user2 REVOKE ALL ON TABLES FROM public
273
+
274
+
statement ok
275
+
ALTER DEFAULT PRIVILEGES FOR ROLE default_priv_user2 REVOKE ALL ON SCHEMAS FROM public
276
+
277
+
statement ok
278
+
ALTER DEFAULT PRIVILEGES FOR ROLE default_priv_user2 REVOKE USAGE ON SEQUENCES FROM public
279
+
280
+
statement ok
281
+
DROP USER default_priv_user
282
+
283
+
statement ok
284
+
DROP USER default_priv_user2
285
+
286
+
# Ensure there are no invalid objects left around. This was how the issue was
287
+
# found prior to #150543.
288
+
query TTTT
289
+
SELECT database_name, schema_name, obj_name, error FROM crdb_internal.invalid_objects;
0 commit comments