fix: revoke attributed API keys on user deletion - #1488
Open
pjb157 wants to merge 1 commit into
Open
Conversation
Deploying control-layer with
|
| Latest commit: |
d778576
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://7c9ad136.control-layer.pages.dev |
| Branch Preview URL: | https://peter-revoke-deleted-user-ap.control-layer.pages.dev |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR updates the user-deletion flow in dwctl to ensure API keys associated with a deleted user are revoked not only when the key is owned by that user, but also when the key is attributed to them (e.g., org/shared-account key attribution via created_by). This closes a gap where users could retain access through attributed keys in shared account contexts.
Changes:
- Expand the API key revocation query during user deletion to delete keys where
user_id = deleted_userorcreated_by = deleted_user. - Add a regression test that asserts attributed keys are revoked on user deletion while unrelated attributed keys remain active.
- Update the SQLx offline query metadata for the modified DELETE statement.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| dwctl/src/db/handlers/users.rs | Extend user deletion to revoke API keys attributed to the deleted user; add a regression test for shared-account attribution behavior. |
| .sqlx/query-c0ecf188c2d5b41a1192bcc08ad1dea8e744fcc8e6c47913081bc174d3b82f21.json | Update SQLx prepared-query metadata to match the new DELETE predicate. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
484
to
493
| // Only when we actually transitioned the user to deleted (idempotent on | ||
| // repeat calls). Hard-delete keys owned by the user (user_id) — these | ||
| // authenticate as them. Keys they merely created for others (created_by) | ||
| // belong to those users and are left alone. The api_keys DELETE trigger | ||
| // emits NOTIFY, so the onwards proxy drops them from its cache at once. | ||
| // repeat calls). Hard-delete keys owned by or attributed to the user so | ||
| // keys issued in another account context cannot outlive their holder. | ||
| // The api_keys DELETE trigger emits NOTIFY, so the onwards proxy drops | ||
| // them from its cache at once. | ||
| if result.rows_affected() > 0 { | ||
| sqlx::query!(r#"DELETE FROM api_keys WHERE user_id = $1"#, id) | ||
| sqlx::query!(r#"DELETE FROM api_keys WHERE user_id = $1 OR created_by = $1"#, id) | ||
| .execute(&mut *tx) | ||
| .await?; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Testing
cargo test -p dwctl test_delete_user_ -- --test-threads=1(7 passed)just lint rust -- -D warningscargo fmt --all --checkThe complete local Rust suite reached 1,979 passing tests; nine unrelated organization email-domain tests could not initialize the host DNS resolver (
invalid IP address syntax) and also failed when rerun individually.