feat(auth): mark a deleted client's refresh tokens before the cascade

Deleting a client now leaves a delete marker for each of its Doorkeeper refresh tokens, so a client that comes back cannot accept a replayed token create (gitlab-org/gitlab#638332 (closed)).

Until now the client's ON DELETE CASCADE removed the token rows outright, markers included, and the marker rule of !1069 (merged) relied on the client staying deleted. An in-flight Layer 2 write or drain upsert that read the application before its destroy can recreate the client seconds after the delete, and a late token create for it was then accepted. ClientRepository.DeleteClient now runs in one transaction: it locks the client row, marks the client's tokens, then deletes the client. That is the token upsert's lock order, client first and rows second, so the two cannot deadlock. The client handler answers ABORTED on a write conflict, as the token handlers do. fosite's storage builds the repository on an ambient transaction, so the repository opens its own only when it holds a pool.

Start with DeleteClient in clients/repository.go and the client-delete test in the token package.

Part 11 of 14. 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 (merged)
  10. !992 (merged) feat(auth): add refresh-token BulkDelete (merged)
  11. !1110 (merged) feat(auth): mark a deleted client's refresh tokens before the cascade <- this MR
  12. !993 (merged) feat(auth): add refresh-token GetState
  13. !1118 (merged) test(auth): drive the refresh-token bulk RPCs through the server
  14. !994 (merged) feat(auth): count bulk RPC records by outcome

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

Edited by Shilpa Kundapur

Merge request reports

Loading
Loading