Skip to content

feat(auth): federated identity, SSO and company-level auth policy - #288

Merged
artempartos merged 27 commits into
developfrom
artempartos/feat-sso-multi-provider
Sep 28, 2026
Merged

artempartos merged 27 commits into
developfrom
artempartos/feat-sso-multi-provider

Conversation

@artempartos

@artempartos artempartos commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Adds federated identity: many identities per user, per-company OpenID Connect
connections, passkeys, authentication codes, emailed sign-in links, SCIM
directory sync, server-side sessions — and a company-level policy deciding which
of those its workspace accepts.

Draft. Everything here is green locally and exercised in a browser, but two
things have never met a real counterpart: Microsoft Entra (including admin
consent) and a real SCIM client. See What has not been verified.


The three constraints that decided the shape

  1. Enterprise SSO must work for self-hosted users. The product is Apache-2.0 and publicly distributed.
  2. No deadline — roadmap work, so total cost of ownership beats time-to-first-SSO-customer.
  3. No paid external dependency in the login path.

Those rule out the commercial CIAM market, the AGPL and paywalled OSS identity
providers, and — together with §4.5 below — SAML.

How it fits together

Two tables, not one. identity_providers is what can authenticate, at
scope: deployment (password, Google, passkey, magic link, codes) or
scope: company (a customer's own OIDC connection). company_auth_policies is
the toggle. One password_digest and one deployment-wide Google client cannot be
expressed as a row per method per company, which is why the two are separate.

Identity is (provider, subject), never email. The subject claim is binding
per kind — OIDC sub, Entra oid, never a UPN. An adapter that cannot obtain
its bound claim fails the sign-in rather than substituting another. Email may
promote an assertion to an existing user only when the provider asserts
email_verified present and true, and only when the asserting provider is
company-scoped and the address is in that company's domain. An absent claim is
not a true claim.

Every assertion is checked against the row that claims it. iss and aud
for any OIDC connection, tid for Entra. Mismatch rejects — no email fallback
and no "try the other connections" retry, because that retry is the
multi-tenant confused-deputy bug.

Enforcement is at company entry, not at the login screen, and is re-evaluated
every request. A session carries appending proofs; a workspace is satisfied
when its proofs intersect what that workspace currently enables. Cross into a
workspace that does not accept the method you proved and you are asked to add a
proof — not signed out.

A super_admin bypasses every company auth surface and in exchange may
authenticate by password only. No federated provider may ever resolve to one.

A passkey is the user's credential (AD-18). Registration and deletion are the
user's alone; a company may decline to accept a passkey but never deletes one.

No connection can lock a workspace out. A new connection arrives switched
off and must be signed in through once before it can be enabled, and a policy
edit that would strand a member is refused.

Why there is no SAML

Two ways to support it in Ruby, both rejected.

In-process: ruby-saml is the only Ruby service provider, and everything
(omniauth-saml, devise_saml_authenticatable) sits on it. Five Critical
authentication-bypass advisories in fifteen months, in three rounds, each a new
angle on the same hazard — two XML parsers, one document, one trust decision.
December 2025's was published as an incomplete fix of March's.

Out of process: a sidecar bridge was built and spiked. The OSS build took three
per-company connections with no licence gate, and the adapter's client_id shape
worked against the live authorize endpoint. It was dropped anyway — carrying a
second service is not worth what SAML buys, because enterprise SSO does not
require it. Entra ID, Okta, Ping, OneLogin, JumpCloud and Google Workspace all
speak OIDC.

What is given up: customers whose IT mandates SAML specifically, or who run ADFS
or Shibboleth.

A test bars ruby-saml and its wrappers from Gemfile.lock, so adding SAML
later is a deliberate decision taken with that history in view rather than a
quiet bundle add.

Why not Keycloak

Keycloak was the starting proposal, and it is the most feature-complete Apache-2.0
identity product in existence — it covers this entire wishlist with no custom
code. It was declined as the wrong shape for this codebase, not as a bad
product.

  • It replaces a model we already own. Memberships with states, domain
    auto-join, invitations, impersonation, soft delete. Its Organizations feature
    has no per-org theming, so what we have today would come back as custom work
    on the other side of the swap.
  • It takes the login page. Passkeys and IdP brokering are browser ceremonies
    that cannot run behind our own React form. The only workaround is Direct
    Grant / ROPC, which RFC 9700 forbids and OAuth 2.1 removed.
  • There is no free LTS. Each community minor is the patched branch for about
    three months, so self-hosters inherit a quarterly upgrade treadmill on a JVM
    identity server — with no first-party production compose file. That collides
    directly with constraint 1.
  • Password migration is not free. Keycloak hashes with SHA-256/512/Argon2,
    not bcrypt. Importing our digests needs a custom PasswordHashProvider SPI,
    or a forced reset for every password user.

It becomes the right answer if the decision is to stop being in the identity
business
— a strategic choice about what this team maintains, not a component
swap. If it is adopted anyway, the least-bad shape is broker-only: Keycloak
holds no users, Rails stays the system of record, and the bcrypt problem
disappears.

Nothing here forecloses that. Every external provider is consumed as plain OIDC
behind one seam, so putting Keycloak, Casdoor or Authentik in front of it later
is a connector change, not a re-platforming. Building this does not foreclose
Keycloak; adopting Keycloak now would foreclose everything else.

The same three constraints eliminated the rest of the market: the commercial CIAM
vendors (Auth0, Okta CIC, WorkOS, Stytch) fail constraint 3 — a paid dependency
in the login path that a self-hoster cannot run — and the AGPL or paywalled OSS
identity servers fail constraint 1, since an Apache-2.0 product cannot ship an
AGPL login path to self-hosters. Citations are in the
market research.


What it looks like

Signing in

Google and a passkey identify the person on their own — Google runs its own
account picker, a passkey is discoverable. Company SSO and an emailed link start
from the address, so they stay inactive until one is typed, and the screen says
why rather than leaving a grey control unexplained.

Nothing typed Address typed

Enterprise SSO discovery

The workspace is resolved from the address's domain. One enabled connection
starts immediately; several offer a choice rather than a guess; none says so
instead of failing obscurely.

Two connections No workspace claims that domain

The emailed link

The mail carries the address a browser actually reaches the app at, port
included. Opening it lands on a confirmation rather than consuming the token,
because mail providers pre-fetch links.

Requested Delivered Confirm before it is spent

Company auth policy

What a workspace accepts, and the connections it owns. A new connection arrives
switched off and carries Not verified yet until someone has signed in through
it once.

A workspace that refuses passwords A connection awaiting its first sign-in

The entry gate

A session proved one way crosses into a workspace that does not accept it and is
asked to add a proof, not signed out. Every method the workspace accepts gets a
control.

Stopped at the gate Proved, and through

Enrolling authentication codes

The QR carries the same secret as the text below it; the text is the fallback for
an authenticator with no camera. Both are redacted here, and the secret the QR
encoded was destroyed after capture.

Who may change any of it

Admin-only in both places it is enforced: a member has no navigation entry, and
typing the path directly is refused rather than merely hidden.

A member's navigation A member typing the path

Auto-join answers which company; the method answers whether

The email domain decides which workspace someone lands in. It never asked
whether that workspace accepts the method they just signed in with, so a Google
sign-in could plant a membership in a workspace that has Google switched off.

That membership can never be entered — the gate re-checks the policy on every
request — and once active it strands its holder, which makes PolicyUpdater
refuse every later policy edit by that company's admins. A membership nobody
can use is worse than no membership: it reads as access, counts as a member, and
quietly freezes the policy screen.

Auth::DomainAutoJoin now declines such a company.

Two related weaknesses are recorded in §7 of the RFC rather than fixed here,
because both are older than this branch and neither is safe to change quietly:
companies.email_domain is an unverified trust anchor, and RESERVED_DOMAINS
is not a public-mail blocklist — it holds fourteen implausible .com names and
no mail provider at all. Company creation being admin-only is what makes that
safe today.

Defects a green suite could not see

Found by driving a browser, not by tests. Each has a regression test now.

  • Impersonation privilege escalation (critical). sign_out never cleared the impersonation key, and session rotation carried it across reset_session. Verified by reverting the fix: a bystander got 200 on /admin.
  • Password credentials never reached the resolver (critical). Anyone whose password postdated the migration had no identity row, so the no-stranding guard refused every policy edit.
  • A SCIM rename could repoint a membership (critical). userName is immutable now, and auto-accept is limited to the company's own domain.
  • Microsoft nOAuth-class takeover (high). Entra sends no email_verified and proves no domain ownership, so that adapter reports email_verified: false unconditionally.
  • SCIM writes were rejected by CSRF in every environment except test, where forgery protection is off — so no request test could catch it. The regression test turns it back on.
  • Emailed links pointed at the wrong port. development.rb overrode the DOMAIN-derived default_url_options with the container-internal port. A config test now reads the environment files, because nothing in a test run exercises development.
  • The step-up screen named three accepted methods and rendered one field.

A deadlock only a deployment could show

The screen told a company admin: "A new connection arrives switched off. Sign
in through it once, then enable it here."
That was impossible to follow.

POST /auth/oidc/:id/start        → 302 /login?error=oauth_failed
PUT  /company/auth_policies/:id  → "no administrator has signed in
   {"enabled": true}                through Acme Okta yet"

Starting a connection required it to be enabled; enabling it required a
completed sign-in through it. Only a super_admin — who bypasses the
activation guard — could break the cycle, so no customer could ever set up
their own SSO.

Both guards were individually tested and green: one test asserts that a
disabled connection cannot be started (correct, against a stranger guessing an
id), and the activation test seeds the identity row directly. Only the pair
deadlocks, which no unit of either could see. It surfaced within minutes of the
first staging deploy.

An admin of the owning company may now start a connection that is still
switched off, and the screen has the Verify button that does it. It stays a
verification rather than a way in: the company does not accept the method, so
the entry gate turns the resulting session away exactly as before, and the
toggle stays shut until the sign-in actually completed. AD-7 rule 1 now says so
explicitly.

Verified on staging

Deployed to staging.flow.aixle.com and exercised there: the method set derives
correctly from configured credentials (Microsoft absent because its keys were
unset), the backfill leaves password and Google enabled for existing companies,
the SCIM endpoint carries the right host, and live sessions survive the cutover —
signing in lands straight in the workspace, no forced re-authentication.

What has not been verified

  • Microsoft Entra against a real tenant, including admin consent.
  • SCIM against a real client (Entra, Okta). Only our own tests.
  • Google end to end: the dev OAuth client has only localhost:4000 registered, so a run from an isolated environment on another port returns redirect_uri_mismatch. Everything up to that point is proven — Google accepts the client_id and rejects only the URI.

Checks

Run through isolated Docker runners, not docker compose exec web: this branch
was developed in a git worktree outside the compose mount, so that service does
not exist there. Same coverage as make check_all; CI runs the ordinary command.

Rebased onto develop at eb694200.

rails test 6573 runs, 20055 assertions — 0 failures, 0 errors, 0 skips
coverage 93.09%
rubocop 2020 files, 0 offenses
brakeman 0 security warnings
tsc / eslint / steiger clean
vitest 134 files, 1573 tests

Folded onto develop's server-side sessions

While this branch was open, #309 built server-side sessions independently:
UserSession, with revocation, idle and absolute timeouts, impersonator_id,
sign-out-everywhere and cable disconnect. This branch had built the same concept
as AuthSession, carrying the one thing theirs did not — the proofs the
company-entry gate reads.

Rather than keep two session tables with two lifecycles, AuthSession is gone
and the proofs moved onto theirs:

user_sessions            their lifecycle
  └─ user_session_proofs  which method satisfied this session

Auth::SessionService shrank from five methods to one, record_proof: starting,
revoking and timing a session out are no longer its business. The impersonation
fix this branch carried is superseded — impersonator_id solves it more
cleanly than patching a cookie key — so only the gate's impersonation exemption
survives.

Three things the merge could not have found on its own:

  • rotp was test-only on develop. This branch needs it at runtime:
    User#totp_secret and Auth::Methods::Totp both run on it. Promoted out of
    the test group.
  • This branch's secrets bypassed encrypted_column, encrypting through the
    raw encryptor. They were therefore invisible to encryption:reencrypt: a key
    rotation would have left identity_providers.encrypted_secret and
    users.encrypted_totp_secret on the retired key and unreadable once it was
    dropped. Both now go through the concern, which also gives them fix!: security and reliability improvements #309's purpose
    binding.
  • The broad /auth/ rate-limit safelist exempted the OIDC start action —
    an endpoint a person triggers, not an identity provider. Only the narrow
    callback safelist survives.

Migration

Nobody is signed out. The gate answers "which method backs this session" from
user_session_proofs, and sessions predating that table have no proof — so every
one of them would have been sent to step-up on the first request after deploy, not
because a policy changed but because the question is new and user_sessions
records no method.

ProveLiveSessionsAtCutover recovers the answer where it is unambiguous: a user
holding exactly one identity provider authenticated through that one, because
there was nothing else to authenticate through. A user holding several is skipped
— choosing between them would be inventing the proof rather than recovering it,
and step-up is the right outcome there. The proof is dated from the session's own
creation, not from the deploy.

This replaces the earlier plan of one forced global re-authentication, which was
chosen before the alternative had been examined.

Verified on staging

Driven end to end against a live Entra tenant and a live Okta org, not only in
tests:

  • Google, password, passkey (CDP virtual authenticator) and TOTP sign-in
  • Microsoft: button derived from credentials, redirect carries the right
    client_id and /auth/microsoft/callback, Entra accepts the password
  • A company OIDC connection: add, verify-before-enable, the prove/enable deadlock
  • SCIM: token shown once, listing scoped to one company, provisioning and
    deprovisioning reflected in Members, 400 refusing to deprovision the last
    admin, 401 for an unknown or disabled token

Two faults surfaced there that no request test could have caught, because both
live between the server and a real client — see Fixed since the draft.

Fixed since the draft

  • /scim/Users returned 404. SCIM fixes the path with a capital U and
    Scimitar advertises it that way in ResourceTypes, but Rails routing is
    case-sensitive and resources :users answers /scim/users. The feature could
    not have worked against any real directory. The same draw also pointed PUT at
    Scimitar's #update, which expects a PATCH Operations body. Both were
    invisible to the request tests, which chose their own URLs.
  • /scim had no rate limit. One bearer token is all that stands between a
    stranger and a company's membership list. Two throttles, per credential and per
    IP, keyed on a digest so a bucket never holds a live credential.
  • Verifying a connection could not work from an Inertia visit — router.post
    cannot follow a cross-origin redirect. It is a real form submission now.
  • Prove-before-enable deadlocked: a connection had to be verified to be
    enabled, and enabled to be verified.
  • User-facing documentation published under /docs.
  • SSO discovery never reached the provider. Resolving an address to its
    company's single connection answered with a 303 to /auth/oidc/:id/start —
    a POST-only route, deliberately so (CVE-2015-9284), and a redirect is
    followed with GET. Every workspace with exactly one connection had no working
    "Sign in with your company SSO". The test asserted the redirect target was
    oidc_start_path, which is exactly what was broken; it never asked whether a
    browser could follow it.
  • Rails named the SCIM routes after their path literal — scim_Users,
    capital and all, reaching the frontend as scimUsersPath, and a bare scim
    that required an :id. Named explicitly now.

Merged in from its own PRs

Both were reviewed separately and merge into this branch rather than develop,
so the release does not first ship a screen we already know we are changing.

  • refactor(settings): move sign-in methods into company settings as Access #337 — sign-in methods become the Access tab of company settings. Each tab
    is its own URL, because the two halves save differently: General is one form
    behind one Save, Access applies every control on the spot. Domain auto-join
    moves with it, and General stops carrying autoAcceptUsers at all — resending
    a stale copy from there would have undone a change made on Access.
  • refactor(auth): draw every sign-in method with one component #339 — one component for every sign-in method. The five were built five
    different ways, including a classNames={{ root: undefined }} that left the
    Microsoft button with none of Google's styling. One height, one border, and a
    fixed icon column so every label starts at the same x.

Documents

🤖 Generated with Claude Code

@artempartos
artempartos force-pushed the artempartos/feat-sso-multi-provider branch from 2cfbd01 to 8815638 Compare September 17, 2026 22:50
artempartos added a commit that referenced this pull request Sep 18, 2026
Six PNGs sat in the tree that nothing in it references.

`01-admin-projects-single-company.png` has been at the repository root
since 48c15ea, unreferenced — a screenshot that escaped into the commit
rather than into a pull request.

`docs/design/images/github-pat-connect/` (5 files, #292) backed that pull
request's description and no document, which is the difference from
`docs/design/images/federated-identity/` on the open #288 branch: those
are embedded in `docs/design/federated-identity.md` with relative links,
so they are the document's own assets and stay.

#292's description now points at its merge commit rather than at its
branch, so the screenshots keep rendering from history after both this
removal and the branch's eventual deletion. Verified: all five answer 200.

Signed-off-by: Artem Petrov <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
@artempartos
artempartos force-pushed the artempartos/feat-sso-multi-provider branch 2 times, most recently from 0bc29d3 to 7f424a0 Compare September 25, 2026 12:14
artempartos and others added 14 commits September 25, 2026 20:58
Market research for broad login coverage, the architecture spine it produced,
the companion RFC, and the BMAD spec kernel.

The research answers why this is built rather than bought: three constraints —
enterprise SSO must work for self-hosted installs, there is no deadline, and no
paid dependency may sit in the login path — eliminate the commercial CIAM market
and the AGPL or self-hosted-paywalled identity providers before any feature
comparison. Keycloak is evaluated on its merits and declined on fit with an app
that already owns its user and organization model.

The spine carries 26 invariants (AD-1..AD-26) with Binds/Prevents/Rule, four
reviewer-gate reports, and an append-only memlog of every decision. Two
questions are left open rather than answered: the sidecar's OSS tenancy, and
IdP-initiated SSO.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
Six capabilities on one seam: a port with an adapter per authentication method,
so adding a method is an adapter plus a provider row and never a change to the
entry gate.

Foundation. Identity is (provider, subject), never email — the previous
resolution joined on address alone and never read email_verified, which is an
account-takeover path the moment a second provider exists. Sessions become
server-side rows whose proofs append, so revocation works, "sign out everywhere"
is possible, and a user in two companies with disjoint policies is not bounced
between step-ups forever.

Company auth policy. Providers and policy are two tables, because a
deployment-wide Google client and a per-customer SAML connection are not the
same shape. Enforcement is at company entry, re-evaluated every request beside
the membership check, and a mismatch redirects to step-up rather than signing
anyone out. A policy edit that would strand any active member is refused and
names them; deletion is evaluated exactly as disabling.

Methods. Microsoft (Entra), per-company OIDC with PKCE and a server-side nonce,
passkeys, single-use emailed links, and TOTP as a step-up that can never start a
session. Every assertion is bound to the row it claims to satisfy — iss, aud,
nonce, tid, bridge tenant — with no email fallback when binding fails.

SAML never enters this process. A connection row holds the bridge's keys, not
IdP metadata, and an invariant test fails if ruby-saml or omniauth-saml ever
appear in Gemfile.lock: five Critical authentication-bypass advisories in
fifteen months is not a dependency to carry in the web process.

SCIM is a first-party endpoint scoped by its bearer token alone, writing
memberships through the same state machine the UI uses and never writing
identities.

Two adversarial reviews caught four defects a green suite did not: an
impersonation marker that outlived its session and granted admin to whoever
signed in next, password credentials that never reached the identity resolver
and so broke the stranding guard for everyone, a SCIM rename that could repoint
a membership at an unrelated account, and a Microsoft assertion that could adopt
an existing account because Entra proves no domain ownership. All four are fixed
and covered.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
Removes the SAML adapter, the bridge client, the compose profile and their
tests. A spike had verified the bridge first — the OSS build took three
per-company connections with no licence gate, the adapter's client_id shape
worked against the live authorize endpoint, and along the way it showed that the
published compose image name did not resolve at all, that one entityID may serve
only one tenant, and that the bridge phones analytics home unless told not to.

None of that was the deciding factor. Carrying a second service is not worth
what SAML buys, because enterprise SSO does not require it: per-company OIDC is
already implemented and tested, and Entra ID, Okta, Ping, OneLogin, JumpCloud and
Google Workspace all speak it. What is given up is customers whose IT mandates
SAML specifically, or who run ADFS or Shibboleth.

The in-process alternative stays rejected for the reason it always was: ruby-saml
is the only Ruby service provider, and it has had five Critical
authentication-bypass advisories in fifteen months — December 2025's published as
an incomplete fix of March's. A test now bars it and its wrappers from
Gemfile.lock, so adding SAML later is a deliberate decision taken with that
history in view rather than a quiet bundle add.

BREAKING CHANGE: the `sso` compose profile and the SSO_BRIDGE_* settings are
removed. No deployment used them.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
Found by running the feature in a browser against a real database. Each belongs
to a class the suite is structurally blind to.

Inertia camelizes prop keys, so every snake_case prop the new pages read came
back undefined: the login screen offered Google on an installation with no
Google credentials and hid passkeys and magic links entirely. Component tests
passed because the test supplied the props, which made them a record of the
author's guess rather than of the contract.

SCIM writes were rejected with "Can't verify CSRF token authenticity". The test
environment disables forgery protection, so request tests were green while a
real directory — which sends a bearer token and no CSRF token — could not
provision anyone. The regression test turns protection back on for that case.

The emailed sign-in link pointed at the wrong port: url_for splits a `host` that
carries one and falls back to the environment default. Invisible in production,
where the domain has no port. Built as a string now, like the OIDC callback.

The SCIM token was passed through a redirect's query string, putting a
credential in browser history, access logs and any Referer. It travels in the
flash.

The step-up code form always failed: setData followed by post sends the previous
state, so a TOTP attempt submitted as a password attempt with an empty password.
The payload is built explicitly and the test now asserts what was posted.

Magic link and passkey sign-ins replaced the live session instead of appending
their proof, unlike the OIDC path — which would have defeated step-up through
either. One shared `sign_in_or_prove` now governs all of them.

Also: deployment providers no longer freeze a humanised label into every
installation's data ("Totp"), the SCIM endpoint is shown before a token exists,
and schema.rb keeps its committed check-constraint rendering.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
The step-up screen named the methods a workspace accepts but only rendered
a control for some of them: `magic_link` had no start path, and `passkey`
has no redirect at all, so both were listed and then unreachable. Someone
whose workspace accepted only those two was told what to do and given no
way to do it.

`magic_link` now starts at `request_magic_link_path`, which fills the
address in from the signed-in user rather than asking for it again, and
the passkey ceremony runs inline on the page.

Also: the sign-in methods page is admin-only in the sidebar, the three
standalone auth screens center their content, and the two settings pages
render inside AuthLayout so they keep the sidebar and page padding.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
config/application.rb derives ActionMailer's default_url_options from
Settings.domain and Settings.protocol, so they follow DOMAIN. development.rb
then set them again to a hardcoded host plus the port the process listens on.
Those two ports are the same only when nothing is published in front of the
app: behind a port mapping, a proxy or a container they differ, and every
emailed link points at a port the recipient cannot open. A sign-in link from a
second dev stack led back to the first one.

MagicLinkMailer built its URL as a string to dodge this, and blamed url_for in
a comment. url_for was never at fault — passing a host that carries a port
works fine until a `port:` option overrides it, which is exactly what the
override added. Both mailers now use the ordinary url helpers.

The guard has to read the config files: nothing in a test run exercises the
development environment.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
Enrolment handed over a 32-character base32 secret and left the person to
retype it. The server already built the otpauth:// URI that an authenticator
reads from a QR; nothing rendered it.

Auth::QrCode renders that URI as an SVG data: URI, so the page shows it with
a plain img tag — no QR library in the bundle and no server-built markup
injected into the document. The image carries its own white ground and the
four-module quiet zone the format requires: left transparent it inherits the
page, which on the dark theme is dark-on-dark and unscannable. The typed
secret stays as the fallback for an authenticator with no camera.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
Both sit above the email field and both are disabled until it has something,
because both start from the address: SSO resolves the workspace from its
domain, and a link has to be sent somewhere. Google and a passkey need no
address — Google runs its own account picker, a passkey is discoverable — so
they stay active. Nothing on screen said any of that, and a greyed control
with no reason reads as broken.

A line under the group now names the reason while the address is missing, and
narrows itself when the installation offers no emailed link.

The block was also duplicated between the ordinary card and the error card;
it is one SignInMethods component now.

Reconciles docs/design/federated-identity.md with the dropped SAML sidecar:
the scope, goals, identity-binding and Keycloak paragraphs still described a
bridge that no longer exists, and the open-questions table still listed five
questions that are all now answered or withdrawn.

Corrects the callback_url comment, which repeated a wrong diagnosis of
url_for. The reason to build that string by hand is real but different: the
value must match what the customer registered byte for byte and must not vary
with the request, and url_for in a controller takes the host from the incoming
request.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
…iation

The RFC now shows the shipped surfaces: signing in, SSO discovery (one
connection, several, none), the emailed link end to end, company auth policy
with an unverified connection, the entry gate before and after, code
enrolment, and the admin-only policy surface refused to a member both ways.
Captured from a running build with the TOTP secret redacted and the secret it
encoded destroyed afterwards.

docs/index.md still described a SAML sidecar in three entries and counted 17
ADs where the spine has 28; the spec still carried an open question about
IdP-initiated SSO that only existed because of SAML. The spine itself was
already coherent — AD-8 and AD-9 are marked retired by AD-28.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
The Settings refactor that landed on develop (#270) brought a guard: every
environment variable a settings file reads must have a row in
docs/reference/configuration.md, and the docs portal must serve that file
rather than a hand-copy. Rebasing onto it surfaced four undocumented
variables from this branch.

AUTH_ENABLED_KINDS is worth reading twice: availability is derived from which
credentials are actually present, so the allowlist can only ever offer less
than that — an installation with no Microsoft credentials never offers
Microsoft however it is set.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
The email domain picks WHICH company someone joins. It never asked WHETHER
that company accepts the method they just signed in with, so a Google sign-in
could plant a membership in a workspace that has Google switched off.

That membership can never be entered — the entry gate re-checks the policy on
every request — and once active it strands its holder, which makes
PolicyUpdater refuse EVERY later policy edit by that company's admins. A
membership nobody can use is worse than no membership: it reads as access,
counts as a member, and quietly freezes the policy screen.

Auth::PolicyResolver.accepts? answers the question with one EXISTS rather than
plucking the whole set to test a single id, and lives beside the rest of the
effective-set arithmetic because that module is declared its only computation.

The test for the freeze goes through IdentityResolver rather than the factory
on purpose: a factory-built user carries a password identity and could never
be stranded, so the first version of it proved nothing.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
Hand-merging this generated file during the rebase dropped a closing brace.
Regenerated from the routes themselves rather than patched.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
Rebasing surfaced four things the merge itself could not.

`sign_in_or_prove` ended up defined twice — the second copy, from the
defects commit, still named the model this branch no longer has, and being
last it won. The Google callback's `rescue StandardError` turned the
resulting NameError into a plain "oauth_failed" redirect, so the only visible
symptom was a proof that never appended.

The test helper still called a SessionService method that is gone. A cookie
carrying only a user id is adopted into a session row on first use, but an
adopted row holds no proof and the entry gate reads proofs, so the helper
mints the row itself.

Encryptable changed shape on develop: `encryption_key :name` replaces the
old override. Both of this branch's secrets were also encrypting through the
raw encryptor rather than the concern, which kept them out of
`encrypted_columns` — so `encryption:reencrypt` would have skipped them and a
key rotation would have left them unreadable once the retired key was
dropped. They go through `encrypt_secret`/`decrypt_secret` now, which also
gives them the purpose binding #309 introduced.

Impersonation hygiene is develop's now: impersonating is a sign-in of its own
recording `impersonator_id`, which covers the escalation this branch had
patched by hand. The test moves to that design and gains the case their
model's own comment promises — suspending the operator mid-impersonation
ends their admin access.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
The template marketplace (#312) landed a migration at the same timestamp this
branch had used, which aborts `db:migrate` outright. The table it creates
depends only on user_sessions and identity_providers, both far earlier, so the
later slot costs nothing.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
@artempartos
artempartos force-pushed the artempartos/feat-sso-multi-provider branch from 7f424a0 to 24b2d28 Compare September 25, 2026 13:11
artempartos and others added 8 commits September 25, 2026 22:59
AD-7 wants a company-scoped connection proved before it can be enabled, and
the proof is a completed sign-in through it. Refusing to START a disabled
connection made that impossible: no sign-in until enabled, no enabling until
signed in. Only a platform operator could break the cycle, so a company admin
could never set up their own SSO — while the screen told them to "sign in
through it once, then enable it here".

An admin of the owning company may now start one that is still switched off.
It stays a verification rather than a way in: the company does not accept the
method, so the entry gate turns the resulting session away exactly as before,
and the connection still cannot be enabled until the sign-in actually
completed. The screen gains the Verify button that starts it, and the toggle
is held shut until it has.

Found by deploying to staging. Both guards were individually tested and green
— "a disabled connection cannot be started" asserts the refusal as correct,
and the enable guard seeds the identity directly. Only the pair deadlocks,
which no unit of either could see.

Also corrects three documents that still promised one forced global
re-authentication at the cutover. That followed from this feature owning the
session record; it no longer does, so live sessions survive and the cutover
costs one step-up instead.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
Verifying redirects to the customer's identity provider, and an Inertia
`router.post` is an XHR: the browser refuses to follow a cross-origin redirect
from one, reports it as CORS, and the page simply sits there. The server was
right all along — the authorize URL was built with PKCE and returned as a 302 —
so no request test could see it. GoogleLoginButton is a form for exactly this
reason; the Verify button now is too.

Still POST with a CSRF token rather than a link: a GET start can be triggered
on a victim's session from an external page (CVE-2015-9284).

The page gains the tests that express the difference a request test cannot —
that Verify submits a form at the start path carrying an authenticity token,
that an unverified connection holds its switch shut, that Verify disappears
once proved, and that a member sees neither Verify nor Remove.

Found on staging within minutes of deploying the fix it belongs to.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
SCIM fixes its collection at "/Users", capital U, and Scimitar advertises
it that way in ResourceTypes. Rails routing is case-sensitive, so the
`resources :users` draw answered "/scim/users" and returned 404 for the
only spelling Entra or Okta ever sends — the feature could not have
worked against a live provider.

The same draw pointed PUT at Scimitar's #update, which expects a PATCH
"Operations" body, so a provider's replace would have been parsed as a
patch. PUT now reaches #replace.

Neither fault was visible to the request tests: they chose their own
URLs, and lowercase happened to be the one they chose. The added routing
assertions pin the canonical spellings, and the round-trip test follows
the Location header of a created member back to a fetch.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
On a deployment that exposes /scim to the internet, one bearer token is
everything standing between a stranger and a company's membership list,
and nothing else about the request identifies the caller.

Two throttles: per credential, generous enough for a real directory's
reconciliation sweep, and per IP, which caps guessing at a rate no
attacker can use. The cache key is a digest, so a throttle bucket never
holds a live credential.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
Two pages: one for a workspace admin — what the methods are, how a
workspace decides which it accepts, connecting an OIDC provider, the
verify-before-enable step, step-up, directory sync — and one for whoever
runs the installation, covering the credentials each provider needs and
why availability is derived from them rather than declared.

Registered in all five places a /docs page has to appear, including the
Ruby slug list in Web::DocsController that is the easy one to miss.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
The policy gate answers "which method backs this session" from
user_session_proofs. Sessions that predate that table have no proof, so
every one of them would be sent to step-up on the first request after
deploy — not because a company's policy changed, but because
user_sessions records no method and the question is new.

Where the answer is unambiguous it is recovered instead of asked for: a
user holding exactly one identity provider authenticated through that
one, because there was nothing else to authenticate through. A user
holding several is skipped, since choosing between them would be
inventing the proof rather than recovering it, and step-up is the right
outcome there.

The proof is dated from the session's own creation, not from the
deploy — that is when the person actually authenticated.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
…ppear

Setting a password creates its identity (User#link_password_identity),
so a plain factory user already holds one provider. The tests were
written as if it held none, which inverted every expectation: the
"no identity" case was proved and the single-provider cases were skipped
as ambiguous.

The shapes now mirror the ones a deployment actually has after the
backfill — a password user, a Google-only user, and the two edges the
migration refuses to guess at.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
@artempartos
artempartos marked this pull request as ready for review September 27, 2026 14:32
Left unnamed, Rails takes the name from the literal path segment: the
collection became `scim_Users` — capital and all, which then reaches the
frontend as `scimUsersPath` — and the next route on the same path fell
back to a bare `scim` that requires an `:id`, reading as the engine root
rather than a member.

The paths themselves are unchanged; only their names are. Nothing in the
frontend referenced the derived helpers, since SCIM is machine-facing.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
Resolving an address to its company's single connection answered with a
303 to /auth/oidc/:id/start. That route is POST only — deliberately, so
a GET cannot be triggered on a victim's session (CVE-2015-9284) — and a
redirect is followed with GET, so the browser landed on a routing error
instead of signing in. Every workspace with exactly one connection had
no working "Sign in with your company SSO".

Discovery now begins the authorization itself, sharing the redirect with
#start so the two ways of reaching a connection cannot drift. It is
already the person's own POST with their CSRF token, so the second hop
added nothing.

The test asserted the redirect TARGET was oidc_start_path, which is
precisely what was broken — it never asked whether a browser could
follow it. It now checks that discovery leaves for the provider, and a
second test pins that it never again answers with one of our own paths.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>
artempartos and others added 2 commits September 27, 2026 20:18
…ess (#337)

* refactor(settings): move sign-in methods into company settings as Access

They read as settings and were reached from a separate sidebar entry, so
the screen is now the Access tab of company settings: which methods the
workspace accepts, its own OIDC connection, its directory sync, and who
may join without an invitation.

Each tab is its own URL rather than a client-side panel swap, because
the two halves save differently — General is one form behind one Save,
Access applies every control on the spot. A tab that is also a route
keeps that honest and stays linkable.

Domain auto-join moves with it: it answers the same question as
everything around it. It is saved on the spot too, since a lone Save
button for one switch would be the only control on the tab that behaved
differently, and settings#update now returns to the tab the edit came
from. General no longer carries autoAcceptUsers at all — resending a
stale copy from there would have quietly undone a change made here.

The list is now reachable by members, read-only: knowing which methods a
workspace accepts is how someone makes sense of a step-up prompt.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>

* fix(settings): follow the moved Access page from every caller

Removing the auth_policies index route removed company_auth_policies_path
with it, and three controllers still redirected there: adding, updating
and removing an OIDC connection, both SCIM token actions, and the return
from verifying a connection. Rails only raises on the call, so the page
itself looked fine.

The two settings tests that covered the Joining card move to where the
card now lives. What replaces them on the general tab asserts the
absence: a second control for the same field would fight the one on
Access, and this page's deferred Save would send a stale copy over it.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>

---------

Signed-off-by: Artem Petrov <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
The five methods were built by three components with five different
recipes: two at size lg and three at the default, two with variant
subtle so they carried no border at all, and MicrosoftLoginButton
applying `classes.googleButton` from a stylesheet that never defined it
— so it silently got none of Google's styling and fell back to the
browser font. Only two methods had an icon, so their labels started at
four different x positions.

AuthMethodButton fixes the shape once: one height, one border, and a
fixed icon column held even where a method has no icon, which is what
puts every label on the same x. Google and Microsoft were byte-identical
apart from an icon, a path and a label, and are now exactly that.

Credentials move above the methods. Two of them wait on the address, and
the field they wait on used to sit below them — the hint said "enter it
below", pointing past the controls it excused.

Also collapses the login card: `error ? <Paper>…</Paper> :
<Paper>…</Paper>` held two byte-identical branches of ~85 lines each.

Signed-off-by: Artem Petrov <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
…takes (#341)

* feat(auth): ask for the address first, then offer what the workspace takes

The login screen offered every method at once and greyed out the two
that need an address — with the field they need sitting below them. Now
it asks for the address, and what comes back is decided by its domain:
a workspace that signs in through a provider goes straight there, one
that does not gets a second step drawn from exactly the methods it
accepts. Nothing that cannot complete is ever offered.

Decided by the DOMAIN, never by whether an account exists. An unknown
address at a known domain answers identically to a known one, or the
screen becomes an oracle for which addresses are registered — there is a
test that compares the two responses field by field.

Authentication codes are excluded at the service: six digits confirm a
session that already exists, and there is nobody to look up from them.

/login/sso becomes /login/identify. Its "this domain has no SSO" branch
stops being the error `no_sso_connection` and becomes the ordinary
second step, which is what it is for most domains.

Validation splits with the screen: the address is settled on step one
and is not editable on step two, so a complaint about it there would
have had nowhere to appear.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>

* fix(auth): keep a refused password on the step it was typed on

Signing in is two screens now, and two things still assumed one.

The system-test page object filled an address and a password together;
the password box only exists on the second screen, so every system test
that signs in died on it. It walks both steps now, and waits for the
second to arrive rather than reaching for a field the server has not
sent yet.

And a refused password redirected to /login — which is the ADDRESS step,
so a typo cost you the address you had already given. It re-renders the
credentials step instead, with the workspace's methods and the refusal
on it. An address no workspace claims still goes back to the start;
there is no step two to return to.

The render moves to a concern, since #identify and #create both reach it.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>

* test(auth): assert the refusal, not the redirect it used to be

A soft-deleted account is still refused at login; it now stays on the
credentials step with the message instead of redirecting, like any other
refusal. The test pinned the redirect, which was the transport rather
than the behaviour.

What it was there for is untouched and still asserted: no session comes
out of it, so the account is refused AT LOGIN rather than signed in and
then dropped by current_user's not_deleted scope.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Signed-off-by: Artem Petrov <[email protected]>

---------

Signed-off-by: Artem Petrov <[email protected]>
Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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