Admin UI single sign-on
Single sign-on lets people sign in to the Admin UI with the account they already use at work instead of a shared password. The first time someone signs in an account is created for them with a default role and budget, and they can be placed into teams from the groups the identity provider sends. When they leave the company and the identity provider disables them, they can no longer get in.
SSO works without a license for up to 5 billable users. Beyond that the gateway rejects SSO sign-ins until an enterprise license key is set, see enterprise. This page configures one identity provider for the whole gateway. To give each organization or Cloud tenant its own provider, routed by verified email domain, see organization single sign-on.
A real-world scenario
A platform team of eight shares one admin password for the gateway. Nobody knows who changed a budget last week, and when a contractor leaves the password has to be rotated and redistributed. The team connects the Admin UI to the company's Okta, so each person signs in as themselves, their changes appear under their name in the audit log, and the contractor's access ends when Okta deactivates them.
Steps
-
Register an application at your identity provider. The redirect URL to enter there is
<PROXY_BASE_URL>/sso/callback, for examplehttps://gateway.example.com/sso/callback. Note the client id and client secret it gives you. -
Sign in to the Admin UI with the existing admin login and open Settings, Admin Settings, and the SSO Settings tab. Choose Add SSO, pick the SSO Provider (Google, Microsoft, Okta, generic OIDC or SAML), enter the client id and secret or, for SAML, the IdP Metadata URL or IdP Metadata XML and the optional SP Entity ID, then the Proxy Base URL, and choose Add SSO. Proxy Admin Email is optional and only saved for your records, it does not make anyone an admin, see Making the first admin. The same settings through the API:
curl -s -X PATCH http://localhost:4000/update/sso_settings \-H "Authorization: Bearer $SPANWAY_API_KEY" -H "Content-Type: application/json" \-d '{"generic_client_id": "0oa1examplecorp","generic_client_secret": "...","generic_authorization_endpoint": "https://login.example.com/oauth2/v1/authorize","generic_token_endpoint": "https://login.example.com/oauth2/v1/token","generic_userinfo_endpoint": "https://login.example.com/oauth2/v1/userinfo","generic_scope": "openid email profile groups","proxy_base_url": "https://gateway.example.com","user_email": "admin@example.com"}'Storing the settings this way needs a database and
store_model_in_db. On a gateway without a database, set the environment variables listed below instead and restart. A laterPATCHonly changes the fields it sends, so{"team_mappings": {...}}keeps the client credentials, and a field sent asnullis cleared. For SAML sendsaml_idp_metadata_urlorsaml_idp_metadata_xml,saml_sp_entity_idandsaml_allow_unsolicitedinstead of the client fields. -
Check that nothing is missing.
curl -s http://localhost:4000/sso/readiness -H "Authorization: Bearer $SPANWAY_API_KEY" -
Sign out and open the Admin UI again. Choose the SSO sign-in button and sign in at your identity provider.
Expected result
Step 3 answers {"status": "healthy", "sso_configured": true, "provider": "generic", "message": "Generic SSO is properly configured"}. After step 4 you land in the Admin UI signed in as yourself. The person whose user id is in PROXY_ADMIN_ID is a proxy admin, everyone else gets the default role from the SSO settings, and the new users appear on the Internal Users page. The SSO Settings tab now shows the configuration with Edit SSO Settings and Delete SSO Settings buttons, and secrets are shown masked.
Settings reference
All providers need PROXY_BASE_URL, the public URL of the gateway.
export PROXY_BASE_URL="https://gateway.example.com"
Google
| Variable | Value |
|---|---|
GOOGLE_CLIENT_ID | OAuth client id from the Google Cloud console. |
GOOGLE_CLIENT_SECRET | OAuth client secret. |
Microsoft Entra ID
| Variable | Value |
|---|---|
MICROSOFT_CLIENT_ID | Application (client) id. |
MICROSOFT_CLIENT_SECRET | Client secret. |
MICROSOFT_TENANT | Directory (tenant) id. |
MICROSOFT_SERVICE_PRINCIPAL_ID | Optional. Enterprise application object id, used to read group assignments. |
MICROSOFT_AUTHORIZATION_ENDPOINT, MICROSOFT_TOKEN_ENDPOINT, MICROSOFT_USERINFO_ENDPOINT, MICROSOFT_GRAPH_ENDPOINT | Optional overrides for sovereign clouds. |
Generic OIDC
Any OpenID Connect provider works with the generic integration, including Okta, Auth0, Keycloak and Ping.
| Variable | Value |
|---|---|
GENERIC_CLIENT_ID, GENERIC_CLIENT_SECRET | Client credentials. |
GENERIC_AUTHORIZATION_ENDPOINT, GENERIC_TOKEN_ENDPOINT, GENERIC_USERINFO_ENDPOINT | Provider endpoints. |
GENERIC_SCOPE | Scopes to request, for example openid email profile groups. |
GENERIC_CLIENT_USE_PKCE | Set to true to use PKCE in the authorization code flow. |
GENERIC_USER_ID_ATTRIBUTE, GENERIC_USER_EMAIL_ATTRIBUTE, GENERIC_USER_DISPLAY_NAME_ATTRIBUTE, GENERIC_USER_FIRST_NAME_ATTRIBUTE, GENERIC_USER_LAST_NAME_ATTRIBUTE | Claims to read user fields from. |
GENERIC_USER_ROLE_ATTRIBUTE | Claim that holds the Spanway role directly. |
GENERIC_INCLUDE_CLIENT_ID, GENERIC_SSO_HEADERS, GENERIC_CLIENT_STATE | Provider specific tweaks for the token request. |
Mapping identity provider groups to roles
GENERIC_ROLE_MAPPINGS_ROLES maps Spanway roles to group names, GENERIC_ROLE_MAPPINGS_GROUP_CLAIM names the claim that lists the user's groups, and GENERIC_ROLE_MAPPINGS_DEFAULT_ROLE applies when no group matches. In the Admin UI the same mapping is Use Role Mappings in the SSO settings form, with the Group Claim, Default Role and one team list per role.
export GENERIC_ROLE_MAPPINGS_GROUP_CLAIM="groups"
export GENERIC_ROLE_MAPPINGS_ROLES="{'proxy_admin': ['platform-admins'], 'internal_user': ['engineering']}"
export GENERIC_ROLE_MAPPINGS_DEFAULT_ROLE="internal_user_viewer"
SAML
SAML 2.0 is supported with the login route /sso/saml/login, metadata at /sso/saml/metadata and the assertion consumer service at /sso/saml/callback. Configure it with SAML_IDP_METADATA_URL or SAML_IDP_METADATA_XML, SAML_SP_ENTITY_ID, the attribute names (SAML_ATTRIBUTE_EMAIL, SAML_ATTRIBUTE_USER_ID, SAML_ATTRIBUTE_ROLE, SAML_ATTRIBUTE_TEAM_IDS, SAML_ATTRIBUTE_FIRST_NAME, SAML_ATTRIBUTE_LAST_NAME), and the signing flags SAML_WANT_ASSERTIONS_SIGNED, SAML_WANT_MESSAGES_SIGNED, SAML_AUTHN_REQUESTS_SIGNED (off by default) and SAML_STRICT (on by default). In the Admin UI pick SAML SSO as the provider and fill in the same values. Allow IdP-initiated (unsolicited) responses (SAML_ALLOW_UNSOLICITED, off by default) lets people start sign-in from the identity provider's app tile. Leave it off unless they need the tile, because it also lets a forged response sign someone in to an account they did not pick. SAML_IDP_METADATA_VALIDATE_CERT (on) and SAML_SP_NAME_ID_FORMAT (email address) are covered in the settings reference.
Managing SSO from the Admin UI
SSO settings stored in the database win over environment variables, and GET /get/sso_settings reports for every field whether its value came from the database, the environment, a default, or is unset. Client secrets are masked in the answer.
| Method | Path | Summary |
|---|---|---|
| GET | /sso/readiness | Check the single sign-on setup |
| GET | /get/sso_settings | Read the Admin UI single sign-on configuration |
| PATCH | /update/sso_settings | Store the Admin UI single sign-on configuration |
GET /sso/readiness reports whether the configured Google, Microsoft or generic OIDC provider has every value it needs, which helps when sign-in fails. It does not check SAML, so a gateway that signs in only through SAML is reported as having no SSO configured. The same check runs from the Admin UI: open Settings, then Admin Settings, stay on the SSO Settings tab and click Check readiness in the SSO readiness card. A green result names the ready provider, a red one lists every missing value, and an informational one means no SSO client id is loaded yet.
Making the first admin
Set PROXY_ADMIN_ID to the user id of the person who should be a proxy admin. When that user signs in through SSO, their role is updated to proxy_admin and the change is written to the audit log. Proxy Admin Email in the SSO settings is saved for your records only and promotes nobody. ALLOWED_EMAIL_DOMAINS (comma separated) rejects sign-ins from other email domains with a 401. PROXY_LOGOUT_URL sends users to your identity provider's logout page after they sign out.
Admin UI sessions
Every sign-in path, SSO, SAML and username and password alike, ends with the gateway setting the session in an HttpOnly token cookie with SameSite=Lax, marked Secure whenever the public origin is HTTPS. It lasts SPANWAY_UI_SESSION_DURATION, 24 hours by default. Scripts in the page never see the session key. The Admin UI reads who is signed in, their role and when the session expires from GET /session/me, which only answers for a request that authenticated with the key in that same cookie. POST /session/logout revokes the session key and clears the cookie.
What each switch does
Use Role Mappings is off by default. On, every sign-in sets the person's gateway role from their identity provider groups, using Group Claim and the team lists, so access follows your directory and the role change is audited. Off keeps whatever role an admin set in the gateway. Default Role applies to anyone whose groups match no list, so choosing Proxy Admin there makes every such person a full admin. Use Team Mappings is off by default. On, sign-in adds people to the teams named in the token claim set in Team IDs JWT Field. Off leaves team membership to admins. Only a proxy admin should change these.
Keeping a fallback login
When SSO is on, the built-in username and password login (UI_USERNAME and UI_PASSWORD) still works at /fallback/login, which lets an admin get in if the identity provider is down. Set general_settings.disable_password_login_when_sso_enabled: true to remove that login. Password sign-ins, this one included, can require an authenticator app code, see two-factor sign-in.
Errors
| What you see | Why | Fix |
|---|---|---|
/sso/readiness answers 503 with "status": "unhealthy" and lists the missing variables. | The provider is only partly configured. | Set the variables it names, or fill in the matching fields on the SSO Settings tab. |
| The identity provider shows a redirect URI mismatch. | The application was registered with a different redirect URL. | Register <PROXY_BASE_URL>/sso/callback exactly, including the scheme. |
401 after signing in at the provider. | The email domain is not in ALLOWED_EMAIL_DOMAINS, or ui_access_mode is admin_only and the person is not an admin. | Add the domain, or see team membership from SSO. |
403 User is not in the restricted SSO group: <group>. | ui_access_mode is restricted_sso_group and the person's groups do not include it. | Add the person to the group at the identity provider. |
403 You must be a Spanway Enterprise user to use SSO for more than 5 users. ... | Without a license SSO allows 5 active users. Once the gateway holds more than 5, every SSO sign-in is refused, existing users included. | Set an enterprise license key, or deactivate users. |
500 Database not connected from /update/sso_settings. | The gateway has no database. | Connect a database, or set the environment variables instead. |
500 saying to set STORE_MODEL_IN_DB. | Settings cannot be stored in the database. | Set general_settings.store_model_in_db: true or STORE_MODEL_IN_DB=True. |
| Nobody is a proxy admin after SSO is on. | PROXY_ADMIN_ID is unset or names a user id the provider does not send. | Set it to the user id the provider returns, then sign in again. |
500 Invalid SAML configuration. The gateway log has the cause. | The SAML metadata or settings could not be loaded. | Read the SAML settings could not be loaded log line and fix the metadata URL or XML. |
401 Could not process SAML response. The gateway log has the cause. | The identity provider's answer failed a check, for example a signature or an unknown request. | Read the SAML response could not be processed log line. |
401 SAML authentication failed. The gateway log has the cause. | The answer was read but did not pass validation, for example it expired, was sent to another address or names another audience. The browser never sees the reason, so nobody can probe the setup from outside. | Read the SAML authentication failed log line, which names the reason. |
500 Invalid SAML service provider metadata. The gateway log has the cause. | The gateway could not build valid metadata for itself, so /sso/saml/metadata cannot be served. | Read the SAML service provider metadata is invalid log line and fix SAML_SP_ENTITY_ID or PROXY_BASE_URL. |
401 SAML assertion contained an invalid subject or email. | The assertion's email or subject is not usable. | Send a valid email in the attribute named by SAML_ATTRIBUTE_EMAIL. |
SAML SSO is not configured, or a refusal naming an unsolicited or replayed response | SAML is off, SAML_ALLOW_UNSOLICITED is off and the sign-in started at the identity provider, or a response was used twice. | Start sign-in from the gateway, or turn the setting on if people need the app tile. |
| Locked out while the identity provider is down. | SSO is the only login. | Use /fallback/login with UI_USERNAME and UI_PASSWORD, unless you disabled it. |
Logs
| Level | Line | Meaning | Action |
|---|---|---|---|
| ERROR | SAML settings could not be loaded: <reason> | SAML sign-in cannot start. | Fix the metadata URL or XML the reason names. |
| WARNING | SAML response could not be processed: <reason> or SAML assertion has an invalid subject or email: <reason> | A SAML sign-in was refused. | One now and then is a stale browser tab. Many in a row mean a certificate or attribute mismatch. |
| WARNING | SAML authentication failed: <reason> | A SAML answer failed validation. The caller only saw the fixed 401 text, the reason is here. | Check the clock, the audience and the reply address the reason names. |
| ERROR | SAML service provider metadata is invalid: <reason> | The gateway's own SAML metadata did not validate. | Fix the entity id or base URL the reason names. |
| WARNING | Continuing without code_verifier ... naming PKCE_STRICT_CACHE_MISS | A sign-in arrived on a replica that does not have its PKCE verifier. | Share Redis between replicas, then set PKCE_STRICT_CACHE_MISS=true. |
| INFO | SSO jwt_spanway_role_map matched role: <role> | A sign-in mapped the person to a role. | None. |
Audit
SSO settings changes are written as updated rows on Spanway_SSOConfig with object id sso_config, secrets masked. Delete SSO Settings saves empty values, so it also shows as updated. A promotion through PROXY_ADMIN_ID and a role change from role mappings write an updated row on Spanway_UserTable with the role before and after, changed by sso_proxy_admin_id or sso_role_map. Every successful SSO sign-in writes an invoked row on Spanway_UserTable with event sign_in, method sso, the email and the address the person signed in from, so the audit log shows who signed in and from where. See Audit logs.
Related
- Organization single sign-on gives each organization its own identity provider.
- Team membership from SSO puts users into teams from their groups.
- CLI sign-in uses the same identity provider from the terminal.
- SCIM provisioning creates and deactivates users from the directory.
- Settings reference lists every SSO environment variable with its default, including
ENABLE_SSO_DEBUG, which serves unauthenticated debug routes and must stay off on a public gateway. - Security settings for two-factor sign-in and the failed login lockout.
- Admin UI for
ui_access_modeand the other UI settings.