Repository navigation
feat(claims): static custom claims for roles and OpenID clients - #584
Merged
Merged
Conversation
DELETE /users/credentials removed a passkey without writing an audit event, so a change to what an account can sign in with left no trace. It now writes credentials_deleted naming the passkey.
Adds webhook endpoints and deliveries behind an audited admin API with step-up on every write. Payloads use the Standard Webhooks signature scheme, are built from committed audit rows past a cursor, and are retried eight times over just under 42 hours before they are dead lettered. An endpoint that answers 410 or fails for three days is disabled. Every callout to an adopter URL goes through one transport that checks the address it connects to, never reaches link-local, multicast or the API itself, never follows redirects, and in production refuses private addresses unless CALLOUT_PRIVATE_HOSTS lists the host. Signing secrets are encrypted under CALLOUT_SECRET_ENCRYPTION_KEY. Writes session_created once per completed sign-in, which user.signed_in is built from, since login_success precedes any factor. Records the design in ADR 0005. Closes #418.
Adds the two login hooks from ADR 0005 (E5), signed with the Standard Webhooks scheme like webhooks and reached through the shared callout transport. - post_login runs once the factor is proven and before the session exists, and may deny. pre_token runs for a new session and on organization switch, and may add claims or deny. - pre_token claims are kept on the session (sessions.hookClaims), copied on refresh and to an exchanged session, so neither calls a hook. They are cleared when the user leaves the organization they were decided for. - One attempt with the hook's timeout. A failure follows the hook's failure mode. A deny answers 403 login_denied with the hook's userMessage; a closed failure answers 503 login_hook_unavailable. - Reserved claim names are stripped and audited, and filtered again at mint. Break-glass administrators and recovery sessions never call a hook. - Admin routes under /admin/login-hooks/:trigger, with step-up and an audit event on every write, and an invocation log pruned after 30 days. Closes #419.
Adds custom claims from ADR 0005 (E6). - custom_claims holds one set per instance role, organization role or OpenID Provider client, behind /admin/custom-claims with step-up and an audit event (names only) on every write. Writes are validated with the shared schema and the source must exist. - mintAccessToken merges instance role sets, then organization role sets while the membership exists, then the session's pre_token hook claims, a later source winning per name, and filters reserved names again. Recovery tokens carry none. - When the sources together exceed 1 KiB the token carries no custom claims and the mint writes custom_claims_omitted. Nothing is trimmed. - Retiring a role or deleting a client deletes its set. - The cookie budget test now pins that a token at both budgets overflows the adapter cookie, which is an open decision. Closes #417.
…laims Separate 1 KiB budgets for permission claims and custom claims made the server adapter's session cookie 5670 bytes at worst, over the 4096 limit. They now share AUTHORIZATION_CLAIMS_BUDGET_BYTES (1 KiB), which replaces PERMISSION_CLAIMS_BUDGET_BYTES. CUSTOM_CLAIMS_BUDGET_BYTES stays the per-set write limit. - If the permission claims and the merged custom claims fit together, the token carries both. - Otherwise the permission claims give way first, replaced with permissions_omitted, since a guard can read GET /users/me/permissions and custom claims have no fallback. - Only when the custom claims do not fit beside the marker are they all dropped, and the mint writes custom_claims_omitted. - Nothing is trimmed partially. Recovery tokens carry neither. The worst-case adapter cookie at the shared budget measures 3868 bytes. ADR 0004 P4, ADR 0005 E6 and the API contract describe the rule.
Among roles of one kind, custom claim sets apply in role-name order. It is deterministic and does not depend on grant order, which an administrator cannot see. ADR 0005 E6 records the decision, and a test now pins the order for organization roles as well as instance roles.
A disabled endpoint was given no deliveries, so events that happened while it was off were never sent, including after the API disabled it for a 410 or three days of failures. Its deliveries are now queued on hold, and turning it back on releases them, back as far as the 30 days deliveries are kept. The release uses the database clock, which the due check compares against.
Bccorb
marked this pull request as ready for review
November 8, 2026 03:52
Bccorb
added a commit
that referenced
this pull request
Nov 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #583 (
feat/login-hooks), which is stacked on #580 (feat/signed-webhooks). Merge those first; the base moves down as each lands. Builds against the published@seamless-auth/types0.40.0.What it adds
ADR 0005 E6: static custom claims.
custom_claims(sourceKind,sourceName,claims jsonb, timestamps), keyed by source, with a check on the kind.CustomClaimRoutes:GET /admin/custom-claims(sources, reserved names and prefixes, budget) and GET/PUT/DELETE/admin/custom-claims/:sourceKind/:sourceName. Writes takerequireAdmin('write')and step-up, are inGUARDED, and are audited (admin_custom_claims_updated,admin_custom_claims_deleted) by claim name only, since values are free text in a permanent log.SetCustomClaimsRequestSchemadirectly, and the responses use the sharedCustomClaimSourceResponseSchemaandCustomClaimListResponseSchema: reserved names and prefixes, the name pattern, depth 3 and 1 KiB per set are refused. The source must exist: an instance role inavailable_roles, an organization role in the catalogue, or an existing OpenID Provider client.oidc_clientsets are stored and served only; seamless-auth-oidc-provider#47 applies them.mintAccessTokenmerges the user's instance role sets, then the active organization's role sets (only while the membership exists), then the session'spre_tokenhook claims. A later source wins per name. Among roles of one kind, sets apply in role-name order (Brandon decided this on 2026-11-07, recorded in ADR 0005 E6), so the result does not depend on grant order, which admins cannot see. Reserved names are filtered again. Recovery tokens carry none.permissions,org_roles,org_permissions) and the merged custom claims shareAUTHORIZATION_CLAIMS_BUDGET_BYTES(1 KiB, replacingPERMISSION_CLAIMS_BUDGET_BYTES). If both fit, the token carries both. Otherwise the permission claims give way first, replaced withpermissions_omitted: true, because a guard can readGET /users/me/permissionsand custom claims have no fallback. Only when the custom claims do not fit even beside the marker are they all dropped, and the mint writescustom_claims_omitted(bytes,budgetBytes). Nothing is trimmed partially.CUSTOM_CLAIMS_BUDGET_BYTESstays the per-set write limit.deleteRoleMappings) or deleting an OpenID application deletes its set, so adding the name back cannot restore old claims.Cookie budget
At the shared budget the worst-case adapter
seamless-accesscookie (five long roles, a long email) measures 3868 bytes (token 2311 bytes) when the budget is split between permissions and custom claims, and 3852 bytes when it is all permissions, under the 4096 limit. Separate budgets measured 5670 bytes, which is why the budget is now shared.Contract changes
custom_claims_omittedis categorized as atokenevent.permissions_omittedat a smaller permission set than before, since the 1 KiB is shared (ADR 0004 P4 anddocs/api-contract.mdupdated).Deviations from ADR 0005
Recorded in the ADR: the shared budget and its order (E6, chosen by Brandon on 2026-11-07, replacing a separate custom claims budget), role-name order between roles of one kind (E6, decided 2026-11-07), and under "Found while building" writes require an existing source with clean-up on removal. It also notes that
z.json()overflowed the OpenAPI generator until 0.40.0 bounded the claim value schema, so the route schemas no longer wrap the shared ones.Checks
On head e32e823, with
@seamless-auth/types0.40.0 from npm:npm run generate:apiruns on the shared claim schemas ("Generated openapi.json, src/generated/api.ts and adapter-manifest.json from 148 paths."), and the document now spells out a claim value instead of any JSON. Committed; no further diff.TEST_DB=postgres, local container) on 108a784 with 0.39.0: 16 files, 267 passed, includingtests/postgres/customClaims.spec.ts(merge order on the real schema and loss on leaving the organization, an overflow that drops the custom claims writes the audit row, sets deleted with the role and the client, the kind check constraint). Not rerun on this head; the change touches no database code.GET /users/me/permissionsstill returns the full set when the token omitted it. Role-name order is pinned for two instance roles and two organization roles setting the same claim, in both grant orders.Closes #417.