feat(auth): refuse upserts for deleted refresh-token ids

An upsert for a refresh-token id that was deleted is now refused, so a replayed create can no longer bring a deleted token back. Rails sends token events through three paths that keep no order, the immediate write, the drain and the sweep (gitlab-org/gitlab#632073 (closed)), and the coming BulkDelete would otherwise leave no trace. The design is design 7 of spec 001 on !959 (closed).

A deleted token keeps its row as a marker: deleted_at is set and the token columns are NULL. The pair (owning_cell_id, source_id) becomes the primary key and its old unique index goes, token_hash becomes a nullable unique column, and a CHECK requires the token columns unless deleted_at is set. The upsert's existing row lock finds a marker by its pair, and fold refuses it with the new REASON_DELETED; the single Upsert returns INVALID_ARGUMENT. The row lock and the key serialise a delete and an upsert for one pair, so there is no explicit lock and no second table. Nothing writes markers yet. BulkDelete (!992 (merged)) will, in one statement, so no release ships a delete without the refusal.

Rejected: a tombstone table guarded by an advisory lock per pair, because 20 concurrent full batches exhausted the Postgres lock table, hash collisions can deadlock unrelated batches, and the locks hid the row-lock test; a tombstone table without locks, because a delete racing a replay can still bring a token back; soft delete with revoked_at, because a delete before the first create has no row to mark.

An Org Mover copy, the same signature under a new pair, is still refused while the old pair is live; once Rails deletes the old pair, a later event for the new pair lands the copy. The table holds no production rows, so the key moves in place. Open: GetState (!993 (merged)) must report a marker as no token, and redemption must treat deleted_at set as deleted. Markers are not purged until Rails names its retry and retention window; a cell restored from backup could then reuse a marked id.

Start with the migration, fold in decide.go and the marker integration test.

Part 9 of 12. The full change is in !959 (closed), the integration MR, kept open for the big picture.

  1. !988 (merged) feat(proto): add BulkUpsertClients and UpsertResult (merged)
  2. !989 (merged) feat(auth): add BulkUpsertClients with per-record results (merged)
  3. !990 (merged) refactor(auth): move the bulk record helpers to internal/batch (merged)
  4. !1010 (merged) fix(auth): decide refresh-token upserts in Go (merged)
  5. !1029 (merged) fix(auth): gate stored rows in one upsert helper and wait on the lock (merged)
  6. !1030 (merged) feat(auth): add a batch path to the refresh-token repository (merged)
  7. !1031 (merged) feat(proto): add BulkUpsert to the refresh-token service (merged)
  8. !991 (merged) feat(auth): add refresh-token BulkUpsert with per-record results (merged)
  9. !1069 (merged) feat(auth): refuse upserts for deleted refresh-token ids <- this MR
  10. !992 (merged) feat(auth): add refresh-token BulkDelete
  11. !993 (merged) feat(auth): add refresh-token GetState
  12. !994 (merged) feat(auth): count bulk RPC records by outcome

Previous: !991 (merged) · Next: !992 (merged)

Edited by Shilpa Kundapur

Merge request reports

Loading
Loading