Scope session cookies, token, refresh and logout to named profiles (#157 step 2b-iii) #311
Loading…
Reference in a new issue
No description provided.
Delete branch "fj-157-profile-cookies"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Step 2b-iii of #157: session cookies, token export, refresh and logout now act on a named account profile. Work sessions stay deferred to 2b-iv, so #157 stays open.
fj auth session --account,refreshandlogoutuse the chosen profile, or the host's default profile when there is one, and never touch legacy credentials.tokenneeds--account: a bareauth tokenon a profiled host stays refused, because a stale Git credential helper runs exactly that.setup-gitstays refused. Without a usable default these commands fail with a message naming the profiled host.A web-session cookie is stored per host and account in two alternating slots. An import stages into the inactive slot, reads it back, then flips the published pointer, so a failed write, read-back or publication leaves the active cookie in place. The pointer records the destination (the PAT web URL, or the Fjord instance id and public URL); if that changes, the cookie is ignored until imported again. Credential rotation and re-login do not move it.
session --with-cookiereads stdin only, even whenFJ_SESSIONis set.auth statusshows how many cookies are active.Logout deletes the profile's secrets first, then removes the profile and its cookie pointer. If a delete fails, the profile stays selectable and logging out again finishes the job. The default pointer is kept, so a logged-out default fails with "default account profile is missing" instead of using the retained legacy credentials;
auth switch HOST --accountor a named login recovers. Refresh replaces a PAT only after the new token verifies, and renews a Fjord profile through its stored refresh token.Scoped cookies are stored and shown in status, but no command sends them yet. The existing
fj auth sessioncookie behaves the same way (Actions rerun uses the API token since #305), so there is no cookie-sending adapter to scope. That, one lock gap and the keychain delete behavior below are in CLS-1267.Failure paths
apifails with the missing-default message while the legacy token file is untouched.Refresh also re-probes the server flavor and version and publishes them, as the legacy refresh does. Review state: five local self-review rounds. The repeated Medium about cookie delivery is the known limit above. A later one notes that
auth::delete_tokenignores some keychain failures; that helper predates this PR, also serves legacy logout, and is in CLS-1267.Size is 609 gross added lines. 525 were within the 530 the lead allowed; the other 84 are the gerri fixer's capability refresh for PAT profiles (profile_maintenance.rs and tests/profile_refresh_capabilities.rs).
Offline tests only: profile_maintenance, fjord_profiles, auth_profiles, auth_profile_recovery, account_override and the bin unit tests. Live behaviour is unchecked.
Automated Codex review (read-only) of head
ceddb8e0a0.tests/profile_maintenance.rs:90,133. Invariant: tests must exercise the failure paths they claim (STANDARDS items 13 and 14). The read-only store tests cover staging-write failure and failure of the first logout deletion. They do not cover read-back failure, publication failure after successful staging, or partial logout where one secret is deleted before another deletion fails. Those edge case recovery paths remain unverified despite the PR body’s broader claim. Add targeted failure injection and assert the published cookie survives failed publication and logout retries finish after partial deletion.The cookie-delivery limitation and PAT locking gap remain accepted deferrals under CLS-1267; no new normal-operation impact was established.
BLOCKING: 0
Reviewed head
ceddb8e0a0at 2026-11-11T05:29:43Z by codex exec (read-only sandbox).Automated Codex review (read-only) of head
7f1231ae36.Medium
src/cli/profile_maintenance.rs:114: Invariant: refresh must update persisted server capabilities after an upgrade (standards 9 and 16). The new PAT path verifies/userbut omits the legacy refresh path’sprobe_serverandrecord_server. This affects both default-profile and explicit-account refresh, with or without a replacement token. On a supported PAT host upgraded from Forgejo 15 to 16, running the documentedfj auth refreshleaves the stored version at 15, so Actions commands continue treating newly available routes as unsupported. This belongs in this PR because it redirects existing refresh invocations to this reduced implementation without claiming that behavior change. Fix by sharing the legacy capability refresh logic and publishing the updated host metadata safely; test an upgrade with stale persisted metadata.Low
src/config/profile_session.rs:156: Accepted deferrals, edge case, CLS-1267. The declared cookie-delivery limitation, PAT login/refresh lock gap, and swallowed keychain deletion failures remain. They concern destination/identity fencing and reporting completion only after successful deletion. I found no new evidence warranting escalation here. Keep their fixes and regression coverage in the referenced follow-up.BLOCKING: 1
Reviewed head
7f1231ae36at 2026-11-11T05:35:51Z by codex exec (read-only sandbox).Automated Codex review (read-only) of head
b970b4fb09.src/config/profile_session.rs:148andsrc/cli/profile_maintenance.rs:126. Accepted follow-up, edge case (CLS-1267). Invariant: profile publication and secret deletion must preserve account ownership and retryability. PAT login and replacement refresh still bypass the account lock, allowing concurrent logout to race publication; the shared deletion helper can also report success while keychain credentials remain. These are documented deferrals, with no new evidence warranting blocking severity. Fix by sharing the account lock across credential publication and making keychain deletion failures observable and retryable. Cookie delivery also remains explicitly deferred in CLS-1267.No new blocking findings from the diff and surrounding code. Review was read-only; tests were not run.
BLOCKING: 0
Reviewed head
b970b4fb09at 2026-11-11T05:57:48Z by codex exec (read-only sandbox).Automated Codex review (read-only) of head
fd0b1d6a52.No new actionable findings found. The cookie-delivery limitation, PAT publication lock gap, and keychain-delete behavior remain accepted low-severity follow-ups in CLS-1267. No new evidence warrants making them blocking.
Read-only review completed against
~/fleet-week/STANDARDS.md; tests were not run.BLOCKING: 0
Reviewed head
fd0b1d6a52at 2026-11-11T06:11:49Z by codex exec (read-only sandbox).