Introducing a new way to review your PRs.

Read the announcement

getarcaneapp / arcane

Modern Docker Management, Designed for Everyone

View on GitHub

26 documents · Updated Oct 19, 2026

docs / authentication-and-authorization-flows

Authentication and authorization flows

Arcane turns a verified user or client credential into a request identity and an effective permission set. Local passwords, OIDC, passkeys, API keys, environment tokens, and federated credentials use different entry paths, but they converge on session or access-token checks before handlers apply role and scope policy. See the parent page Identity and access for the wider identity model.

Authentication boundary

The authentication boundary accepts browser sessions and machine credentials at the API edge. It reads each operation's security requirements, identifies the caller, validates the credential against current state, and places the user, session, and permission context where downstream handlers can use them. The Huma middleware is the shared entry point for normal API operations, while the Echo middleware serves WebSocket and other Echo routes. Auth handlers expose the login, logout, refresh, and current-user contracts that begin or maintain this boundary. Request contracts and transport behavior are described in API services and API transport and webhooks.

References: backend/…/handler.go• L638-703 backend/…/handler.go• L984-1048 backend/…/handler.go• L98-248

Credential paths

Arcane supports several credential paths that represent different actors. A browser or CLI user normally uses a JWT access token, while a service or environment uses a key or token with its own scope.

Credential pathIdentity resultPermission source
Local passwordUser accountUser role assignments
OIDC authorization or device flowLinked or new user accountManual roles plus OIDC-derived roles
PasskeyUser accountUser role assignments
Personal API keyKey ownerOwner's current role assignments
Scoped API keyKey owner or linked accountGrants stored on the key
Environment access tokenSynthetic environment identityAll environment actions for that environment
Agent tokenSynthetic agent identitySudo access for infrastructure paths
Federated credential exchangeService account identityRole assigned to the federated credential

The Huma and Echo paths use the same trust order. Agent mode accepts the configured agent credential and assigns infrastructure sudo context. Manager requests first recognize environment access tokens and API keys, then use a bearer token or browser cookie. A valid environment credential creates an environment identity. An invalid user API key fails closed instead of silently falling through to bearer authentication. Public operations may still use a valid bearer token to populate caller context without making authentication required.

References: backend/…/handler.go• L662-701 backend/…/handler.go• L737-785 backend/…/handler.go• L984-1087

User session flow

The user session flow separates primary authentication from session creation. The auth service first checks the selected primary factor. It creates the session and token pair only after any required second factor succeeds.

The following diagram shows how local, OIDC, and passkey entry paths converge on one session issuer.

flowchart TD
    A[Login request] --> B{Primary factor}
    B -->|Username and password| C[Verify local user]
    B -->|OIDC callback| D[Verify provider response and reconcile user]
    B -->|Passkey assertion| E[Verify passkey]
    C --> F{Passkey MFA enabled?}
    D --> F
    E --> G[Complete login]
    F -->|Yes| H[Pending MFA transaction]
    F -->|No| G
    H --> I[Passkey or recovery code]
    I --> G
    G --> J[Persist session]
    J --> K[Issue access and refresh tokens]
    K --> L[Set browser cookie or return bearer tokens]

An access token identifies the user and session. A refresh token identifies the same session and rotates on use. A browser session token uses a separate browser-cookie path and signing contract. Each token type has its own subject and claim checks, so a browser token cannot act as a bearer access token. Each request validates the token and the persisted session, either directly or through a short-lived local verification cache. Logout, password changes, MFA changes, and administrator actions can revoke access before token expiry when they invalidate the related session or cache entries.

Local login accepts a username or an email identity. If the same value matches different accounts as a username and an email, the login fails rather than selecting one account by accident. The frontend can also request a server-managed auto-login path for deployments that enable it. The server keeps those credentials out of the browser, and a failed attempt or an MFA challenge returns the user to the normal login path.

References: backend/…/service.go• L200-345 backend/…/service.go• L658-791 backend/…/handler.go• L98-166 backend/…/handler.go• L168-248 backend/…/handler.go• L186-289

Session lifecycle

Sessions record the source of authentication and useful request facts such as the user agent and IP address. They can expire naturally or become revoked. Verified access and browser tokens may be cached within one backend process for a short time, so session and user changes must clear matching cache entries when immediate local effect is required.

Lifecycle eventResult
Successful loginNew session with access and refresh tokens
Access token expiryClient uses the refresh token to obtain a rotated pair
LogoutCurrent session is revoked and the browser token cookie is cleared
Password changeOther sessions are revoked; the current session remains active
Logout from all other devicesAll sessions except the current one are revoked
Session expiry or revocationLater token validation fails
Application version changeThe refresh path accepts the session and issues tokens for the current version

The refresh path validates the signed refresh token, checks its session and user, and rotates the refresh identifier. A token version mismatch is recoverable through refresh. Revoked or invalid sessions return an unauthorized result and clear the browser cookie. Token verification cache invalidation keeps logout, password, MFA, and user changes effective before the cache lifetime ends.

References: backend/…/service.go• L658-791 backend/…/service.go• L794-877 backend/…/handler.go• L168-248 backend/…/handler.go• L787-809

Federated access tokens

Federated access tokens provide short-lived, non-interactive access for a trusted service account. Arcane creates a dedicated federated session and records the credential that caused issuance. The token has no refresh pair and its lifetime is bounded by the service contract. The credential issuance and exchange boundary is described in Federated credentials and exchange.

References: backend/…/service.go• L968-1022 backend/…/service.go• L1071-1081

OIDC flow

OIDC lets an external identity provider authenticate the user while Arcane remains the session issuer. The flow uses the authorization-code pattern for browser and mobile clients, and a device-code pattern for CLI clients.

Authorization-code exchange

The browser flow starts with a server-generated authorization URL. The server stores state, nonce, and the code verifier in a short-lived state value. The callback must return the matching state before Arcane exchanges the code and verifies the provider's ID token. Mobile redirect URIs must match the configured allowlist exactly.

The following diagram shows the trust boundary between the client, Arcane, and the OIDC provider.

sequenceDiagram
    participant Client
    participant Arcane
    participant IdP as OIDC provider
    Client->>Arcane: Request authorization URL
    Arcane->>Arcane: Create state, nonce, and code verifier
    Arcane-->>Client: URL plus state value
    Client->>IdP: Authenticate and approve access
    IdP-->>Client: Redirect with code and state
    Client->>Arcane: Submit code and state
    Arcane->>Arcane: Validate state and expiry
    Arcane->>IdP: Exchange code with verifier
    IdP-->>Arcane: Tokens and identity claims
    Arcane->>Arcane: Verify ID token and reconcile account
    Arcane-->>Client: Arcane session tokens

Arcane can discover provider endpoints from the issuer or use explicit endpoints. It verifies the ID token against the provider's issuer, client, signing keys, and nonce. It combines ID-token claims with user-info claims only when the subject matches. A stable sub claim is required before account reconciliation.

References: backend/…/service.go• L107-158 backend/…/service.go• L169-237 backend/…/service.go• L303-416 backend/…/service.go• L418-520

Device authorization

The device flow gives a CLI a device code and a human a verification code. The CLI polls the provider through Arcane until the provider approves, delays, or rejects the request. A successful exchange verifies the returned identity and follows the same account reconciliation and session creation path as browser OIDC.

Accounts with passkey MFA cannot complete this flow because a CLI has no WebAuthn authenticator. Those users use a personal API key for non-interactive CLI access instead.

References: backend/…/service.go• L542-620 backend/…/service.go• L623-707

OIDC account and role reconciliation

OIDC identity reconciliation updates provider-owned profile data and refreshes provider tokens. On every successful OIDC login, Arcane rebuilds the user's OIDC-sourced role assignments from the configured groups claim. Manual role assignments remain unchanged.

OIDC role mappings connect an external claim value to a role and optional environment. The claim can come from the configured path in user-info data or from the ID token. A stable OIDC subject remains the account link. A verified email can permit an account merge when that setting is enabled. An unverified provider email cannot claim an existing local account.

References: backend/…/service.go• L364-423 backend/…/service.go• L511-599 backend/…/service.go• L531-570

Passkey and MFA flow

Passkeys provide discoverable WebAuthn login and can also act as a second factor for password or OIDC login. The passkey service owns the WebAuthn ceremony and pending transaction state, but the auth service remains the only component that issues JWT sessions.

Passkey login

A passkey login begins with a public challenge and finishes with a validated assertion. A successful assertion identifies the user and then calls the common session issuer. Mobile login adds a one-time verifier-bound exchange so the native client can receive the session without using a browser cookie.

Passkey login and MFA ceremonies expire and can be consumed only once. The client receives public challenge options and opaque transaction identifiers. The server keeps the ceremony data and primary authentication context.

References: backend/…/handler.go• L178-239 backend/…/handler.go• L241-289 backend/…/handler.go• L504-523

MFA challenge

When a local or OIDC account has passkey MFA enabled, primary authentication returns mfa_required instead of a session. The client submits the pending transaction with a passkey assertion or one unused recovery code. Only then does the auth service create the final session and record the MFA method.

Recovery codes are one-time values. The service stores only their digests and returns plaintext codes only when they are generated or regenerated.

References: backend/…/service.go• L265-312 backend/…/handler.go• L108-140 backend/…/handler.go• L241-289

Step-up authentication

Step-up authentication is a fresh password or passkey check for sensitive passkey management actions. A successful check creates a short-lived grant bound to the current user and session. The grant cannot be reused from another session, and passkey management requires an interactive session rather than only a machine credential.

The account cannot remove its last usable authentication method. Enabling or disabling MFA and regenerating recovery codes also require a valid step-up grant. Disabling MFA invalidates cached user authentication state.

References: backend/…/handler.go• L291-423 backend/…/handler.go• L425-470 backend/…/handler.go• L492-501

Role and permission policy

Authorization begins after authentication resolves the caller's effective permission set. A permission is a stable <resource>:<action> contract. It is either global for organization-level work or scoped to a single environment.

Global role assignments apply to organization-level endpoints and to every environment. Environment assignments apply only to their named environment. The resolver combines all assignments, then middleware checks the required permission against the request's target scope.

References: backend/…/handler.go• L812-826 backend/…/handler.go• L1099-1142

Authorization enforcement

Huma operation security metadata and middleware keep the same permission contract for normal requests and remote environment proxy requests. The middleware attaches the resolved permission set to the request context for downstream checks. A missing or failed permission lookup produces a deny-all set rather than granting access. Agent credentials receive a separate sudo set for infrastructure paths. Environment credentials receive only the permissions for their environment.

The frontend receives a backend-owned access manifest to hide unreachable routes and choose a fallback page. This is only a user-interface aid. The backend middleware and handler checks remain authoritative.

References: backend/…/handler.go• L667-703 backend/…/handler.go• L737-785 backend/…/handler.go• L812-856 backend/…/handler.go• L1042-1097

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the Huma and Echo credential precedence and fail-closed behavior aligned.
  • Keep access, browser, refresh, and federated token subjects aligned with their verification paths.
  • Preserve refresh behavior for application-version changes without treating a valid session as revoked.
  • Invalidate cached verification entries when session, password, MFA, role, or account state changes.
  • Keep OIDC state, nonce, code-verifier, subject, and mobile redirect checks consistent across authorization-code and device flows.
  • Keep OIDC group mappings separate from manual role assignments when rebuilding provider-sourced roles.
  • Keep passkey completion and MFA completion routed through the common session issuer.

Important failure modes

TriggerConsequenceGuard
Application version changes while a session remains validAccess verification returns a recoverable unauthorized resultRefresh accepts the session and rotates current-version tokens without clearing cookies
API-key permission lookup fails for a scoped keyThe request could gain the owner's broader permissions if fallback occursScoped-key failures use a deny-all permission set
OIDC callback has a bad state, nonce, subject, or expired transactionThe external identity is not acceptedState expiry, nonce checks, ID-token verification, and subject matching stop reconciliation
Provider email is not verified during account mergeAn OIDC identity could claim an existing local accountAccount merge requires provider-verified email
Passkey management uses a machine credential or omits step-up proofSensitive credential changes could bypass user presenceManagement requires an interactive session and a session-bound step-up grant
A session or role change leaves token-cache entries activeA stale request identity may remain valid for the cache lifetimeSession and user cache invalidation removes matching entries

Key files

FileWhy to read it
backend/…/handler.goShows the API edge credential order, request identity setup, session endpoints, and authorization context.
backend/…/service.goShows primary-factor separation, session issuance, refresh rotation, OIDC account reconciliation, and federated token issuance.
backend/…/helpers.goDefines the token subjects, required claims, and user-context requirement shared by verification paths.
backend/…/service.goShows provider discovery, authorization-code and device flows, claim checks, and redirect validation.
backend/…/handler.goShows passkey login, MFA completion, mobile exchange, and step-up-protected credential management.