fix: wipe user secrets when user is soft-deleted (#24985)

Extend the delete_deleted_user_resources() trigger so that secrets
belonging to a soft-deleted user are removed in the same transaction as
the existing api_keys and user_links cleanup.

user_secrets.user_id has ON DELETE CASCADE, but Coder soft-deletes users
by flipping users.deleted rather than removing the row, so the foreign key
cascade never fires and secrets would otherwise survive deletion.

Assisted by Coder Agents.
This commit is contained in:
Zach
2026-05-11 09:07:30 -06:00
committed by GitHub
parent 81e2be69e9
commit b221632615
9 changed files with 207 additions and 27 deletions
+4 -2
View File
@@ -25153,8 +25153,10 @@ type GetUserSecretsTelemetrySummaryRow struct {
// distribution is active non-system users. Specifically:
//
// - deleted = false: Coder soft-deletes by flipping users.deleted
// rather than removing rows, so secrets persist after delete but
// are unreachable.
// rather than removing rows. The delete_deleted_user_resources()
// trigger now removes their user_secrets, but soft-deleted users
// are still excluded here so they don't dilute the percentile
// distribution as zero-secret entries.
// - status = 'active': dormant users (no recent activity) and
// suspended users (explicitly disabled) cannot use secrets, so
// they shouldn't dilute the percentile distribution as