Skip to content

auth: pending SSO sessions and TOTP step-up (§7.3) - #17

Merged
Yoshiofthewire merged 9 commits into
mainfrom
kyguard/stepup
Nov 25, 2026
Merged

Yoshiofthewire merged 9 commits into
mainfrom
kyguard/stepup

Conversation

@Yoshiofthewire

@Yoshiofthewire Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

In one line: Every SSO sign-in now stops at a five-minute pending session until the user enters a TOTP code. The code exchanges it for a new 12-hour session.

What changed

  • The SSO callback issues a pending session bound to the login (issuer, sid, original iat, the IdP's MFA assertion). It authenticates only GET /api/auth/me, logout and /api/auth/stepup/*. Everything else answers 403 stepup_required, and /api/settings shows it only the public payload.
  • POST /api/auth/stepup/totp deletes the pending session and issues a new active one (new token, 12 h, stepup_at set, same binding) in one transaction. It then re-checks both logout fences after commit.
  • First factor: enroll / enroll/confirm work only if the ID token asserted MFA. Otherwise the answer is 403 and an auth.enrollment_blocked audit event.
  • Codes share the break-glass limits: 5 failures end the pending session, and 10 per user per 15 minutes refuse even a correct code.
  • The web shell shows a step-up screen for pending sessions.
  • Two test commits replace the fixed 000000 wrong code with one that matches no nearby step (same flake as the auth: break-glass accounts with mandatory TOTP #3 Guide finding).

Review this

  • internal/api/stepup_handlers.go: the exchange. A pending token must never become active, and the fence re-check must run after commit.
  • internal/store/sqlstore.go ExchangePendingSession: the transaction that holds the user row while deleting the pending session and inserting the active one.
  • Safe to skip: web/dist (generated; CI checks it is current).

Checked: go test -race and the FIPS profile, full suite, SQLite and PostgreSQL 17 at this head (details below). Every security property has a mutation that fails its test (table below).
Not checked: e2e/compose_test.go locally: Major's Docker address pool is exhausted, so it runs in CI only.
You need to: review. Held unmerged by rule.

§13 Phase 0 checklist: mfa_factors, pending sessions, enrollment rule, TOTP exchange, attempt limits, per-action step-up (§7.3) (per-action windows are in the next PR). Acceptance 4, 5, 6, 7 (TOTP half; the CLI half comes with §7.6).

Detail

Mutation table (each mutation makes the named test fail)

# Property Mutation Failing test
S1 A pending session reaches only me/logout/stepup drop the pending restriction TestSSOSignInIsPendingUntilStepUp
S2 The pending token dies at the exchange skip deleting the pending row TestSSOSignInIsPendingUntilStepUp
S3 Enrollment needs IdP MFA skip the MFA check on enroll TestEnrollmentNeedsIdPMFA
S4 The 5th failure ends the pending session skip the delete at the session limit TestStepUpCodeLimits
S5 The active session lasts 12 h other TTL TestSSOSignInIsPendingUntilStepUp
S6 The original iat is kept use the exchange time TestSubjectLogoutUsesTheOriginalIat
S7 Fences are re-checked after commit drop the re-check TestLogoutRacingStepUpLeavesNoActiveSession (PostgreSQL), TestLogoutBeforeStepUpEndsTheSignIn

hawthorn ran S1–S7 at the pre-rebase head b31d536. Since then this branch has moved only by rebasing onto the #3/#7 fixes and by the wrong-code test helper; the code under test is unchanged.

Checks at f46b35c

  • gofmt, go vet, go build, go test -race -count=1 -p 2 ./... and the same under GODEBUG=fips140=on: SQLite pass (Major, kslot; every K host was busy); PostgreSQL 17 pass (Major, own postgres:17-alpine container). Exit 0 on both.

Stack

#1 → #3 → #7 → #17 (this) → #18 → #19.

Review fixes (hawthorn fix-auth)

  • Guide, flaky test (915bf7c): the replay check uses the code enrollment actually spent (enrollCode), not one computed again, which could land on the next step.
Property Mutation Test Result
a replayed enrollment code fails compute the code again one step later (the old behaviour across a boundary) TestStepUpCodeLimits fails (200)

Checked at 915bf7c: race and FIPS suites on SQLite (Major) and PostgreSQL 17 (Major, own container), exit 0.

Merge of #7's fix (hawthorn fix-auth-3)

# Property Mutation Failing test
S8 A pending session reaches the step-up routes drop /api/auth/stepup/ from pendingAllowed TestOIDCSignInStepsUpToActive (enroll: 401)
S9 The OIDC callback issues only a pending session IssuePendingSession stores stage=active TestOIDCSignInIsPendingUntilStepUp, TestOIDCSignInStepsUpToActive

Checks at this head: gofmt, vet, go test -race -count=1 -p 2 ./... and the same under GODEBUG=fips140=on: SQLite pass, 14/14 packages (Major, kslot; every K host was busy); PostgreSQL 17 pass (Major, own postgres:17-alpine container), exit 0. make notes-check passes.

Round 4 (hawthorn): main merged, Guide "Recovery Deadlock" fixed

Property Mutation Test Result
A failed load after an accepted code is retried, not re-exchanged restore the old StepUp.tsx (calls onDone() and keeps the code form) StepUp.test.tsx "retries only the session load after an accepted code" fails (Unable to find role="alert")

Checks: web unit 44/44 and build (Node 26.13.1) at 58ddf66. Go race + FIPS ran at the bottom (#7 @ 0975542) and the top (#28) of the stack; see #28.

Round 4b (hawthorn): Guide "Missing notification"

  • ca43ea9: the blocked screen (no factor, no IdP MFA) now posts once to POST /api/auth/stepup/enroll. That 403 is the only path that records auth.enrollment_blocked (spec §7.3 rule 3). The screen says "An administrator has been notified" only after the server answers 403. On any other answer or a network failure it says to sign in again or contact an administrator. web/dist is rebuilt with Node 26.13.1.
  • sso: identity by (issuer, subject); fresh, per-app sign-in #7 has merged into main, so this PR is now the bottom of the auth stack.
Property Mutation Test Result
The notification claim follows the recorded event the old StepUp.tsx (claims it without calling the route) "reports a blocked enrollment to the server before saying admins were notified", "does not claim a notification the server did not record" both fail

Checks at ca43ea9: web unit 45/45 and build (Node 26.13.1). Go race + FIPS at ca43ea9: SQLite pass (k82, exit 0), PostgreSQL 17 pass (Major, own postgres:17-alpine container, exit 0).

🤖 Generated with Claude Code

@Yoshiofthewire

Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member Author

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪

🧪 PR contains tests

⚡ No major issues detected


⚠️ Review coverage: The following files were not included in this review because of the token budget:

  • web/dist/assets/index-CUm1t9UT.js

Advisory only: this comment never gates the pull request.
gpt-6.1-sol using pr-agent on behalf of Yoshi

@Yoshiofthewire

Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member Author

Security review - cleared

Detail withheld: this repository is public, and posting an unfixed finding here would be public disclosure. The full report was posted to the hand-off board at https://myslop.urlxl.us/f/pr-reviewer-busnes-app-kyguard-server-17, where it is readable by the operator and expires seven days after the last post.

Review input was truncated; omitted changes were not reviewed.


claude-opus-5-5 using security-audit on behalf of Yoshi

@Yoshiofthewire

Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member Author

Autonomous review - 1/1 personas cleared

  • security: cleared

Merging remains a human decision; this bot never approves.


claude-opus-5-5 using security-audit on behalf of Yoshi

Yoshiofthewire and others added 4 commits November 25, 2026 07:51
Every SSO callback now issues a five-minute pending session bound to
the login (issuer, sid, original iat, IdP MFA assertion) that
authenticates only /api/auth/me, logout and /api/auth/stepup/*; all
else is 403 stepup_required and settings stay public (spec §7.3).

POST /api/auth/stepup/totp exchanges it, in one transaction holding
the user row, for a new 12-hour active session with a new token and
the same binding, then re-checks the logout fences after commit. A
user without a factor may enroll one (enroll, enroll/confirm) only if
the ID token asserted MFA; otherwise the block is audited. Codes share
the break-glass limits: five per pending session, ten per user per 15
minutes. The web shell shows a step-up screen.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Computing it again could land on the next TOTP step and turn the replay
into a fresh code (PR Reviewer Guide).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Yoshiofthewire

Copy link
Copy Markdown
Member Author

Guide (flaky replay test) fixed in 915bf7c: enrollCode returns the code enrollment actually spent, and TestStepUpCodeLimits replays that one. Recomputing the code one step later (the old behaviour across a boundary) makes the test fail with 200.

Yoshiofthewire added a commit that referenced this pull request Nov 25, 2026
An SSO callback now issues only a pending session that lasts five
minutes. The session middleware refuses a pending session everywhere
except who-am-I and logout, so SSO users can do nothing else until the
TOTP step-up exchange (#17) lands.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Yoshiofthewire and others added 4 commits November 25, 2026 09:27
…d/stepup

#7 (9220dd7) made the SSO callback issue a pending session that only
who-am-I and logout accept. Conflicts resolved in favour of stepup:
IssuePendingSession, ExchangePending and pendingAllowed with
/api/auth/stepup/* stay. #7's IssueSSOSession, which stepup no longer
calls and which would issue an active SSO session here, is dropped.

TestOIDCSignInIsPendingUntilStepUp now expects stepup's 403
stepup_required instead of #7's 401. New TestOIDCSignInStepsUpToActive
signs in through the generic OIDC routes, enrolls on the pending session,
then steps up again with a code, both through to an active session
(the #7 Guide note's integration test).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
When the code exchange succeeds but reading /api/auth/me fails, StepUp no
longer leaves the code form up (a second code gets "already stepped up"):
it says the user is signed in and offers Try again, which only reloads.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Yoshiofthewire added a commit that referenced this pull request Nov 25, 2026
Brings #17's step-up retry and #18/#25 fixes up. web/dist rebuilt from
the merged sources with Node 26.13.1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Yoshiofthewire
Yoshiofthewire changed the base branch from kyguard/sso-identity to main November 25, 2026 20:53
The blocked screen claimed "An administrator has been notified" without
calling the enroll route, the only path that records
auth.enrollment_blocked (spec §7.3 rule 3). It now posts to it once and
shows the claim only on its 403; otherwise it asks the user to sign in
again or contact an administrator. web/dist rebuilt (Node 26.13.1).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Yoshiofthewire added a commit that referenced this pull request Nov 25, 2026
Brings #17's blocked-enrollment notification fix up. web/dist rebuilt
from the merged sources with Node 26.13.1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Yoshiofthewire
Yoshiofthewire merged commit 47228d3 into main Nov 25, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant