Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Native identity backend

For operators running the native build (identity-native), which needs Hydra but no Kratos. It covers what differs from the Kratos build: building it, its required settings, sessions, throttles, mail, upstream providers and SAML. Everything both builds share is in the operator guide; the Kratos build has its own guide, Kratos identity backend.

The native build keeps identities, credentials, sessions and the self-service flows (login, registration, verification, recovery, settings, logout) in Forseti’s own database. Hydra stays: OAuth2 and OIDC work the same on both builds. The choice is made at compile time with a cargo feature, and a binary carries exactly one identity backend.

Building and running it

cargo build --release --locked --no-default-features --features identity-native
make check-native    # cargo check + clippy with the native feature
make run-native      # debug run against config.toml

--all-features does not build: the two identity features exclude each other. static/styles.css is committed, so make css is only needed after a template change.

What it replaces and what it leaves out

There is no Kratos container, no Kratos config file, no Kratos courier and no audit webhook. Forseti serves /self-service/* itself, sends verification and recovery codes through [email], and writes the flow audit rows (identity.created, auth.login, password.changed, password.recovered, verification.completed, profile.updated, mfa.*, identity.oidc.linked, identity.oidc.unlinked) directly, with the request’s IP and user agent. A password change ends the OP sessions and grants of the identity’s other browsers in-process, as the password.changed webhook does on the Ory build.

Upstream sign-in runs against the providers listed in [[identity.oidc_providers]] (see Upstream sign-in providers), and Enterprise SAML SSO works as on the Ory build (see SAML SSO).

Not available on the native build:

  • Apple sign-in and any other provider that is neither OpenID Connect nor GitHub.
  • WebAuthn security keys and passkeys. Second factors are TOTP and backup codes.
  • forseti-config: there are no Kratos or Hydra files to lint or edit.
  • Moving existing Kratos identities over. The native build is for fresh installs.

Configuration

[kratos] and [audit].webhook_token are not read. Two settings are required, and Forseti refuses to boot without them:

  • [security].cookie_secret, as key material (below).
  • [email] with enabled = true. A disabled mailer would mark every code as sent while nothing leaves the host, so new accounts could never verify.

The native settings live under [identity]; see [identity] configuration below for the native keys and their defaults. privileged_session_minutes applies to both builds and is in the operator guide.

[identity] configuration

Keys only the native build reads. unverified_ttl_days and privileged_session_minutes, which both builds read, are in the operator guide.

[identity]
session_lifespan_hours = 24
password_min_length = 8
password_breach_check = false
login_ip_rate_per_minute = 20
login_ip_rate_per_hour = 200
login_identifier_rate_per_15m = 10

[[identity.oidc_providers]]
id = "google"
kind = "oidc"
issuer = "https://accounts.google.com"
client_id = "..."
client_secret_env = "FORSETI_GOOGLE_CLIENT_SECRET"
# scopes = ["openid", "email", "profile"]
  • session_lifespan_hours: native build only. A sign-in session and its cookie end this many hours after sign-in, whether or not the session is in use. Default 24; Forseti refuses to boot with 0 or with more than 8760 (one year).
  • password_min_length: native build only. Shortest accepted password, in characters. Default 8; Forseti refuses to boot with a value below 8 or above 256, the maximum password length.
  • password_breach_check: native build only. When true, a new password is checked against the HaveIBeenPwned range API: Forseti sends the first five hex characters of the password’s SHA-1 (with the Add-Padding header) and rejects the password if the rest of the hash is in the answer. The lookup times out after 2 s and a failed lookup lets the password through. Default false.
  • login_ip_rate_per_minute, login_ip_rate_per_hour: native build only. Sign-in form submits per client IP (resolved through [proxy]); past either bucket the answer is a plain 429 with Retry-After. Defaults 20 and 200, clamped to 1000 and 10000; 0 turns a bucket off.
  • login_identifier_rate_per_15m: native build only. Password attempts per email address in 15 minutes, counted before the account is looked up, so unknown and known addresses throttle alike; past the limit the sign-in form says to try again later. Default 10, clamped to 1000; 0 turns it off. Someone who knows an address can use up its attempts and block password sign-in for that address for 15 minutes. TOTP and backup-code attempts are capped at 10 per account in 15 minutes. The counters live in each Forseti process, so several instances each allow their own share.
  • oidc_providers: native build only. Upstream sign-in providers, one [[identity.oidc_providers]] table each, at most 16; none by default. Forseti checks them at boot without contacting the providers and refuses to start on an invalid entry. What they do, the redirect URI to register and the email rules are under Upstream sign-in providers.
    • id: 1 to 64 characters of A-Z, a-z, 0-9, ., _, -, unique ignoring case. It is the last segment of the redirect URI <[self].url>/self-service/methods/oidc/callback/<id> and the value of idp_hint.
    • kind: "oidc" (OpenID Connect, discovery from issuer) or "github".
    • issuer: oidc only, required; github takes none. An https:// URL without query or fragment, compared verbatim with the discovery document’s issuer. http:// and private or loopback hosts pass only with [oauth.cimd].allow_private_targets.
    • client_id: required, non-empty.
    • client_secret or client_secret_env: exactly one. client_secret_env is the name of an environment variable holding the secret; the resolved secret must be non-empty.
    • scopes: list of scope tokens. Default ["openid", "email", "profile"] for oidc, which must include openid; ["read:user", "user:email"] for github.

On the native build every identity key is derived from [security].cookie_secret: the AES-256-GCM key that encrypts stored TOTP secrets, pending enrolment secrets and queued mail payloads, and the HMAC keys for verification and recovery codes, backup codes and logout links. Changing the secret means:

  • every enrolled authenticator stops working (the stored TOTP secrets no longer decrypt), so every TOTP user needs an admin recovery code and a fresh enrolment;
  • outstanding verification and recovery codes, backup codes and logout links stop matching;
  • queued mail no longer decrypts and is abandoned unsent.

Passwords and sessions survive: password hashes are Argon2id PHC strings and session tokens are stored as plain SHA-256 hashes. There is no rotation tooling. Back the secret up with the database, and treat losing it like losing the database.

Mail and the first admin

Mail is a hard requirement, and it shapes the bootstrap. There is no admin seeding verb on the native build: the first admin registers through /registration like anyone else, with an address listed in [admin].allowed_emails. Registration signs the new account in and shows the verification screen, but the admin surface requires a verified address and AAL2, and a later password sign-in with an unverified address is refused. So the first admin must receive the verification mail, verify, then enrol TOTP at /settings/2fa before /admin opens. Check that [email] delivers before handing out the URL.

Sessions

PropertyValue
Cookieforseti_session, or __Host-forseti_session when [self].url is https; HttpOnly, SameSite=Lax, Path=/, Secure on https, no Domain
Lifespan[identity].session_lifespan_hours (default 24), absolute: counted from sign-in, not extended by use
Privileged window[identity].privileged_session_minutes (default 15). Changing the email address, password, TOTP or backup codes, or linking or unlinking a provider, after it lapses sends the browser to a re-authentication first, with the password or a linked oidc provider; a name change does not need it
Second factorAn identity with TOTP gets AAL2 only after a TOTP or backup code; until then pages that need a session send it to the step-up. Stepping up moves the session to a new token

The session token is 32 random bytes; the database keeps its SHA-256 hash. Each session records its AAL, the methods used with their times, and the client IP (resolved through [proxy]) and user agent seen at sign-in. Revoking a session at /settings/sessions or /admin/sessions takes effect on the next request.

Throttles

Per-IP limits answer with a plain 429 and Retry-After; per-address and per-account limits answer on the form with “Too many sign-in attempts right now” (message 9000001), except the code-guess limit, which answers like a wrong code. All counters live in the Forseti process, so several instances each allow their own share.

WhatLimit
Sign-in submits per client IPlogin_ip_rate_per_minute / login_ip_rate_per_hour (20 / 200)
Password attempts per email addresslogin_identifier_rate_per_15m (10 per 15 minutes), counted before the account is looked up
TOTP and backup-code attempts per account10 per 15 minutes
Registration init and submits per client IP, and globallythe [auth].registration_* values; a provider sign-up with a provider-verified address spends the submit buckets
Flow starts (/self-service/{login,recovery,verification,settings}/browser) per client IP60 per minute, 600 per hour
Provider callbacks (/self-service/methods/oidc/callback/<id>) per client IP60 per minute, 600 per hour, a bucket of its own
Verification and recovery submits per client IP, shared5 per minute, 30 per hour
Codes mailed per address, verification and recovery together5 per hour
Guesses per code5; a code lives 15 minutes
Code guesses per address, across every code mailed to it (verification, recovery, address change, provider sign-up)15 per hour; a refused guess gets the wrong-code answer
Settings submits per client IP30 per minute, 300 per hour
Email address and password changes per account10 per 15 minutes, shared

The per-address password limit is the lockout trade-off: anyone who knows an address can spend its attempts and keep its owner out of password sign-in for 15 minutes, whether or not they know the password. Raising login_identifier_rate_per_15m loosens that and gives a password guesser more room; 0 turns it off and leaves only the per-IP buckets.

The per-address code-guess limit has the same property: anyone who can start a verification, recovery or provider sign-up flow for an address can spend its guesses, and the owner’s mailed codes for that address fail until guesses fall out of the one-hour window. Someone who keeps spending them keeps the address locked; an admin recovery code is not counted against this limit and still works.

Background workers and /readyz

Two workers run next to the webhook worker and stop with it on shutdown:

  • Mail: drains identity_mail_outbox every 5 seconds and right after a code is queued, up to 32 rows per pass. A failed send is retried after 10 seconds, doubling to at most 5 minutes; a row is abandoned after 10 attempts, or unsent once its code (15 minutes) has expired. A sent or abandoned row keeps no payload. /readyz reports ready (degraded: mail worker stale, ...) when the worker has been silent for more than 20 seconds.
  • Maintenance: a minute after boot and then hourly, deletes sessions revoked or expired more than 30 days ago, flows expired more than a day ago (their codes go with them), and sent or abandoned mail rows queued more than 30 days ago.

/admin/status shows the backend as “Identity (built in, alive)” and “Identity (built in, ready)” (ready runs a database query), the courier queue counts from the outbox (queued and abandoned rows), and no Kratos webhook cards. The build row labelled “Kratos” shows native <version>.

Tables

The native backend owns seven tables in Forseti’s database: identities, identity_credentials (password, TOTP and backup codes per identity), identity_oidc_links (provider links: provider id, provider subject and link date; no upstream tokens), identity_sessions, identity_flows, identity_codes and identity_mail_outbox. The migrations create them on both builds, so the schema does not depend on the build; they stay empty on the Ory build. Deleting an identity removes its credentials, provider links, sessions, codes, mail rows and the flows tied to it. Back them up with the rest of Forseti’s database (see Backups).

Admin recovery codes

On /admin/identities/{id}, an admin can mint a recovery code (POST /admin/identities/{id}/recovery). On the native build this creates a recovery flow that no browser holds yet and a 6-digit code for it; nothing is mailed, and the identity’s earlier recovery codes stop working. A disabled identity gets no code: enable it first. The admin hands over the link (<self>/self-service/recovery?flow=<id>) and the code out of band. Opening the link takes nothing, so a chat preview or mail scanner that fetches it leaves it usable, and the page shows no account data. The first browser to submit on the page takes the flow; any other browser gets the expired-flow page. Entering the code (5 guesses, 15 minutes; the per-address code-guess limit does not apply) signs the user in at AAL1 and opens the password page within the privileged window. An identity with TOTP still steps up before settings open, with TOTP or a backup code, so a recovery code does not get a user past a lost authenticator without backup codes.

Upstream sign-in providers

Each [[identity.oidc_providers]] entry (keys under [identity] configuration) puts a provider button on the sign-in page and on both registration steps, and a Link button on /settings/linked-providers. The label and mark come from the id: google, github, microsoft and apple get their brand name and mark, gitlab and facebook their name, any other id is shown with its first letter capitalised. Every id is accepted as idp_hint and listed in discovery’s idp_hints_supported (see the integration guide).

  • kind = "oidc": OpenID Connect against <issuer>/.well-known/openid-configuration. Authorization code flow with PKCE (S256) and a nonce; Forseti authenticates at the token endpoint with client_secret_basic, or client_secret_post when the discovery document lists methods without client_secret_basic. The document’s issuer must equal the configured value byte for byte; its endpoints may sit on other hosts (Google’s token and key endpoints do), each passing the same outbound checks as the issuer. When the document lists code_challenge_methods_supported, it must include S256. ID tokens must be signed RS256 or ES256. Google, Microsoft Entra, Keycloak and another Forseti all fit.
  • kind = "github": GitHub’s OAuth app flow. There is no ID token: Forseti reads https://api.github.com/user and /user/emails with the access token and drops the token afterwards. The account’s subject is the numeric GitHub user id.

Register this redirect URI at the provider, with [self].url as the origin users reach Forseti on:

<[self].url>/self-service/methods/oidc/callback/<id>

It is the path Kratos uses, so an install moving from the Ory build re-registers only if the host changes. Give the client secret as client_secret or, to keep it out of the file, as client_secret_env naming an environment variable. Forseti stores no upstream tokens, only the provider id, the provider’s subject for the account and the link date.

GitHub OAuth app. Under GitHub’s Developer settings, OAuth Apps, set the Authorization callback URL to <[self].url>/self-service/methods/oidc/callback/github (the last segment is the configured id), then copy the client id and a generated client secret into the entry. The default scopes are read:user user:email; user:email is what lets Forseti read the address list. Forseti takes the address GitHub marks both primary and verified; an account whose primary address is unverified signs up through the email-needed path below. The name splits at the first space into first and last name.

What an upstream address is worth. When the provider asserts the address verified (an ID token with email_verified: true, or GitHub’s primary verified address), a sign-up through that provider stores it verified and sends no mail. This holds for every configured provider, so configure only providers whose verification you trust. Microsoft Entra sends no email_verified, so its users always take the email-needed path. Without a verified address, the registration page asks for one: Forseti mails a code to it, and the account, its provider link and the session are created only when that code is entered in the browser that started the sign-up. An address that already has an account is refused with “An account with the same identifier (email, phone, username, …) exists already.” when it is typed, as password registration refuses it. An address on [admin].allowed_emails gets the same message when its code is entered, or right away when the provider asserted it verified; no account is created for it either way. Addresses over 254 characters, or ones a mail provider could read as another recipient, count as absent.

No automatic linking. A provider sign-in whose address belongs to an existing account does not sign in to that account: the user sees the registration page with the “account exists” message, signs in with what they have, and links the provider under Settings, Linked providers. A provider sign-up never creates an account for an address on [admin].allowed_emails; an admin registers with a password and links the provider afterwards. A provider account links to one Forseti account at most, and an account links to each provider once.

Linking and unlinking. Both need the privileged window; past it the browser goes to the re-authentication page first. An account whose address was never verified cannot link a provider (see below). Unlink is offered, and accepted, only while the account keeps another way to sign in: a password, or a link to another configured provider.

A provider id is permanent for its issuer. Links are stored by (id, subject). Pointing an existing id at another issuer or switching its kind hands every existing link to whichever account of the new provider carries the same subject. Add a new entry with a new id instead. Removing an entry leaves its links in the database: nobody can sign in through them, they show on the linked-providers page without an Unlink button, and they no longer count as a way to sign in when another provider is unlinked.

Sessions and re-authentication. A provider sign-in issues an AAL1 session (method oidc, with the provider id); an account with TOTP still steps up with its second factor. The re-authentication page (/login?refresh=true) offers the password and every configured oidc provider linked to the account. Those providers are sent max_age=0 and must return an auth_time claim no earlier than the moment the user was sent to the provider and no later than the callback, each with 60 seconds of clock skew, or the attempt is refused. GitHub is not accepted for re-authentication: it has no way to ask for a fresh login and reports no login time. A GitHub-only account signs out and in again to reopen the privileged window, and should set a password to pass an OAuth client’s prompt=login.

CSP. form-action carries each configured provider’s issuer origin (https://github.com for github) on the pages that show its button, so no [security].extra_form_action entry is needed. A provider whose authorization endpoint is on another host than its issuer does need one, with that endpoint’s origin.

When a provider is down. Forseti fetches the discovery document on first use and keeps it for an hour, and the key set for 10 minutes; an ID token signed with an unknown key triggers one early key refresh, at most once a minute. A failed refresh keeps serving the last copy and tries again after 60 seconds. Each request to a provider times out after 5 seconds. With nothing cached and the provider unreachable, the button leaves the user on the page with “Signing in with the provider did not work. Please try again.” (message 9000002); the same message covers a provider error, a refused code exchange and an invalid ID token on the way back, each with an auth.login_failed audit row.

Audit. identity.created and auth.login carry method: oidc and the provider id; identity.oidc.linked and identity.oidc.unlinked record settings changes. The provider callback has its own per-IP limit (60 per minute, 600 per hour). A sign-up through a provider with a provider-verified address also spends the [auth].registration_* per-IP and global buckets of POST /self-service/registration; over them nothing is created and the browser gets the plain 429. A sign-in to an existing account is not counted there, and the email-needed path is counted when its address is submitted.

Addresses that were never verified

An account counts as never verified until a code mailed to its address has been entered once (verification, recovery or an address change), unless it was created verified (a provider sign-up with a provider-verified address, a SAML just-in-time account). An address change does not reset that state. Three rules hang off it, so that someone who registered an address they do not own keeps nothing once the owner proves it:

  • Recovery by mailed code resets the account. Before the recovering user gets a session, Forseti revokes the account’s sessions, deletes its password, TOTP, backup codes, provider links and offline passphrase, drops its outstanding codes and pending address changes, and ends its OAuth sessions and grants at Hydra. The user then sets a new password on the recovery handoff page. The password.recovered audit row carries unverified_reset: true and the counts of what went. Organization memberships, profile fields and resource claims stay. A recovery code an admin minted proves no mailbox and resets nothing.
  • No second factor or provider link before verification. Enrolling TOTP, generating backup codes and linking a provider are refused with “Account not active yet. Did you forget to verify your email address?” (message 4000010).
  • An email change stays pending until proven. The account keeps its current address, verified mark and sign-in until the code mailed to the new address is entered, from a browser signed in to that account: a signed-out browser is sent to sign in first, an account with TOTP to its second factor, then back to the code page. A newer change request replaces the pending one. The audit rows are profile.updated with address_change: requested, then verification.completed with address_change: applied.

SAML SSO

With [saml] configured and a license with the saml feature, /sso/* and /admin/saml work as on the Ory build; see Enterprise SAML SSO. The session is issued directly: an AAL1 session with method saml and no amr claim in ID tokens, with no Kratos recovery link involved, so none of the Kratos link method setup applies. A disabled account, or one whose address was never verified, gets no session. [saml].identity_schema_id is not read. When the assertion names an existing account, the confirm step goes through the re-authentication page, with the account’s password or a linked oidc provider.