Scope session cookies, token, refresh and logout to named profiles (#157 step 2b-iii) #311

Merged
stephen merged 4 commits from fj-157-profile-cookies into main 2026-11-11 06:27:07 +00:00
Owner

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, refresh and logout use the chosen profile, or the host's default profile when there is one, and never touch legacy credentials. token needs --account: a bare auth token on a profiled host stays refused, because a stale Git credential helper runs exactly that. setup-git stays 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-cookie reads stdin only, even when FJ_SESSION is set. auth status shows 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 --account or 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 session cookie 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

  • Failed write, read-back or publication: tests/profile_maintenance.rs makes the credential store unusable during an import (the token file becomes a directory, which also fails as root in CI) and checks the previous cookie is kept and no new secret is stored.
  • Retry after a failed delete: the same test makes logout fail with the store unusable, checks the profile still works, then logs out.
  • Rotation: a cookie imported before a PAT refresh is still counted and replaceable afterwards, and replacing it leaves one secret.
  • Destination change: pointing the host at another URL drops the cookie from status until it is imported again; the Fjord profile check covers per-account cookies and logout next to another account.
  • Legacy fallback: after logging out the default, api fails with the missing-default message while the legacy token file is untouched.
  • Concurrency: import, clear and logout share a per-account lock and re-check the profile generation and destination inside the publication lock. PAT login and pasted-token refresh do not take that lock yet (CLS-1267).

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_token ignores 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.

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`, `refresh` and `logout` use the chosen profile, or the host's default profile when there is one, and never touch legacy credentials. `token` needs `--account`: a bare `auth token` on a profiled host stays refused, because a stale Git credential helper runs exactly that. `setup-git` stays 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-cookie` reads stdin only, even when `FJ_SESSION` is set. `auth status` shows 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 --account` or 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 session` cookie 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 - Failed write, read-back or publication: tests/profile_maintenance.rs makes the credential store unusable during an import (the token file becomes a directory, which also fails as root in CI) and checks the previous cookie is kept and no new secret is stored. - Retry after a failed delete: the same test makes logout fail with the store unusable, checks the profile still works, then logs out. - Rotation: a cookie imported before a PAT refresh is still counted and replaceable afterwards, and replacing it leaves one secret. - Destination change: pointing the host at another URL drops the cookie from status until it is imported again; the Fjord profile check covers per-account cookies and logout next to another account. - Legacy fallback: after logging out the default, `api` fails with the missing-default message while the legacy token file is untouched. - Concurrency: import, clear and logout share a per-account lock and re-check the profile generation and destination inside the publication lock. PAT login and pasted-token refresh do not take that lock yet (CLS-1267). 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_token` ignores 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.
Scope web sessions, token export, refresh and logout to named profiles (#157 step 2b-iii)
Some checks failed
ci / check (pull_request) Failing after 4m40s
ci / coverage (pull_request) Has been skipped
ci / live-e2e (pull_request) Has been skipped
ceddb8e0a0
Session cookies are staged, read back and published as a pointer bound to the profile generation and destination instance. Logout removes the profile and its secrets but keeps the default pointer, so a logged-out default never falls back to legacy credentials.
gerri approved these changes 2026-11-11 05:29:43 +00:00
Dismissed
gerri left a comment

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

  • Low: 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 ceddb8e0a0 at 2026-11-11T05:29:43Z by codex exec (read-only sandbox).

Automated Codex review (read-only) of head ceddb8e0a043a0171742f113f117ffb619bff32c. - **Low**: `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 ceddb8e0a043a0171742f113f117ffb619bff32c at 2026-11-11T05:29:43Z by codex exec (read-only sandbox).
Inject store failures without relying on file permissions (#157 step 2b-iii)
All checks were successful
ci / check (pull_request) Successful in 17m18s
ci / coverage (pull_request) Successful in 2m47s
ci / live-e2e (pull_request) Successful in 2m55s
7f1231ae36
CI runs as root, which ignores a read-only directory. The profile maintenance test now makes the token file a directory instead.
gerri requested changes 2026-11-11 05:35:52 +00:00
Dismissed
gerri left a comment

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 /user but omits the legacy refresh path’s probe_server and record_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 documented fj auth refresh leaves 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 7f1231ae36 at 2026-11-11T05:35:51Z by codex exec (read-only sandbox).

Automated Codex review (read-only) of head 7f1231ae36201f356942e45e036d9f117ff23ea8. - **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 `/user` but omits the legacy refresh path’s `probe_server` and `record_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 documented `fj auth refresh` leaves 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 7f1231ae36201f356942e45e036d9f117ff23ea8 at 2026-11-11T05:35:51Z by codex exec (read-only sandbox).
Refresh persisted server capabilities for PAT profiles
Some checks failed
ci / check (pull_request) Failing after 4m29s
ci / coverage (pull_request) Has been skipped
ci / live-e2e (pull_request) Has been skipped
b970b4fb09
gerri approved these changes 2026-11-11 05:57:49 +00:00
Dismissed
gerri left a comment

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

  • Low: src/config/profile_session.rs:148 and src/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 b970b4fb09 at 2026-11-11T05:57:48Z by codex exec (read-only sandbox).

Automated Codex review (read-only) of head b970b4fb09b1377831d3fa15a2f6b888d2377511. - **Low**: `src/config/profile_session.rs:148` and `src/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 b970b4fb09b1377831d3fa15a2f6b888d2377511 at 2026-11-11T05:57:48Z by codex exec (read-only sandbox).
Insert the capability keys in the refresh test fixture (#157 step 2b-iii)
All checks were successful
ci / check (pull_request) Successful in 12m39s
ci / coverage (pull_request) Successful in 2m39s
ci / live-e2e (pull_request) Successful in 2m59s
fd0b1d6a52
The fixture omits flavor and server_version, and indexing a missing TOML key panics, so the test failed during setup.
gerri approved these changes 2026-11-11 06:11:50 +00:00
gerri left a comment

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 fd0b1d6a52 at 2026-11-11T06:11:49Z by codex exec (read-only sandbox).

Automated Codex review (read-only) of head fd0b1d6a522a2b3a35f3ca447ba0f99deaeb8996. 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 fd0b1d6a522a2b3a35f3ca447ba0f99deaeb8996 at 2026-11-11T06:11:49Z by codex exec (read-only sandbox).
Sign in to join this conversation.
No description provided.