Repository navigation
feat(service-accounts): Soft-delete service accounts - #129950
Merged
Merged
Conversation
Deleting a service account now keeps the row with is_active=False, the way deleting a user works, instead of hard-deleting it. No tombstone is written, so cell tables that point at the account (dashboards, saved queries, investigations, Seer workflows) keep their reference. Project links are removed and all_projects is cleared. The cell replica stays and replicates is_active=False, which every replica reader already checks. Control-side lookups (list, details, PUT, and the RPC get/update/delete) hide deleted accounts. POST and PUT now reject isActive=false with a 400, since an account can no longer be paused; isActive=true is still accepted so generated clients keep working. Co-Authored-By: Shaun Kaasten <[email protected]> Co-Authored-By: Shaun Kaasten <[email protected]>
Deleting is the only way to turn a service account off, and deleted accounts return 404, so isActive was always true in responses and could only be set to true in requests. Seer's generated client has the field, but no Seer code reads or sends it. Co-Authored-By: Shaun Kaasten <[email protected]>
Contributor
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 4a9aa71. Configure here.
gricha
approved these changes
Nov 4, 2026
skaasten
pushed a commit
that referenced
this pull request
Nov 6, 2026
This is part 1 of the service account access tokens plan. It's the first PR in a stack: 1. **This PR**: the control `ServiceAccountToken` model and its table. 2. #130108: replicating tokens to the cell (`ServiceAccountTokenReplica`, the outbox and the RPC method). Nothing creates, reads or authenticates tokens yet. **What changes** `ServiceAccountToken` is a plain control silo model in this PR. The next PR makes it a `ReplicatedControlModel`, which needs no schema change. - Only `token_hashed` (unique) and `token_last_characters` are stored. The plaintext is never stored. - Each token has its own `scope_list`, validated with `validate_grantable_scopes`. The authenticator will intersect it with the account's current scopes on every request, so narrowing the account narrows the token, but widening the account doesn't widen it. - `date_deactivated` is the token's status: `NULL` means active. Revoking keeps the row, like org auth tokens. There's no separate `is_active` boolean that could disagree with it. - `service_account` is a normal `CASCADE` FK. Accounts are soft-deleted (#129950), so it only fires when the org is deleted. - `organization_id` is copied from the account, so the outbox and the cell replica in the next PR don't need a join. - `created_by` is always a human user. Per the plan, token management is human-only. - `RelocationScope.Excluded`: a relocated token would need a new secret anyway. - `__repr__` leaves out the hash. Migration `service_accounts/0005` creates the table. It's new and empty, so the migration is safe to run during deploy. **Tests** - `ServiceAccountTokenTest`: `scope_list` rejects non-grantable scopes, and the repr omits the hash. - `tests/sentry/service_accounts`, `hybridcloud/tasks/test_backfill_outboxes.py`, the backup coverage, invariants and snapshots tests, and `db/test_silo_models.py` pass locally. - The migration applies, reverses and reapplies cleanly, and `makemigrations --check` finds no changes. prek and mypy pass. **Known failures from master** - `migration drift` fails on the `sentry_grouprelease.new_release_id` indexes. - 3 tests in `seer/endpoints/test_organization_seer_workflow_configs.py` fail. Both fail the same way on master today. <!-- junior-request-attribution:start --> via [automation `evt_96f99ce311a0097e57d5a80fb82b61c7`](https://junior-prod.sentry.dev/automations/evt_96f99ce311a0097e57d5a80fb82b61c7) · Run ID `dispatch_f7e53e47800bce9272ae0b23084ecc16`, **shaun.kaasten**. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:agent-dispatch%3Adispatch_f7e53e47800bce9272ae0b23084ecc16 --> -- [View Session](https://junior-prod.sentry.dev/conversations/agent-dispatch%3Adispatch_f7e53e47800bce9272ae0b23084ecc16) [[Sentry]](https://sentry.sentry.io/explore/conversations/agent-dispatch%3Adispatch_f7e53e47800bce9272ae0b23084ecc16/?project=4510944073809921) <!-- junior-session-footer:end --> --------- Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
This branch was successfully deployed
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.

PR 2 of the service account soft-delete plan. PR 1 (#129914) made names unique only among active accounts, so a deleted account's name can be reused.
Deleting a service account now keeps the row and sets
is_active=False, likeUser, instead of hard-deleting it. That keeps references such ascreated_by_service_account_idon dashboards pointing at a real account, and it makes the token work later in the plan simpler. The cell replica stays too, withis_active=False.ServiceAccount.deactivate()does the delete. It locks the active row, removes its project links, clearsall_projectsand turns the account off. Everything that reads an account through the API or RPC now treats a deleted account as missing (404 /None). The cell-side readers already reject inactive accounts.Deleted is now the only way to be inactive, so
isActiveis gone from the request and the response. In a response it was alwaystrue, and in a request onlytruewas useful. Like other unknown fields,isActivein a request is now ignored. Seer's generated client still lists the field, but no Seer code reads or sends it, so it can drop out the next time the client is regenerated. Audit entries no longer recordis_active.If two DELETE requests race, the second one gets a 404 and writes no audit entry.
Left as is:
via shaun.kaasten.
--
View Session [Sentry]