Skip to content

Sign in with an identity provider

People can sign in to the leader with an identity provider their organization already runs - Microsoft Entra ID, Keycloak, Google, GitHub, or any OpenID Connect issuer - next to, or instead of, a local password. Each configured provider gets a Continue with ... button above the password form on /login, and a Link button on the profile's Security tab.

The leader is an OpenID Connect client here (the authorization code flow with PKCE); it is never the provider. The CLI and agents need nothing new: swarm login and the OAuth device flow go through a browser session, so they get the same sign-in.

Configure a provider

A provider is a set of environment variables on the leader, named SWARM_OIDC_<NAME>_*, where <NAME> is letters and digits. It exists once SWARM_OIDC_<NAME>_CLIENT_ID is set; one with a missing secret or an unusable issuer is logged at startup and left out. The startup log lists the providers it loaded (Identity providers: ...).

Variable Effect
_CLIENT_ID The client id the provider issued to the leader.
_CLIENT_SECRET or _CLIENT_SECRET_FILE Its secret, or a file holding it (a mounted secret).
_PRESET oidc, keycloak, entra, google or github. Defaults to the name when the name is one of them (SWARM_OIDC_GOOGLE_* is Google), else oidc.
_ISSUER The issuer URL discovery starts from (<issuer>/.well-known/openid-configuration). HTTPS; plain HTTP only to localhost. Google and Entra fill it in.
_SCOPES Space- or comma-separated. Default openid email profile; GitHub read:user user:email (plus read:org with _ALLOWED_ORGS).
_LABEL The button's text after "Continue with". Defaults to the preset's name.
_LINK_BY_EMAIL 1: on a first sign-in, attach the identity to the local account with the same provider-verified email. Off by default - see below.
_ALLOWED_DOMAINS Comma-separated email domains allowed to sign in. Empty allows any.
_ALLOWED_TENANTS Entra: comma-separated tenant ids allowed to sign in.
_TENANT Entra: the tenant id or domain; default organizations (any work or school account).
_HOSTED_DOMAIN Google: the Workspace domain (hd claim) required.
_ALLOWED_ORGS GitHub: comma-separated organizations; the account must be an active member of one.
_ROLES_CLAIM Dotted path of the claim with groups or roles. Default groups; Keycloak realm_access.roles.
_ADMIN_ROLES Comma-separated values of that claim that make an account an admin. Set, the role is applied at every sign-in: anyone without one becomes a user (the last admin keeps the role). Unset, the leader manages roles itself.
_REQUIRE_MFA 1: refuse an ID token whose amr claim does not include mfa.

Register the leader at the provider with this redirect URI:

https://<leader>/auth/oidc/<name>/callback

<name> is the lower-case name. The leader builds the URI from SWARM_LEADER_URL when it is set, else from the address the request arrived on; behind a proxy, set SWARM_LEADER_URL to the address people use, or the provider refuses the redirect and the sign-in's state cookie is not sent back.

Generic OpenID Connect

Any issuer with discovery: Authentik, Zitadel, Auth0, Okta, Authelia, Dex.

SWARM_OIDC_SSO_ISSUER=https://id.example.com/application/o/silentswarm
SWARM_OIDC_SSO_CLIENT_ID=silentswarm
SWARM_OIDC_SSO_CLIENT_SECRET_FILE=/run/secrets/oidc-sso
SWARM_OIDC_SSO_LABEL="Example Corp"

Keycloak

The issuer is the realm. To let Keycloak decide who is an admin, give those people a realm role and name it:

SWARM_OIDC_KEYCLOAK_ISSUER=https://keycloak.example.com/realms/lab
SWARM_OIDC_KEYCLOAK_CLIENT_ID=silentswarm
SWARM_OIDC_KEYCLOAK_CLIENT_SECRET=...
SWARM_OIDC_KEYCLOAK_ADMIN_ROLES=swarm-admin

A client role works too: _ROLES_CLAIM=resource_access.silentswarm.roles. A stock Keycloak puts realm roles (realm_access.roles) in the access token only, not the ID token. With _ADMIN_ROLES set, the leader reads the roles claim from the ID token when it is there, else from the access token, else from userinfo: no mapper is needed. The access token counts only when it is signed by the realm's keys, unexpired, issued to this client (azp) and for the same user as the ID token. For client roles set _ROLES_CLAIM to resource_access.<client_id>.roles. Keycloak puts email_verified in the token from the user's Email verified flag; an address that is not verified there is not trusted here.

Microsoft Entra ID

Register an app (App registrations, platform Web, the redirect URI above) and create a client secret.

SWARM_OIDC_ENTRA_CLIENT_ID=<application (client) id>
SWARM_OIDC_ENTRA_CLIENT_SECRET=...
# One tenant:
SWARM_OIDC_ENTRA_TENANT=<directory (tenant) id>
# Or any work account, from some tenants only:
SWARM_OIDC_ENTRA_ALLOWED_TENANTS=<tenant id>,<tenant id>

The identity is the tenant id plus the object id (tid + oid), never the email, which a user or admin can change and which may be missing. Entra does not mark emails verified by default: add the optional claim xms_edov (and email) to the ID token under Token configuration, or the leader cannot create accounts for, or link by email, people from that tenant. Accounts can still be linked from the profile.

Google

SWARM_OIDC_GOOGLE_CLIENT_ID=<id>.apps.googleusercontent.com
SWARM_OIDC_GOOGLE_CLIENT_SECRET=...
SWARM_OIDC_GOOGLE_HOSTED_DOMAIN=example.com   # optional: one Workspace domain

_HOSTED_DOMAIN is sent to Google as a hint and checked on the ID token's hd claim.

GitHub

GitHub is OAuth 2.0 without OpenID Connect: there is no ID token, so the leader reads the account from /user and takes only a primary, verified address from /user/emails. Create an OAuth app with the callback URL above.

SWARM_OIDC_GITHUB_CLIENT_ID=...
SWARM_OIDC_GITHUB_CLIENT_SECRET=...
SWARM_OIDC_GITHUB_ALLOWED_ORGS=example-org     # optional

An organization that restricts OAuth apps has to approve the app before its membership can be read.

Who signs in as whom

An identity is the provider's issuer and subject (iss + sub; Entra's tenant + object id; GitHub's numeric user id), kept in the user_identities table. That pair is the only thing a sign-in is matched by. On a sign-in:

  1. Linked already - the account it is linked to signs in.
  2. A local account has the same email - the identity is linked to it only when the provider verified the address and the provider has _LINK_BY_EMAIL=1. That trusts the provider with every address it vouches for, so it is off by default, and it never links to an admin account: an admin links from the profile. Otherwise the person is told to log in with the password and link the provider on the profile.
  3. No account - one is created, where registration would allow it: not under SWARM_CLOSED_REGISTRATION (except the very first account, which becomes the admin), and pending_approval under SWARM_REQUIRE_ADMIN_APPROVAL. The provider verified the email, so SWARM_REQUIRE_EMAIL_VERIFICATION does not apply. A provider that shares no verified email cannot create an account. The new account has no password: an admin's Reset password on the users page says it signs in with instead of issuing a link, and Add a password (swarm admin users reset-password --add-password) gives it one as well. Only that link sets a password on such an account: a plain reset link is refused when used.

An email the provider does not mark verified (email_verified, Entra's xms_edov, GitHub's verified) is never matched, stored or used.

Every sign-in also checks the allowlists (_ALLOWED_DOMAINS, _ALLOWED_TENANTS, _HOSTED_DOMAIN, _ALLOWED_ORGS) and _REQUIRE_MFA. A disabled or pending account does not sign in through a provider either.

Two-factor

The leader's own two-factor code applies to password sign-ins. A sign-in through a provider does not ask for it: the provider's own sign-in and its multi-factor policy apply instead, and _REQUIRE_MFA=1 makes the leader insist that the provider reports one (amr contains mfa). Not every provider puts amr in the ID token, or not by default: check one token from yours before turning this on, or nobody signs in. Linking a provider to an account therefore adds a way in that does not go through the account's TOTP - the profile says so next to the Link buttons. SWARM_REQUIRE_ADMIN_2FA still sends an admin without local two-factor to enroll before the console and admin pages open.

Linking and unlinking

On /profile, Security, Sign-in methods lists the providers linked to the account and a Link button per configured provider. Linking goes to the provider and back; the identity must not belong to another account. The last sign-in method of an account without a password - or without one it may use, under SWARM_PASSWORD_LOGIN=0 - cannot be unlinked.

Turn password sign-in off

Once everyone signs in through a provider, switch passwords off:

SWARM_PASSWORD_LOGIN=0
SWARM_PASSWORD_LOGIN_ADMINS=ops@example.com      # the break-glass admins

With SWARM_PASSWORD_LOGIN=0:

  • /login shows only the Continue with ... buttons; the password form and the Register link are gone. POST /api/v1/auth/login answers every address that may not use a password exactly as it answers a wrong password (401 Invalid email or password., after the same password hash), so the answer does not tell which addresses are listed, and these refusals do not count towards the lockout.
  • POST /api/v1/auth/register answers 403: new accounts come from a first sign-in through a provider (or from an admin).
  • Changing one's own password is refused, and the profile hides it.
  • Forgot password? is gone from the login page, and POST /api/v1/auth/forgot-password answers 404: a mailed link would set a password nobody may sign in with. /forgot-password says so and names the configured providers to sign in with instead. A break-glass admin who forgot theirs uses swarm-leader admin set-password (below). A reset link issued before the switch is refused when used (403), except a break-glass admin's. With password sign-in on, a forgot-password request for an account that has no password and signs in through a provider mails no link either, only which provider it signs in with.
  • An admin's Reset password issues no link: the answer, and the users page, say how the account signs in instead ("reason": "password_login_off"). Add user creates the account without a password and without a set-password link; it reaches the account through a provider with _LINK_BY_EMAIL=1, or links one after an admin has given it a way in.
  • swarm login, the device flow and MCP connectors need nothing: they sign in through the browser, so through the provider.

Break glass. The addresses in SWARM_PASSWORD_LOGIN_ADMINS (comma-separated) keep signing in with their password - and their two-factor code - as long as the account is an admin. They are how an operator gets in while the provider is down or misconfigured. The login page shows them an Administrator sign-in with a password button that opens the form; it shows whenever the list is set, without saying who is on it. Each such sign-in is audited as auth.login with break-glass.

Why a named list in the environment, and not a local-only path or an admin toggle in the app:

  • Only whoever runs the leader can change it. Nobody who takes over an admin session, or an IdP group that maps to _ADMIN_ROLES, can add themselves; an admin demoted in the app (or by the provider's roles) loses the exception at once, since both the list and the role are required.
  • A "from localhost only" exception would depend on the client address, which behind a reverse proxy is whatever SWARM_TRUSTED_PROXY_HOPS makes of X-Forwarded-For - every request through a proxy on the same host would look local. The leader host already has a local path that needs no HTTP at all (below).
  • The break-glass admins are ordinary accounts with a password, so they are created and repaired with the existing tools.

Make them strong: enroll two-factor for each (SWARM_REQUIRE_ADMIN_2FA=1 enforces it for every admin), keep the list short, and do not link a provider to them if the provider's _ADMIN_ROLES could demote them. At startup the leader logs a warning for each listed address that has no account, is not an admin, has no password or has no two-factor, when the list is empty, and when no provider is configured.

The last resort is the leader host, which works with no HTTP and no provider (Locked out?):

swarm-leader admin create-user ops@example.com --role admin   # a break-glass admin
swarm-leader admin set-password ops@example.com               # a forgotten one

then add the address to SWARM_PASSWORD_LOGIN_ADMINS (or set SWARM_PASSWORD_LOGIN=1) and restart the leader. A fresh leader started with SWARM_PASSWORD_LOGIN=0 gets its first admin either from the first sign-in through a provider or from create-user.

How the round trip is checked

  • state, nonce and the PKCE verifier are generated per sign-in and stored server-side for ten minutes (oidc_auth_states); the state is also put in an httponly cookie scoped to /auth/oidc. The callback needs the state in its URL to equal that cookie and name a stored sign-in for this provider, and uses it once - a callback URL from another browser signs no one in.
  • A link also needs the same signed-in account to start and finish it.
  • The ID token must be signed with an asymmetric algorithm (never none or an HMAC) by a key in the issuer's JWKS (refetched once for an unknown key id), name the leader's client id in aud (and in azp when there are several audiences), come from the discovered issuer, carry this sign-in's nonce, and not be expired (60 s of clock skew).
  • The discovery document must name the configured issuer (Entra's multi-tenant {tenantid} template is resolved from the token's tid).
  • After signing in, the browser goes back to ?next= only if it is a path on the leader.
  • A failed sign-in returns to /login?sso_error=<reason>; the provider's own message goes to the log and the audit, not to the page.

Audit

Event When
auth.sso_login A sign-in through a provider (provider=<name>).
auth.sso_linked An identity linked, from the profile or by=email.
auth.sso_unlinked An identity unlinked on the profile.
auth.sso_failed A refused sign-in or link, with the reason.
auth.sso_role _ADMIN_ROLES changed an account's role.
user.register An account created by a first sign-in (via=sso:<name>).

Deleting a user deletes the identities linked to it.

Endpoints

Route Access
GET /api/v1/auth/oidc/providers public The providers the login page shows, password_login and break_glass.
GET /auth/oidc/{name}/login?next= public Starts a sign-in: redirect to the provider.
GET /auth/oidc/{name}/callback public The provider's way back; gated by the state.
POST /api/v1/auth/oidc/{name}/link session Starts linking: {"url": ...} to send the browser to.
GET /api/v1/auth/identities session The account's identities, the providers, whether it has a password and may sign in with it (password_login).
DELETE /api/v1/auth/identities/{id} session Unlink one.

The identity routes are account security: browser sessions only, not on MCP or the CLI, like password and two-factor changes.

Not yet

SAML 2.0, providers configured on an admin page instead of the environment, per-organization providers, SCIM provisioning, and back-channel logout.