Repository navigation
Delete role assignments when locally-managed users / groups are deleted - #11713
charliepark wants to merge 10 commits into
Conversation
|
@claude review |
There was a problem hiding this comment.
I reviewed this PR and found no bugs. Because it changes how authorization data (role assignments) is deleted across project, user and silo deletion, a human look is still worthwhile.
What was reviewed:
- The new
role_assignment_delete_by_identity_on_connectionandrole_assignment_delete_by_resource_on_connectionhelpers in role.rs, and how project.rs, silo_user.rs, scim_provider_store.rs and the silo delete transaction call them. - The bulk deletes outside the transaction in silo.rs. They run before users and groups are soft-deleted, and their subquery filters (silo_id, time_deleted IS NULL, user_provision_type) match the partial indexes on silo_user and silo_group. The identity-side delete can use
lookup_role_assignment_by_identity_id. - Removing
silo_group_delete, which nothing called, and the imports only it used.
Extended reasoning...
The change touches role assignment cleanup in six datastore files and adds a schema join allowance. It also adds integration tests for project, silo, user and group deletion. The surface it touches is authorization data: it deletes rows that grant permissions on silos and projects. No query was found that deletes too much or too little, and the indexes support the new subqueries. It is deferred rather than approved because it is a non-trivial change to permission-related data paths, and the silo bulk deletes run outside the transaction.
|
I had some questions about what happens when you do what actions in different kinds of silos.
|
| pub(super) async fn role_assignment_delete_by_identity_on_connection( | ||
| &self, | ||
| conn: &async_bb8_diesel::Connection<DbConnection>, | ||
| identity_type: IdentityType, |
There was a problem hiding this comment.
You could drop IdentityType here because there is only ever going to be one type for the ID anyway. Passing the type at the callsite feels kind of like a safeguard, but it isn't really. It would just do nothing if it was the wrong type, and only a test expecting the assignment to go away (which you have) would catch the problem.
In working on a console PR (oxidecomputer/console#3211) I discovered that #8605 was still open. (#9276 handled deletion of role assignments for SCIM-managed users / groups, but not for local ones). This PR adds a method that handles the deletion of role assignments for locally-managed users and groups, and calls it when the user / group is deleted. It also deletes silo-scoped role assignments when a silo is deleted.
Note: there is no method to delete groups locally, but deleting a silo without addressing the roles would leave some orphaned rows, so this code cleans up the roles during the silo deletion process.
"But wait!", I hear you say, "what about the orphaned rows from users that have already been deleted from the silo? Isn't that what prompted #8605 in the first place?" Good question. That is outside the scope of this PR, but the robot suggests there's a migration from before that covers similar territory:
schema/crdb/cleanup-orphaned-subnet-pool-silo-links(version 248):So that's something we can talk through separately.
Unrelated, but I also came across some old uncalled code in
silo_group_delete; this PR removes that method as well.#8605 will still be open after this merges. We will need to clean up the leftover rows, per the note above, to fully close that issue.