# Single sign-on

> Let people sign in with the accounts your identity provider manages (Keycloak, Entra ID, Authentik, Okta or any OpenID Connect provider), by hand or from the deployment's environment.

## What single sign-on does

With single sign-on, people sign in to the control plane with the account they already have at your identity provider. The identity provider checks the password, the second factor and any other policy; the control plane never sees the password. The control plane works with any identity provider that speaks OpenID Connect: Keycloak, Microsoft Entra ID, Authentik, Zitadel, Okta, Google Workspace, Dex and others.

Password sign-in stays. The first administrator is always a local account with a password, created when the control plane is set up, and local administrators keep the way back in when the identity provider cannot be reached.

## What you need first

- **HTTPS.** Single sign-on works only when the control plane is reached over HTTPS and the identity provider's address starts with `https://`. Over plain HTTP anyone on the network could read the sign-in codes and the session cookie, and most identity providers refuse a plain HTTP redirect address anyway. Put HTTPS in front of the control plane and set `SECURE_COOKIES=true` for it.
- **A client at your identity provider.** Register the control plane as a confidential OpenID Connect client (also called a web application or an app registration) that uses the authorization code flow. You need three values from it: the **issuer URL**, the **client ID** and the **client secret**.
- **The redirect URI.** Configuration → Access → Sign-in shows it, with a copy button. It is the control plane's address followed by `/api/auth/oidc/callback`, for example `https://control-plane.example.com/api/auth/oidc/callback`. It is built from the address in your browser, so open the control plane at the address people use before you copy it. Register exactly this at the identity provider, one for each address people use.
- **The sign-out address.** Register the control plane's address followed by `/signed-out` as an allowed address after sign-out (Keycloak: **Valid post logout redirect URIs**), so signing out ends the identity provider's session too.

## Setting it up on the Configuration page

1. Open **Configuration → Access → Sign-in**.
2. Enter the **issuer URL**, the **client ID** and the **client secret**. The client secret is stored encrypted and never shown again; the card says only whether one is stored.
3. Optionally enter the **name on the sign-in button** (for example "Company login"), the **role groups** and the **allowed group** (see below).
4. Click **Test connection**. It tests what you typed, before you save it. The control plane fetches the identity provider's discovery document and signing keys, checks that the issuer it states is the one you entered, and says whether sign-in asks for the `groups` scope (see below). The test cannot check the client secret; the first real sign-in does.
5. Under **Login methods**, tick **Single sign-on**, and click **Save single sign-on settings**. Switching single sign-on on runs the connection test again, and nothing is saved when it fails.

Then open the login page in another browser and click **Sign in with** *your provider*. The first sign-in creates the person's account; they appear under **Configuration → Access → Users** from then on.

## Who may sign in, and what they may do

The identity provider decides both, through groups:

- **Allowed group:** when set, only its members may sign in. Everyone else is refused with a message telling them to ask their administrator. When empty, everyone the identity provider signs in may sign in.
- **Role groups:** the **administrator group**, the **operator group** and the **viewer group**. A member of one holds that role in the control plane; a member of several holds each of them. An administrator can do everything; an operator deploys, scales and restarts models; a viewer reads everything and changes nothing (Configuration → Access → Users lists every role with what it allows).
- With none of the three groups set, everyone who signs in is an operator. With any of them set, someone in none of them is a viewer: nobody gets more than reading by default.
- The groups are read at every sign-in, so moving someone between groups at the identity provider changes their role at their next sign-in. A single sign-on account's roles are the identity provider's: they are not changed under Users.

The group names are read from the ID token's `groups` claim; change the **groups claim** if your identity provider uses another name. Sign-in asks the identity provider for the `groups` scope, which some identity providers need before they send the groups. It leaves the scope out when the identity provider lists the scopes it offers and `groups` is not among them, because an identity provider such as Keycloak refuses a scope it does not know. The groups must then come from the identity provider's own configuration, and **Test connection** warns about it when role groups or the allowed group are set. The username comes from the `preferred_username` claim, or from the email address when that claim is missing; change the **username claim** if yours differs.

## Login methods

The login methods are the ways people may sign in: **Password**, **Single sign-on**, or both. At least one stays on.

| Login methods | `LOGIN_METHODS` | Password sign-in | Single sign-on |
|---|---|---|---|
| Password | `local` | yes | no |
| Password and single sign-on | `local,oidc` | yes | yes |
| Single sign-on only | `oidc` | no | yes |

**Single sign-on only** is for a control plane whose users know only the identity provider. Nobody sees the control plane's own sign-in page: a browser without a session goes straight to the identity provider's sign-in, and comes back to the page it asked for. There is no first-administrator setup either: members of the **administrator group** are administrators, so the group must be set, and the first member who signs in manages the control plane. When something is wrong, the page shows the reason and a **Try again** button instead of redirecting again. The way back in when nobody can sign in is a command on the machine; see **Getting back in**.

Switching single sign-on **off** stops every single sign-on account at once, in the browser and for its control plane API keys, until you switch it on again. The Configuration page names how many accounts and keys that is and asks you to confirm. Switching it back on lets them work again; nothing is lost.

Replacing the identity provider (a different issuer URL) has the same effect on the accounts of the old one: they stop working, and people sign in again through the new one, which creates new accounts.

## How long people stay signed in

**Configuration → Sign-in → Stay signed in for** sets how long a browser session lasts after its sign-in, from 5 minutes to 30 days; empty means 24 hours. It counts from the sign-in, not from the last click. Shortening it signs out every session that is older than the new length, on its next request. A deployment can set it with `SESSION_MAX_AGE` (in seconds) instead; the field then shows that value read-only.

## Managing your account

People who sign in with single sign-on manage their account (password, two-factor sign-in, profile) at the identity provider, not here. Enter where they do that as the **account management URL** under **Configuration → Access → Sign-in** (for Keycloak, `https://<keycloak>/realms/<realm>/account`), or set `OIDC_ACCOUNT_URL` in the deployment. Everyone signed in with single sign-on then finds **Account** in their user menu, above **Logout**; it opens that address in a new tab. People who sign in with a password manage their account here, so they get no such item. Without an account management URL, nobody does.

## Signing out

Signing out ends the session in the control plane. When the identity provider offers a sign-out address (Keycloak, Entra ID, Authentik and Okta do), the browser goes there too, so the identity provider's session ends as well, and comes back to a page that says you are signed out. That page never signs you in again by itself.

When the identity provider offers no sign-out address, only the control plane's session ends. In single-sign-on-only mode, the next sign-in then needs no password at the identity provider while its own session lasts.

## When someone leaves

Removing a person at the identity provider stops their next sign-in. It does not end a browser session they already have (it lasts until its session length is over, 24 hours by default) and it does not stop their control plane API keys until they expire (30 days by default). To stop everything at once, open **Configuration → Access → Users** and **Deactivate** the account.

## Provisioning from the deployment

Automated installations can set single sign-on in the control plane's environment instead of on the Configuration page. The values the deployment sets win on every start, and the Configuration page shows them read-only with where they come from.

| Variable | What it sets |
|---|---|
| `OIDC_ISSUER_URL` | The issuer URL. Setting it makes every identity provider setting come from these variables |
| `OIDC_CLIENT_ID` | The client ID (required with `OIDC_ISSUER_URL`) |
| `OIDC_CLIENT_SECRET_FILE` | A file holding the client secret, like the control plane's other secrets (required with `OIDC_ISSUER_URL`) |
| `OIDC_DISPLAY_NAME` | The name on the sign-in button |
| `OIDC_ADMINISTRATOR_GROUP` | The administrator group |
| `OIDC_OPERATOR_GROUP` | The operator group |
| `OIDC_VIEWER_GROUP` | The viewer group |
| `OIDC_ALLOWED_GROUP` | The allowed group |
| `OIDC_GROUPS_CLAIM` | The groups claim, default `groups` |
| `OIDC_USERNAME_CLAIM` | The username claim, default `preferred_username` |
| `OIDC_ACCOUNT_URL` | The account management URL (see **Managing your account**) |
| `LOGIN_METHODS` | `local`, `oidc`, or `local,oidc`; set on its own, independently of the rest |
| `AUTH_FORCE_LOCAL_LOGIN` | `true` turns password sign-in back on for every local account (see below) |
| `SESSION_MAX_AGE` | How long a browser session lasts, in seconds (300 to 2592000); overrides **Stay signed in for** |

A variable set to an empty value counts as not set. A deployment that sets `OIDC_ISSUER_URL` without a client ID, names a secret file that cannot be read, sets `LOGIN_METHODS` to an empty or unknown value, sets `LOGIN_METHODS=oidc` without `OIDC_ADMINISTRATOR_GROUP`, sets an `OIDC_ACCOUNT_URL` that is not an absolute `http://` or `https://` address, or includes `oidc` without `SECURE_COOKIES=true` does not start, and the control plane's log names every problem.

A machine that people reach only through the identity provider sets, for example:

```
LOGIN_METHODS=oidc
OIDC_ISSUER_URL=https://login.example.com/realms/company
OIDC_CLIENT_ID=onprem-ai
OIDC_CLIENT_SECRET_FILE=/run/secrets/oidc_client_secret
OIDC_ADMINISTRATOR_GROUP=onprem-ai-admins
OIDC_OPERATOR_GROUP=onprem-ai-operators
OIDC_VIEWER_GROUP=onprem-ai-viewers
OIDC_DISPLAY_NAME=Company login
OIDC_ACCOUNT_URL=https://login.example.com/realms/company/account
SECURE_COOKIES=true
```

Two files are all it takes:

- **`/etc/onprem-ai/control-plane/config.env`**: add the variables above, with `OIDC_CLIENT_SECRET_FILE=/run/secrets/oidc_client_secret` exactly as shown.
- **`/var/lib/onprem-ai/control-plane/secrets/oidc_client_secret`**: write the client secret into it. The installer created this file empty, owned by the control plane's user (1000) with mode 0400, and the control plane mounts it on its own, so it keeps that owner and mode:

```sh
cd /var/lib/onprem-ai/control-plane
printf '%s' '<client-secret>' > secrets/oidc_client_secret.tmp
chown 1000:1000 secrets/oidc_client_secret.tmp && chmod 0400 secrets/oidc_client_secret.tmp
mv secrets/oidc_client_secret.tmp secrets/oidc_client_secret
```

Then run `sudo onprem-ai-ctl apply` to apply them. While the file is still empty, a control plane whose config file names it does not start, and its log says to write the client secret into it.

Every instance of the control plane must receive the same values.

## Getting back in

If the identity provider is unreachable or misconfigured and password sign-in is a login method, sign in with a local administrator's password.

When nobody can sign in (single sign-on only, or every administrator password is lost), use the recovery command on the control plane's machine, over SSH, as root:

```
sudo onprem-ai-ctl recovery show-sign-in
sudo onprem-ai-ctl recovery sign-in-link --username NAME
sudo onprem-ai-ctl recovery sign-in-link --create-administrator NAME
```

A control plane installed before release 4.5.0 has no `onprem-ai-ctl`. In the control plane's folder, run `docker compose exec backend python -m control_plane.recovery --help` and use the commands it lists.

- `show-sign-in` shows the sign-in settings in effect, where each one comes from, and the administrators.
- `sign-in-link` prints a recovery link for the account you name. It works one time, for 15 minutes. For an account with a password while password sign-in is on, the link opens a page where you set a new password, and you then sign in with it. For a single sign-on account, or when password sign-in is off, the link signs you in once, with no identity provider and no password. Add `--control-plane-admin-address HOST:PORT` (the address you open the control plane on, for example `192.168.0.250:3443`) to get the whole link; without it, put the printed part after the address.
- `--create-administrator NAME` first creates a new local administrator without a password. Use it when no administrator account exists that you can use.

The audit trail records every link the command makes, and every password set or sign-in with one. Signed in, correct the settings under **Configuration → Access → Sign-in**; when the deployment sets them, change the environment and restart the control plane.

`AUTH_FORCE_LOCAL_LOGIN=true` in the deployment is a second way: after a restart, every local account can sign in with its password again, whatever the login methods say, and single sign-on keeps working. Remove it once you are back in.

## Setting up common identity providers

### Keycloak

**Signing in with Keycloak** has every step in order, tested against Keycloak 26.4 and 26.8. In short:

1. In your realm, **Clients → Create client**: type OpenID Connect, a client ID of your choice.
2. Turn **Client authentication** on, keep **Standard flow** on.
3. **Valid redirect URIs:** the redirect URI from the Configuration page. **Valid post logout redirect URIs:** the control plane's address followed by `/signed-out`.
4. **Credentials** tab: copy the client secret.
5. For groups, add a **Group Membership** mapper to the client's dedicated scope: token claim name `groups`, **Full group path** off, **Add to ID token** on.
6. The issuer URL is `https://<keycloak>/realms/<realm>`.

### Better Auth

**Signing in with Better Auth** has every step in order, tested against Better Auth 1.7.7. In short:

1. Add the `jwt` and `oauthProvider` plugins. List `groups` in `scopes` and `scopes_supported`, and put `preferred_username`, `email` and `groups` into the ID token with `customIdTokenClaims`: Better Auth has no groups of its own.
2. Create a confidential client with `adminCreateOAuthClient`: the redirect URI from the Configuration page, `post_logout_redirect_uris` with the control plane's address followed by `/signed-out`, `enable_end_session: true`, `skip_consent: true`, `token_endpoint_auth_method: "client_secret_basic"`.
3. The issuer URL is Better Auth's `baseURL` followed by its `basePath`, for example `https://login.example.com/api/auth`.

### Microsoft Entra ID

1. **App registrations → New registration**, platform **Web**, redirect URI from the Configuration page.
2. **Certificates & secrets → New client secret**: copy its value.
3. **Token configuration → Add groups claim** (security groups). Entra ID sends group object IDs, not names: enter the group's **object ID** as the administrator or allowed group.
4. The issuer URL is `https://login.microsoftonline.com/<tenant-id>/v2.0`.
5. Entra ID's `preferred_username` is the user principal name (usually the email address); it becomes the username here.

### authentik

**Signing in with authentik** has every step in order, tested against authentik 2026.8. In short:

1. A provider (**OAuth2/OpenID Provider**, client type **Confidential**) with **Authorization Code** among its grant types, the redirect URI and the `/signed-out` address as its redirect URIs, `default-invalidation-flow` as its invalidation flow, the `openid`, `email` and `profile` scopes, and **Include claims in id_token** on.
2. An **Application** that uses the provider.
3. authentik offers no `groups` scope: the groups arrive in the `profile` scope's `groups` claim.
4. The issuer URL is `https://<authentik>/application/o/<application-slug>/`, with the trailing slash.
5. Reached by a plain IP address, authentik presents its self-signed certificate; put a reverse proxy with your certificate in front of it.

### Zitadel

**Signing in with Zitadel** has every step in order, tested against Zitadel 4.19. In short:

1. A project with one role per control plane role, and a **Web** application with **Code** and a client secret, the redirect URI, and `/signed-out` as its **Post Logout URI**.
2. **Include user's profile info in the ID Token** on.
3. Zitadel sends roles as an object in `urn:zitadel:iam:org:project:roles`; an action on the **Complement Token** flow (**Pre Userinfo creation**) writes the role keys into a `groups` claim, the list the control plane reads.
4. The issuer URL is Zitadel's external address, `https://<zitadel>`, without a trailing slash.

## What the sign-in errors mean

A failed single sign-on returns to the login page with the reason. The ones an administrator fixes:

- **could not reach** *the identity provider*: the issuer URL is wrong, or the control plane cannot reach it (network, DNS), or its certificate comes from your own certificate authority, which is not yet in the folder `/etc/onprem-ai/trusted-certificate-authorities/` on the control plane's machine (**Trusting your own certificate authority**); copy it there, then run `sudo onprem-ai-ctl restart`.
- **refused the sign-in request**: the client ID or client secret is wrong, or the redirect URI is not registered exactly as the Configuration page shows it.
- **could not be verified**: the issuer URL differs from what the identity provider states (the connection test names both), or a clock on one of the machines is wrong.
- **did not say who you are**: the identity provider releases neither the username claim nor the email address to this client.
- **already has your username**: a local account has the same username. Accounts are never merged: rename the local account, or change the username at the identity provider.

When the login page says a defect happened and names an error report, the failure is the control plane's, not your configuration's: send the error report to support.
