Lock PAT profile replacement and fence pasted-token refresh (CLS-1267) #316

Merged
stephen merged 2 commits from stephen/cls-1267-replacement-lock into main 2026-11-11 17:04:17 +00:00
Owner

CLS-1267 item 2 (the lock and the refresh fence). Old-generation cleanup is a separate PR.

profile_session import, clear and logout take a per-account lock and check the profile generation. PAT login and pasted-token refresh published through profiles::store without it, so a replacement could interleave with a stale destructive operation.

  • profiles::store now takes the same lock (fjord_scope::lock, keyed by host and account) around staging and publishing.
  • auth refresh --token captured the profile it verified but published without checking it was unchanged. It now goes through store_fenced, which re-checks the generation before staging, inside the lock, and again inside the publish edit. A logout or replacement in between wins, and the refresh fails with "profile changed; retry" with nothing written. Plain auth login replacement keeps last-writer-wins.
  • A save that fails to read back, fails to publish or is refused deletes the credential it staged. Before, a failed publish left it behind.

Tests (config dir and keychain isolated in a child process): a stale profile_session::logout after a replacement is refused and leaves the new secret readable; a fenced store publishes when unchanged and, when stale, is refused with the token file unchanged; a replacement blocks while another holder has the account lock (confirmed to fail with the lock line removed).

Not here: a failed cleanup still loses the staged key's identity (deletion errors are ignored), which self-review flagged as Low. That belongs with the old-generation cleanup PR, where a retired-generation list needs a hosts.toml schema field; I am asking the lead before adding that. Touches only src/config/profiles.rs, src/cli/profile_maintenance.rs and tests, and fj-cl confirmed it is not editing those.

CLS-1267 item 2 (the lock and the refresh fence). Old-generation cleanup is a separate PR. `profile_session` import, clear and logout take a per-account lock and check the profile generation. PAT login and pasted-token refresh published through `profiles::store` without it, so a replacement could interleave with a stale destructive operation. - `profiles::store` now takes the same lock (`fjord_scope::lock`, keyed by host and account) around staging and publishing. - `auth refresh --token` captured the profile it verified but published without checking it was unchanged. It now goes through `store_fenced`, which re-checks the generation before staging, inside the lock, and again inside the publish edit. A logout or replacement in between wins, and the refresh fails with "profile changed; retry" with nothing written. Plain `auth login` replacement keeps last-writer-wins. - A save that fails to read back, fails to publish or is refused deletes the credential it staged. Before, a failed publish left it behind. Tests (config dir and keychain isolated in a child process): a stale `profile_session::logout` after a replacement is refused and leaves the new secret readable; a fenced store publishes when unchanged and, when stale, is refused with the token file unchanged; a replacement blocks while another holder has the account lock (confirmed to fail with the lock line removed). Not here: a failed cleanup still loses the staged key's identity (deletion errors are ignored), which self-review flagged as Low. That belongs with the old-generation cleanup PR, where a retired-generation list needs a hosts.toml schema field; I am asking the lead before adding that. Touches only `src/config/profiles.rs`, `src/cli/profile_maintenance.rs` and tests, and fj-cl confirmed it is not editing those.
profiles::store now takes the per-account lock that profile_session import,
clear and logout already hold, so a replacement and a stale destructive
operation cannot interleave. auth refresh --token publishes through
store_fenced, which re-checks inside the lock and the publish that the profile
is still the generation it verified. A failed or refused publication deletes
the credential it staged.
Delete a staged PAT whose read-back failed (CLS-1267)
All checks were successful
ci / check (pull_request) Successful in 22m57s
ci / live-e2e (pull_request) Successful in 3m18s
ci / coverage (pull_request) Successful in 4m33s
0508b4a78a
gerri approved these changes 2026-11-11 16:39:30 +00:00
gerri left a comment

Automated Codex review (read-only) of head 0508b4a78a.

  • Low src/config/profiles.rs:191, also :160. Edge case, accepted deferral: Unpublished credentials must retain a recoverable identity until deletion succeeds (standards 4 and 14). Both cleanup paths ignore deletion errors. If staging succeeds but read-back or publication fails, a subsequent keychain deletion failure leaves an orphan credential with no persisted generation reference. Track retired generations durably and retry deletion in the cleanup follow-up identified in the PR body.

No high or medium findings.

BLOCKING: 0

Reviewed head 0508b4a78a at 2026-11-11T16:39:29Z by codex exec (read-only sandbox).

Automated Codex review (read-only) of head 0508b4a78a8031184f18b950448b5d5429c9a570. - **Low** src/config/profiles.rs:191, also :160. **Edge case, accepted deferral:** Unpublished credentials must retain a recoverable identity until deletion succeeds (standards 4 and 14). Both cleanup paths ignore deletion errors. If staging succeeds but read-back or publication fails, a subsequent keychain deletion failure leaves an orphan credential with no persisted generation reference. Track retired generations durably and retry deletion in the cleanup follow-up identified in the PR body. No high or medium findings. BLOCKING: 0 --- Reviewed head 0508b4a78a8031184f18b950448b5d5429c9a570 at 2026-11-11T16:39:29Z by codex exec (read-only sandbox).
stephen deleted branch stephen/cls-1267-replacement-lock 2026-11-11 17:04:17 +00:00
Sign in to join this conversation.
No description provided.