Skip to content

sso: identity by (issuer, subject); fresh, per-app sign-in - #7

Merged
Yoshiofthewire merged 7 commits into
mainfrom
kyguard/sso-identity
Nov 25, 2026
Merged

Yoshiofthewire merged 7 commits into
mainfrom
kyguard/sso-identity

Conversation

@Yoshiofthewire

@Yoshiofthewire Yoshiofthewire commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

In one line: An account is now identified by the verified token's (issuer, subject), every sign-in demands a fresh IdP login, and admin comes only from the per-app roles claim.

What changed

  • users.sso_issuer with a unique (sso_issuer, sso_subject) index; sessions record their issuer; both back-channel logout fences (sso_logouts, sso_subject_logouts) are keyed by issuer (migration 13). Two issuers with the same subject are two users.
  • Generic OIDC routes /api/sso/oidc/login and /callback (shared handler with KySignOn).
  • Authorization requests send max_age=0 and the profile's MFA acr set (urn:kysignon:acr:mfa; KY_OIDC_MFA_ACRS for OIDC); the callback parses auth_time, amr, acr and refuses auth_time missing, >120 s old or in the future. The MFA assertion (amr has mfa or acr in the set) is recorded for the next PR.
  • Role = admin only if per-app roles contains admin, recomputed and written at every sign-in; the IdP-wide role fallback is gone.
  • SCIM never grants admin; KY_SCIM_ALLOW_ADMIN removed; SCIM rows take KY_SCIM_ISSUER (default KY_KYSIGNON_ISSUER) and adoption matches on issuer and subject.

Review this

Checked: go test -race ./... SQLite (K81) and PostgreSQL 17 (K83) exit 0 at this head's parent and again after rebase on #3's fixes; smoke test passes. Mutations (each fails its test): role fallback restored → TestSignInRoleComesOnlyFromPerAppRoles; freshness check skipped → TestStaleAuthTimeIsRefused; lookup ignoring issuer, and sid logout ignoring issuer → TestIssuerIsPartOfTheIdentity; SCIM grant allowed → TestSCIMNeverGrantsAdmin; otp counted as MFA → TestMFAAssertionRule; max_age dropped → TestAuthorizationRequestAsksForFreshMFA.
Not checked: the Compose replica e2e locally (Major's Docker address pool is exhausted); CI runs it.

Decided for you

  • SCIM "refuses admin unconditionally" is read as "no setting can let SCIM grant admin"; SCIM can still deactivate or demote an existing admin, so directory deprovisioning keeps working (docs/DECISIONS.md 9).
  • KY_SCIM_ISSUER defaults to the KySignOn issuer (DECISIONS 10); a future auth_time is refused (11); the fence tables are replaced, not converted (12).
  • SSO sign-in fails closed until local step-up: on this PR alone an SSO sign-in gets only a 5-minute pending session, which can call who-am-I and logout and nothing else. SSO users cannot get further until auth: pending SSO sessions and TOTP step-up (§7.3) #17 (the TOTP exchange) lands; only break-glass accounts can work on sso: identity by (issuer, subject); fresh, per-app sign-in #7 by itself.

You need to: review; hold unmerged. Stacked on #3.

§13 Phase 0 items: from "Identity: …" — users.sso_issuer; issuer-aware AdoptSCIMUser; generic OIDC routes; max_age=0, auth_time, amr, acr; MFA assertion rule; per-app admin without fallback; SCIM admin refusal; logout fences by issuer (the check-after-insert exchange path and its concurrent test come with step-up). Acceptance: 7 (auth_time), 8, 10.

Review fixes (hawthorn fix-auth)

  • Guide, restart failure (c2eb117): SCIM refuses an externalId while no issuer is set, and a row created before then takes the issuer with its first subject.
  • Guide, migration failure (c2eb117): the unique (sso_issuer, sso_subject) index skips unissued rows, so migration 13 applies over legacy cross-provider collisions. The start check names the repair (DECISIONS 12).
  • Security P2 (8f67570): migration 13 deletes SSO sessions from before it, which no issuer-keyed logout could end. Local sessions stay.
Property Mutation Test Result
no SCIM subject without an issuer (create) drop the create check TestSCIMNeverStoresASubjectWithoutAnIssuer fails
same (PUT/PATCH) drop the update check same fails
an issuer-less row takes the issuer the store never writes sso_issuer same fails
migration 13 survives legacy collisions the old index predicate TestMigration13KeepsLegacySubjectCollisions fails
migration 13 drops unfenceable sessions drop the DELETE TestMigration13DropsSessionsNoLogoutCouldEnd fails

Checked at 8f67570: race and FIPS suites on SQLite (k80) and PostgreSQL 17 (k82), exit 0.

Review fix (hawthorn fix-pr7): SSO sign-in fails closed until local step-up

Property Mutation Test Result
SSO sign-in yields a pending session the callback's session issued active (the old behaviour) TestOIDCSignInIsPendingUntilStepUp fails
a pending session authorizes nothing the middleware ignores stage same fails (admin users, backup status, signed-in settings all served)
a pending session lasts 5 minutes default session TTL same fails
only who-am-I and logout any GET allowed same fails

No existing test needed changing; the other SSO tests use only who-am-I and logout.

Checked at 9220dd7: gofmt, vet, build, race and FIPS suites on SQLite (Major, kjob fallback; every K host was busy, exit 0) and PostgreSQL 17 (k83, exit 0). Web code is unchanged.

Round 4 (hawthorn): main merged

🤖 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: 5 🔵🔵🔵🔵🔵

🧪 PR contains tests

⚡ Recommended focus areas for review

Blocked Step-up

Every SSO login now receives a pending session, but pendingAllowed permits only identity lookup and logout. Requests to /api/auth/stepup/* therefore fail authentication with ErrStepUpRequired, preventing users from completing the TOTP step-up needed to access the application. Allow the appropriate enrollment and verification routes for pending sessions and add an end-to-end test that completes SSO login, performs step-up, and accesses an authenticated endpoint.


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-7, where it is readable by the operator and expires seven days after the last post.


gpt-6.1-sol 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.


gpt-6.1-sol using security-audit on behalf of Yoshi

@Yoshiofthewire

Copy link
Copy Markdown
Member Author

Fixed in e6e0cdd (rebased on #3's fbfe25c):

  • Security P2, adoption conflict. After a lost LinkSSOIdentity race, AdoptSCIMUser accepts the reloaded row only if it still has the token's issuer and subject and the signing-in provider; otherwise ErrConflict and the callback answers 409 with no session. TestAdoptionRevalidatesTheIdentity changes the subject between lookup and adoption; weakening the check makes it fail.
  • Guide, legacy identities. Startup refuses a database holding SSO subjects with no issuer (rows from before migration 13), with instructions to set users.sso_issuer (TestStartRefusesUnissuedIdentities; mutation-checked). No KyGuard install predates the migration; recorded in docs/DECISIONS.md.

Checked: go test -race ./... on PostgreSQL 17 (own container on Major) and SQLite (K80), no failures.

🤖 Generated with Claude Code

Yoshiofthewire and others added 3 commits November 25, 2026 07:11
Account identity is now the verified token's (iss, sub) (spec §7.2):
users.sso_issuer with a unique index, sessions record their issuer,
and both back-channel logout fences are keyed by issuer, so the same
sid or subject from another issuer is untouched. SCIM accounts take
KY_SCIM_ISSUER (default KY_KYSIGNON_ISSUER) and adoption matches on
both halves.

Add the generic OIDC login and callback routes. Both providers send
max_age=0 and their MFA acr set as acr_values, parse auth_time, amr
and acr, refuse an auth_time missing or older than 120 seconds, and
record whether the token asserted MFA for the step-up PR to use.

The role now comes only from the per-app roles claim, recomputed at
every sign-in; the IdP-wide role fallback is gone. SCIM never grants
admin and KY_SCIM_ALLOW_ADMIN is removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review of cd927d9: when adoption lost a race, the reload by row ID
accepted the row even if a concurrent SCIM externalId correction had
changed its subject, so a session could be issued for an account that
no longer matched the verified token. The reload now must still carry
the token's issuer and subject and the signing-in provider, else 409.

Startup now refuses a database holding SSO subjects without an issuer
(pre-migration-13 rows), which (issuer, subject) lookups cannot reach.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SCIM refused nothing when no issuer was configured, so a create with an
externalId stored an unissued identity and the next start refused. It
now refuses an externalId until KY_SCIM_ISSUER or KY_KYSIGNON_ISSUER is
set, and a row created before that takes the issuer with its first
subject.

Rows from before migration 13 may share a subject across providers and
all get an empty issuer, so the unique identity index now skips unissued
rows. The migration applies; the start check names the repair.

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

Copy link
Copy Markdown
Member Author

Guide findings fixed in c2eb117:

  • Restart failure: SCIM now refuses an externalId (create, PUT, PATCH) while neither KY_SCIM_ISSUER nor KY_KYSIGNON_ISSUER is set. A row created before an issuer was set takes the issuer with its first subject. TestSCIMNeverStoresASubjectWithoutAnIssuer fails under all three mutations (create check, update check, store issuer write).
  • Migration failure: the unique (sso_issuer, sso_subject) index now skips rows with an empty issuer, so migration 13 applies over legacy cross-provider collisions. The startup check then names the repair (set each issuer; delete or merge duplicates first), and the index refuses a duplicate once issuers are set. TestMigration13KeepsLegacySubjectCollisions fails with the old index predicate, on both drivers. DECISIONS 12 updated.

Sessions from before migration 13 get an empty issuer, so neither
issuer-keyed back-channel logout fence reaches them. The migration now
deletes them; local break-glass sessions stay (security review P2).

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

Copy link
Copy Markdown
Member Author

Security P2 (legacy SSO sessions) fixed in 8f67570: migration 13 deletes sessions with an sso_sid or belonging to an SSO-subject user, so no issuer-less session outlives it; local sessions stay. TestMigration13DropsSessionsNoLogoutCouldEnd runs on both drivers and fails without the DELETE.

Yoshiofthewire and others added 2 commits November 25, 2026 08:14
Resolves CHANGELOG and DECISIONS: both sides kept; the crypto stack's
decisions keep their numbers under their own heading.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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

Copy link
Copy Markdown
Member Author

Security P1 fixed in 9220dd7: SSO sign-in fails closed until local step-up. The callback issues a 5-minute pending session, which the session middleware accepts only for who-am-I and logout. SSO users can't get further until #17's TOTP exchange lands. Regression test TestOIDCSignInIsPendingUntilStepUp fails under four mutations (table in the PR body). Race and FIPS suites pass on SQLite and PostgreSQL 17.

Yoshiofthewire added a commit that referenced this pull request Nov 25, 2026
…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>
Yoshiofthewire added a commit that referenced this pull request Nov 25, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Yoshiofthewire added a commit that referenced this pull request Nov 25, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

# Conflicts:
#	docs/DECISIONS.md
Yoshiofthewire added a commit that referenced this pull request Nov 25, 2026
…t-chain

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Yoshiofthewire added a commit that referenced this pull request Nov 25, 2026
… into kyguard/intents

Drops audit-chain's "scope of this PR" decision 19: this PR builds what it deferred.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Yoshiofthewire added a commit that referenced this pull request Nov 25, 2026
…to kyguard/restore

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Yoshiofthewire added a commit that referenced this pull request Nov 25, 2026
…-login

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Yoshiofthewire added a commit that referenced this pull request Nov 25, 2026
…) into kyguard/web-restepup

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

Copy link
Copy Markdown
Member Author

Note

🤖 Claude Opus 5.5 responding on behalf of Yoshiofthewire

On "Blocked step-up": #7 fails closed on purpose. On this PR alone an SSO sign-in gets a pending session that reaches only GET /api/auth/me and logout, because the step-up routes don't exist until #17. The exchange, the /api/auth/stepup/* allowance in pendingAllowed and the integration test the note asks for are all in #17 (abd0abd), which now merges this PR's 9220dd7:

  • TestOIDCSignInStepsUpToActive signs in through the generic OIDC routes, enrolls and activates, then steps up again with a code. Dropping /api/auth/stepup/ from pendingAllowed fails it (enroll: 401).
  • TestOIDCSignInIsPendingUntilStepUp from this PR still passes there. Its only change is the refusal code: auth: pending SSO sessions and TOTP step-up (§7.3) #17 answers 403 stepup_required where this PR answers 401.

No routes were added to #7.

@Yoshiofthewire
Yoshiofthewire changed the base branch from kyguard/break-glass to main November 25, 2026 18:33
Brings in #3-#6 and the badge fix. CHANGELOG: both sides kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Yoshiofthewire
Yoshiofthewire merged commit cd5eccb 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