Report keychain delete failures instead of succeeding (CLS-1267) #314

Merged
stephen merged 6 commits from stephen/cls-1267-keychain-delete into main 2026-11-11 16:23:35 +00:00
Owner

CLS-1267 item 3. auth::delete_token ignored every keychain delete error and succeeded after removing the file entry, so logout and session clear could report success while a locked keychain still held the secret.

Behaviour

  • NoStorageAccess (keychain locked or access denied): the file entry is removed, then the delete fails, so the caller keeps the profile or session selectable and running it again finishes the job.
  • PlatformFailure on macOS and Windows, where a keychain always exists (keyring maps a locked keychain from a headless session or a denied prompt to it): same, fails.
  • PlatformFailure on Linux: warns once per run and succeeds, so logout still works where keyutils is blocked, e.g. in a container with the default seccomp profile that falls back to the file store.
  • Other keyring errors still propagate. Profile keys stay redacted in the error.
  • Legacy fj auth logout now deletes the secrets first (each one attempted) and removes the host from hosts.toml only if all succeeded (Hosts::remove_after_cleanup), so a failed delete leaves the host configured for a retry. Before, it removed and saved the host first, which would have made the retry impossible.

Known limit (self-review round 3, left as is)
On Linux a PlatformFailure can also be an EPERM from a seccomp-restricted environment that does hold a keyutils credential from elsewhere. fj cannot tell that from "no keyring" with the error the backend gives, so it warns and succeeds there. The warning is printed once so it is not silent.

User-visible: logout and session clearing can now fail with a keychain error where they used to say success. That is the point of the item; decided as option (a) with the lead.

Tests: mock keychain for each error class and both platform settings, a profile-key redaction check, and the host-retained-on-failure behaviour. clippy on this host's newer toolchain stops at an existing lint in src/cli/pr_line_comment.rs, untouched here. May overlap src/cli/auth.rs with 2b-iv; the edit is confined to logout.

Not in this PR: deleting the previous generation's secrets when a profile is replaced (profiles::store, fjord_profiles::login) does not exist today, so replacement leaves the old credential behind regardless of keychain errors. That needs its own change with a persisted cleanup identity; it belongs with the held replacement-lock PR (CLS-1267 item 2) and I will note it on CLS-1267.

CLS-1267 item 3. `auth::delete_token` ignored every keychain delete error and succeeded after removing the file entry, so logout and session clear could report success while a locked keychain still held the secret. **Behaviour** - `NoStorageAccess` (keychain locked or access denied): the file entry is removed, then the delete fails, so the caller keeps the profile or session selectable and running it again finishes the job. - `PlatformFailure` on macOS and Windows, where a keychain always exists (keyring maps a locked keychain from a headless session or a denied prompt to it): same, fails. - `PlatformFailure` on Linux: warns once per run and succeeds, so logout still works where keyutils is blocked, e.g. in a container with the default seccomp profile that falls back to the file store. - Other keyring errors still propagate. Profile keys stay redacted in the error. - Legacy `fj auth logout` now deletes the secrets first (each one attempted) and removes the host from `hosts.toml` only if all succeeded (`Hosts::remove_after_cleanup`), so a failed delete leaves the host configured for a retry. Before, it removed and saved the host first, which would have made the retry impossible. **Known limit (self-review round 3, left as is)** On Linux a `PlatformFailure` can also be an `EPERM` from a seccomp-restricted environment that does hold a keyutils credential from elsewhere. fj cannot tell that from "no keyring" with the error the backend gives, so it warns and succeeds there. The warning is printed once so it is not silent. User-visible: logout and session clearing can now fail with a keychain error where they used to say success. That is the point of the item; decided as option (a) with the lead. Tests: mock keychain for each error class and both platform settings, a profile-key redaction check, and the host-retained-on-failure behaviour. clippy on this host's newer toolchain stops at an existing lint in `src/cli/pr_line_comment.rs`, untouched here. May overlap `src/cli/auth.rs` with 2b-iv; the edit is confined to `logout`. Not in this PR: deleting the previous generation's secrets when a profile is replaced (`profiles::store`, `fjord_profiles::login`) does not exist today, so replacement leaves the old credential behind regardless of keychain errors. That needs its own change with a persisted cleanup identity; it belongs with the held replacement-lock PR (CLS-1267 item 2) and I will note it on CLS-1267.
auth::delete_token ignored every keychain error and succeeded after removing
the file entry, so logout, session clear and replacement cleanup could report
success while a locked keychain still held the secret. A keychain that refuses
access (NoStorageAccess) now fails the delete after the file entry is removed,
so the caller keeps the profile selectable and a retry finishes. PlatformFailure,
which a machine with no keychain service also reports, only warns once so
headless logout keeps working.
A locked keychain now fails a delete, so legacy logout must not drop the host
entry first or a retry has nothing to clean up. Secrets are deleted first, each
attempted, and the host is removed only if all succeed.
Treat a platform failure as real where a keychain always exists (CLS-1267)
Some checks failed
ci / check (pull_request) Has been cancelled
ci / coverage (pull_request) Has been cancelled
ci / live-e2e (pull_request) Has been cancelled
79107b3998
gerri requested changes 2026-11-11 15:33:56 +00:00
Dismissed
gerri left a comment

Automated Codex review (read-only) of head 79107b3998.

  • Medium CHANGELOG.md:11. Invariant: replacement must retain cleanup identity until old secrets are deleted, and release notes must match behavior (standards 11 and 14). The claimed profile-replacement fix is absent. profiles::store and fjord_profiles::login publish a new generation without calling delete_token for the previous generation. On a normal PAT refresh with a pasted token or repeated Fjord login, the old credential remains in storage while replacement reports success. Subsequent logout knows only the new generation, so it cannot remove that old secret. This belongs here because the PR explicitly claims replacement cleanup now reports failures. Implement cleanup with a persisted retry identity for both profile types, or remove replacement from the claimed scope and track that missing behavior separately.

  • Low src/auth/mod.rs:369. Edge case, accepted deferral: the PR body's “Known limit” still applies: Linux PlatformFailure can represent denied access to an existing credential. The warning-and-success branch can therefore leave a secret behind. No new evidence warrants making this blocking. Retain the documented follow-up to distinguish backend absence from access failure.

BLOCKING: 1

Reviewed head 79107b3998 at 2026-11-11T15:33:55Z by codex exec (read-only sandbox).

Automated Codex review (read-only) of head 79107b3998cc8bdbc105bdde214d7afafc75e894. - **Medium** CHANGELOG.md:11. Invariant: replacement must retain cleanup identity until old secrets are deleted, and release notes must match behavior (standards 11 and 14). The claimed profile-replacement fix is absent. `profiles::store` and `fjord_profiles::login` publish a new generation without calling `delete_token` for the previous generation. On a normal PAT refresh with a pasted token or repeated Fjord login, the old credential remains in storage while replacement reports success. Subsequent logout knows only the new generation, so it cannot remove that old secret. This belongs here because the PR explicitly claims replacement cleanup now reports failures. Implement cleanup with a persisted retry identity for both profile types, or remove replacement from the claimed scope and track that missing behavior separately. - **Low** src/auth/mod.rs:369. **Edge case, accepted deferral:** the PR body's “Known limit” still applies: Linux `PlatformFailure` can represent denied access to an existing credential. The warning-and-success branch can therefore leave a secret behind. No new evidence warrants making this blocking. Retain the documented follow-up to distinguish backend absence from access failure. BLOCKING: 1 --- Reviewed head 79107b3998cc8bdbc105bdde214d7afafc75e894 at 2026-11-11T15:33:55Z by codex exec (read-only sandbox).
Drop the unimplemented replacement claim from the changelog (CLS-1267)
All checks were successful
ci / check (pull_request) Successful in 17m37s
ci / live-e2e (pull_request) Successful in 3m6s
ci / coverage (pull_request) Successful in 3m7s
be847b1b31
gerri approved these changes 2026-11-11 15:36:44 +00:00
Dismissed
gerri left a comment

Automated Codex review (read-only) of head be847b1b31.

No new correctness, security, or failure-path problems found.

  • Low: src/auth/mod.rs:376, edge case, accepted deferral. Invariant: successful deletion confirms the secret is gone. Linux PlatformFailure still permits success when a restricted environment cannot delete an existing keyutils credential. This is the PR body's documented “Known limit,” unchanged by this review. A follow-up needs backend error discrimination or persisted cleanup identity to support reliable retries.

BLOCKING: 0

Reviewed head be847b1b31 at 2026-11-11T15:36:43Z by codex exec (read-only sandbox).

Automated Codex review (read-only) of head be847b1b313255099a52d5e7f4749506c34799cf. No new correctness, security, or failure-path problems found. - **Low**: `src/auth/mod.rs:376`, edge case, accepted deferral. Invariant: successful deletion confirms the secret is gone. Linux `PlatformFailure` still permits success when a restricted environment cannot delete an existing keyutils credential. This is the PR body's documented “Known limit,” unchanged by this review. A follow-up needs backend error discrimination or persisted cleanup identity to support reliable retries. BLOCKING: 0 --- Reviewed head be847b1b313255099a52d5e7f4749506c34799cf at 2026-11-11T15:36:43Z by codex exec (read-only sandbox).
Tidy the changelog after the merge
All checks were successful
ci / check (pull_request) Successful in 19m10s
ci / live-e2e (pull_request) Successful in 3m11s
ci / coverage (pull_request) Successful in 4m59s
a48954410d
gerri approved these changes 2026-11-11 15:59:37 +00:00
gerri left a comment

Automated Codex review (read-only) of head a48954410d.

  • Low src/auth/mod.rs:370, edge case, accepted deferral: The invariant “successful logout confirms secret removal” remains qualified by the PR body’s Known limit. Linux PlatformFailure can represent blocked access to an existing keyutils credential. In that case, logout warns and succeeds while the credential remains. Follow-up: distinguish backend absence from access failure where possible, or retain cleanup identity for a later retry.

No additional correctness, security, or failure-path problems found in the diff or its callers.

BLOCKING: 0

Reviewed head a48954410d at 2026-11-11T15:59:36Z by codex exec (read-only sandbox).

Automated Codex review (read-only) of head a48954410dbb1011d1c3eb019ac7b4fb844ed0d4. - **Low** `src/auth/mod.rs:370`, edge case, accepted deferral: The invariant “successful logout confirms secret removal” remains qualified by the PR body’s **Known limit**. Linux `PlatformFailure` can represent blocked access to an existing keyutils credential. In that case, logout warns and succeeds while the credential remains. Follow-up: distinguish backend absence from access failure where possible, or retain cleanup identity for a later retry. No additional correctness, security, or failure-path problems found in the diff or its callers. BLOCKING: 0 --- Reviewed head a48954410dbb1011d1c3eb019ac7b4fb844ed0d4 at 2026-11-11T15:59:36Z by codex exec (read-only sandbox).
Sign in to join this conversation.
No description provided.