Repository navigation
fix(secrets): check dependents and delete in one atomic step on every route (#21039) - #21196
Conversation
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 13 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
Code review (code-reviewer pass) follow-up at 9edb765Verdict: APPROVE (no blocking defect; the findings below are fixes in this PR or follow-ups, none changes the correctness of the lock). Refs #21039, not Closes (see AC4/AC5). Locking is correct.
AC verdicts (as worded)
Recommendation for the coordinator: |
✅ SSOT Configuration Compliance: Passing🎉 No new hardcoded values of either class — Known backlog in |
Code review (code-reviewer pass) follow-up at 80bfd1bFixes are in fee4986 (head 80bfd1b is that commit plus main merged). Still
Local runs (real Postgres 16 on a scratch port, stopped afterwards): Postgres race file 4 passed; backend secrets/envelope/audit/20750 files plus the env-registry guard test 187 passed; vitest on 4 secrets spec files 27 passed; Notes. The unlocked read uses each route's own listing gate (main route: manage authority; envelope user: write; service: system-vault owner), and the delete's own write check still runs under the lock. The main route's |
|
Code review (code-reviewer pass) delta at 80bfd1b (vs. verdict at 9edb765)
CodeRabbit threads: 0 review threads; the only CodeRabbit comment is a rate-limit notice (nothing to answer). |
|
Verdict: APPROVE @ 232ed37
Checks, all read from the diff:
|
…nstant-time helper (#21039)
|
Fixed the red guard on the merge train: the dependents-digest confirmation now compares through the shared constant-time helper ( |
|
Verdict: APPROVE @ 2d4952f No findings.
|
Thinking Path
ON DELETE CASCADEwithout the confirmation the check exists to require.secret_dependencies.secret_idis a foreign key ontosecrets.id. So the store's own mechanism is enough, and no new lock framework or lease is needed.SELECT ... FOR UPDATEon the secret row conflicts with theFOR KEY SHARElock the foreign key takes on registration. Taking it first and listing dependents under it makes the two orders safe: registration first, the listing sees it and refuses (409); delete first, the registration fails the foreign key.What Changed
autobot-backend/api/secrets_guarded_delete.py:guarded_delete(session, secret_id, dependents=, delete=)= lock row, refuse 409 whiledependents()lists any,delete().refuse_dependentsmoved there (the one 409 shape).api/secrets_system_vault.py:delete_system_vault_secret(mainDELETE /api/secrets/{id}) calls it via_guarded_vault_delete; the old unlocked_refuse_unconfirmed_dependentsis gone.api/envelope_secrets_delete.py:audited_delete(userDELETE /api/v2/secrets/{id}and serviceDELETE /api/v2/secrets/system/{id}) calls it; audit intent and outcome unchanged, the refusal is still recorded asdenied/has_dependents.api/secrets_delete_race_21039_test.py(per route: a dependent registered as the lock is granted gives the same 409 and dependents list as the main route, the audit trail records the refusal, a plain delete still succeeds; lock-before-list-before-delete ordering; compiledFOR UPDATE; bulk route) andtests/migrations/test_secret_delete_race_21039.py(real Postgres, two sessions, both orders).secrets_system_vault_17731_test.py: the fixture session now has an awaitableexecute.Verification
secrets_delete_race_21039_test.py,tests/migrations/test_secret_delete_race_21039.pyandtests/migrations/test_secrets_api.py: 36 passed.*20640*,*20665*,*20557*,*18648*,*17731*,*20750*) plus the new unit file: 105 passed.test_main_route_refuses_a_dependent_registered_in_the_window.test_envelope_routes_refuse_a_dependent_registered_in_the_window[user].test_envelope_routes_refuse_a_dependent_registered_in_the_window[service].test_bulk_chat_delete_cannot_race_a_registrationshows a registration at the seam finds no vault row (not found) and nothing is recorded. The route has no vault secret to lock, so it is not a guarded-delete caller; whether that satisfies this criterion is a maintainer call.api/secrets_guarded_delete.py::guarded_delete, called by the main and both envelope routes.get_credential_store().revoke) is a different store and also has no dependents; untouched.Refs #21039. Closes only on the bulk criterion being accepted.
Single-issue rationale: the guarded delete changes the shared secrets delete helpers that every other secrets PR would also touch, so it cannot ride with another issue.
Model Used
Claude Sonnet 5.5 (claude-sonnet-5-5), via Claude Code.