Single sign-on
A team signs in to the console and the control plane with the identity provider
it already has, any OpenID Connect provider, and the provider's groups decide
the roles. Nobody has a password on the instance; people are added and removed
in one place, the provider. Single sign-on works with the password sign-in
(RUSTYBIN_CONTROL_AUTH=password, the default), where users live; the
admin token stays the break glass.
Set it up
- At the provider, create an OpenID Connect client with the authorization code
flow (a confidential client with a secret, or a public one: the instance
always uses PKCE) and register
https://<instance>/_rustybin/sso/callbackas its redirect URI. Ask for the groups in the ID token: most providers need a scope (oftengroups) or a mapper for it. - On the instance, set the
sso.*settings under Management, Sign-in, Single sign-on (they needsettings.security; the secret alsosecrets.write), or from the environment:
| Setting | Variable | Default | |
|---|---|---|---|
sso.enabled | RUSTYBIN_SSO_ENABLED | false | The "Sign in with" button on the sign-in screen |
sso.name | RUSTYBIN_SSO_NAME | the issuer's host | The button says "Sign in with <name>" |
sso.issuer | RUSTYBIN_SSO_ISSUER | The issuer URL, exactly as the provider's discovery document says it (https; http only on a loopback address) | |
sso.client_id | RUSTYBIN_SSO_CLIENT_ID | The client at the provider | |
sso.client_secret (secret) | RUSTYBIN_SSO_CLIENT_SECRET | not set | Not set: a public client (PKCE only) |
sso.scopes | RUSTYBIN_SSO_SCOPES | openid profile email | openid is always added |
sso.groups_claim | RUSTYBIN_SSO_GROUPS_CLAIM | groups | The claim with the groups; a dotted path reads a nested one (realm_access.roles) |
sso.role_map | RUSTYBIN_SSO_ROLE_MAP | empty | group=role entries, several roles separated by spaces (developers=editor tester); a person's roles are the union of their groups' |
sso.default_roles | RUSTYBIN_SSO_DEFAULT_ROLES | empty | The roles of a person in no mapped group; empty refuses them |
sso.allowed_domains | RUSTYBIN_SSO_ALLOWED_DOMAINS | empty | Only emails at these domains sign in (an email the provider says is unverified is refused); empty: any |
sso.provision | RUSTYBIN_SSO_PROVISION | true | A person becomes a user at their first sign-in; off: only users an admin added |
sso.password_sign_in | RUSTYBIN_SSO_PASSWORD_SIGN_IN | true | Off: only single sign-on and the admin token sign in (no password sign-in, no invitations) |
- Test (or
rustybin sso test, thetest_ssotool) fetches the provider's discovery document and keys now and says the redirect URI to register:
# Discovery and the keys, fetched now through the outbound policy (purpose
# sso), and the redirect URI to register at the provider.
POST {{sso_url}}/_rustybin/sso/test
Authorization: Bearer {{sso_admin_token}}
HTTP 200
[Asserts]
jsonpath "$.ok" == true
jsonpath "$.redirect_uri" == "{{sso_url}}/_rustybin/sso/callback"
jsonpath "$.discovery.issuer" == "{{base_url}}"
jsonpath "$.discovery.token_endpoint" == "{{base_url}}/oauth/token"
jsonpath "$.keys" count > 0
jsonpath "$.client_secret.set" == true
jsonpath "$.unknown_roles" count == 0
The role map takes {group, roles} objects too (an API call, rustybin.yaml); it
keeps them as group=role role strings. A role written project:role, or an object
{group, project, roles}, is a role in that project (a group that
gives roles in projects only takes no default roles; a project the instance does not
have is ignored and test lists it among the unknown roles). A group name with a comma (an LDAP DN) is
given that way rather than in the comma separated variable:
# The role map takes {group, roles} objects too (kept as group=role role).
PATCH {{sso_url}}/_rustybin/settings
Authorization: Bearer {{sso_admin_token}}
Content-Type: application/json
{ "values": { "sso.role_map": [{ "group": "admins", "roles": ["admin"] }, "users=viewer"] } }
HTTP 200
The examples on this page use Rustybin's own demo identity provider
as the provider of a second instance (alice is in the groups users and
admins, bob in users; its groups scope puts the groups in the ID token).
The sign-in
The sign-in screen asks GET /_rustybin/sso/status (open, never a secret) and
shows Sign in with <name>; with the password sign-in off, the password form
is gone:
# The sign-in screen asks (open, never a secret).
GET {{sso_url}}/_rustybin/sso/status
HTTP 200
[Asserts]
jsonpath "$.enabled" == true
jsonpath "$.ready" == true
jsonpath "$.name" == "Demo IdP"
jsonpath "$.password_sign_in" == true
The button opens GET /_rustybin/sso/start with the S256 challenge of a verifier
the console keeps in the tab. The instance sends the browser to the provider: the
authorization code flow with its own PKCE verifier, a state and a nonce:
# The console (or the CLI) starts with the S256 challenge of a verifier it
# keeps; the browser goes to the provider.
GET {{sso_url}}/_rustybin/sso/start?return_to=console&challenge=E9Melhoa2OwvFrEMTJguCHaoeK1t8URWbuGJSstw-cM
HTTP 302
[Captures]
state: header "Location" regex "[?&]state=([A-Za-z0-9_-]+)"
nonce: header "Location" regex "[?&]nonce=([A-Za-z0-9_-]+)"
code_challenge: header "Location" regex "[?&]code_challenge=([A-Za-z0-9_-]+)"
[Asserts]
header "Location" startsWith "{{base_url}}/oauth/authorize?"
header "Location" contains "response_type=code"
header "Location" contains "client_id=rustybin"
header "Location" contains "code_challenge_method=S256"
The person signs in at the provider, which sends the browser to the callback:
# The person signs in at the provider, which sends the browser to the
# instance's callback with a code.
POST {{base_url}}/oauth/authorize
[FormParams]
client_id: rustybin
redirect_uri: {{sso_url}}/_rustybin/sso/callback
response_type: code
scope: openid profile email groups
state: {{state}}
nonce: {{nonce}}
code_challenge: {{code_challenge}}
code_challenge_method: S256
username: alice
password: alice
action: approve
HTTP 303
[Captures]
callback: header "Location"
[Asserts]
header "Location" startsWith "{{sso_url}}/_rustybin/sso/callback?code="
GET /_rustybin/sso/callback exchanges the code at the token endpoint, verifies
the ID token, maps the groups to roles, links or creates the user, and sends the
browser back to the console with a one-time code (two minutes):
# The instance exchanges the code, verifies the ID token, maps the groups and
# sends the browser back to the console with a one-time code.
GET {{callback}}
HTTP 302
[Captures]
code: header "Location" regex "#/sso/(rbs_[A-Za-z0-9_-]+)"
[Asserts]
header "Location" startsWith "/ui/#/sso/rbs_"
The console trades the code and its verifier for a sign-in token, the same 12
hour token a password user gets (the session says obtained: "sso"):
# The console trades the code and its verifier for a sign-in token.
POST {{sso_url}}/_rustybin/sso/token
Content-Type: application/json
{ "code": "{{code}}", "verifier": "dBjftJeZ4CVP-mB92K27uhbUJU1p1r_wW1gFWFOEjXk" }
HTTP 200
[Captures]
alice: jsonpath "$.token"
[Asserts]
jsonpath "$.obtained" == "sso"
jsonpath "$.user" == "alice"
jsonpath "$.roles" includes "admin"
jsonpath "$.roles" includes "viewer"
jsonpath "$.token_type" == "Bearer"
GET {{sso_url}}/_rustybin/session
Authorization: Bearer {{alice}}
HTTP 200
[Asserts]
jsonpath "$.obtained" == "sso"
jsonpath "$.user" == "alice"
jsonpath "$.permissions" includes "users.manage"
What the instance checks of the ID token: the algorithm (RS256 or ES256; never
none nor a shared secret), the signature with the provider's keys, the issuer,
the audience (the client id; azp when it is there or when there are several
audiences), the expiry and iat (a minute of leeway), and the nonce of this
sign-in. The provider's tokens (access, refresh, ID) are never kept.
A refusal goes back to the sign-in screen with its reason: expired (the sign-in
took over ten minutes), denied (the provider refused), provider_error,
invalid_id_token, domain_not_allowed, email_unverified, not_linked,
disabled, no_role, last_admin,
rate_limited. not_linked stands for every refusal that is about the name: a
password user has it, another identity of the provider is linked to it, a user
added ahead has it without the verified email, or nobody has it while
sso.provision is off. The browser (and so a person choosing their name at the
provider) learns nothing about the instance's users; the detail is in the log
(rustybin::sso).
Users from single sign-on
A person the provider signs in becomes a user with source: sso and no password
(with sso.provision on; off, an admin adds them first, below). Their sign-in
name is the ID token's preferred_username, else the email, made to fit the
user name rules. From then on the provider's subject is their identity:
a later sign-in finds them whatever name the provider gives.
- Roles follow the groups at every sign-in: a group removed at the provider
demotes them at their next sign-in, and a session lasts at most 12 hours. Signing
them out everywhere (
rustybin users sessions <user> --end) applies it at once. - An admin pins roles on top of the groups' (
pinned_roles); a change of theirrolesis refused (sso_user: the provider gives those):
# An admin pins a role on top of the groups' (a PATCH of roles is refused:
# the provider's groups give those).
PATCH {{sso_url}}/_rustybin/users/{{alice_id}}
Authorization: Bearer {{sso_admin_token}}
Content-Type: application/json
{ "pinned_roles": ["tester"] }
HTTP 200
[Asserts]
jsonpath "$.pinned_roles" includes "tester"
jsonpath "$.roles" includes "tester"
jsonpath "$.roles" includes "admin"
PATCH {{sso_url}}/_rustybin/users/{{alice_id}}
Authorization: Bearer {{sso_admin_token}}
Content-Type: application/json
{ "roles": ["viewer"] }
HTTP 409
[Asserts]
jsonpath "$.reason" == "sso_user"
- No password, no invitation: an invitation, a password reset and a password
change are refused (
sso_user), and no password signs them in:
# alice is a single sign-on user: no password, no invitation.
GET {{sso_url}}/_rustybin/users/alice
Authorization: Bearer {{sso_admin_token}}
HTTP 200
[Captures]
alice_id: jsonpath "$.id"
[Asserts]
jsonpath "$.source" == "sso"
jsonpath "$.sso.issuer" == "{{base_url}}"
jsonpath "$.sso.mapped_roles" includes "admin"
POST {{sso_url}}/_rustybin/users/{{alice_id}}/invite
Authorization: Bearer {{sso_admin_token}}
HTTP 409
[Asserts]
jsonpath "$.reason" == "sso_user"
- Disabled on the instance refuses their next sign-in, whatever the provider
says. The guard rails of users apply: the provider cannot drop the
last enabled admin (the sign-in is refused with
last_admin). - An identity never takes over a password account: a provider user whose name
is a password user's is refused, and another subject of the same provider with a
linked user's name too (both
not_linked). - Added ahead (
sso.provisionoff):POST /_rustybin/userswith"sso": true(rustybin users invite <name> --sso --role viewer, theinvite_usertool withsso: true, the console's Invite with Single sign-on user) creates the user with no link; the roles given are pinned. Give the user their email: the first sign-in links them only when the provider vouches for that email (email_verified: truein the ID token; a user without an email whose name is the address counts), whatever name the provider sends. A matching name alone never links (a provider may let people choose their user name, or leave an email unverified), and a new user's name comes from the email only when it is verified. - The provider vouches for twelve hours: a sign-in token lives twelve hours, and the agent tokens of the built-in OAuth server acting for a single sign-on user (access and refresh) are refused once the person last signed in through the provider more than twelve hours ago, until they sign in again. A person removed at the provider keeps no agent past it.
Only single sign-on
sso.password_sign_in off leaves single sign-on and the admin token: POST /_rustybin/login and POST /_rustybin/join answer 403 password_sign_in_off. It
applies only while single sign-on is set up (enabled, with the issuer and the
client id), so a half-configured provider never locks everyone out; a session
signed in with a password before keeps working until it ends. Keep
RUSTYBIN_ADMIN_TOKEN set as the break glass (the diagnostics warn without one):
# Only single sign-on and the admin token: the password sign-in is refused.
PATCH {{sso_url}}/_rustybin/settings
Authorization: Bearer {{sso_admin_token}}
Content-Type: application/json
{ "values": { "sso.password_sign_in": false } }
HTTP 200
POST {{sso_url}}/_rustybin/login
Content-Type: application/json
{ "username": "rustybin", "password": "rustybin" }
HTTP 403
[Asserts]
jsonpath "$.reason" == "password_sign_in_off"
The command line and agents
rustybin login --sso --url https://<instance> listens on a loopback address of
this machine, opens the browser on the instance's start (return_to is that
loopback address, the rule the management server's OAuth sign-in applies to
native clients), takes the one-time code back and keeps the token in the profile
(--no-browser prints the address instead; --wait seconds, default 300):
rustybin login --sso --url https://mocks.example.com
rustybin whoami # obtained: sso
rustybin sso status
rustybin sso test # exits 1 when the provider cannot be read
An agent connecting to the management MCP server with OAuth asks the console for consent: the console session behind the consent is the single sign-on user's.
Security
- The network: discovery, the keys and the token endpoint go out through the
outbound policy under
the purpose
sso, whose rule permits the issuer's host once single sign-on is set up (keys or a token endpoint on another host needegress.allow). Each answer is read up to 256 KiB, in 10 seconds. Discovery and the keys are cached for an hour; a key id the cache does not know fetches the keys once more. - The flow:
state(32 random bytes, one use), thenoncechecked in the ID token, PKCE between the instance and the provider, and a second PKCE between the instance and the console (or the CLI): the one-time code works only with the verifier whose challenge started the sign-in, so a code that leaks from the address bar is useless. - Bounds: at most 256 sign-ins under way (10 per client address), each for ten minutes: a full table drops the oldest sign-in of the address with the most under way, so filling it never refuses a person's start. At most 256 one-time codes, each for two minutes. The callback and the code exchange are throttled like the password sign-in (5 failures per client address and minute, 20 from every address together in a lane of their own: failed callbacks never hold back a password sign-in).
- Discovery: under an
httpsissuer the authorization, token and keys endpoints must behttpstoo (httponly under a loopbackhttpissuer): the client secret, the code and the keys never travel in the clear. - The command line's listener answers only the callback that carries its own
random
cli_state(kept inreturn_to's query): a page that finds the port cannot endrustybin login --ssowith a forged answer, and what comes back is printed without control characters. - The client secret is a secret setting: sealed at rest, shown as
{set, hint}, never a tool input nor returned. - From git: a document from the repository never changes
an
sso.*setting (a pusher would repoint the issuer or map their group toadmin); such an entry is reported and kept as it is.
On every surface
| Surface | Where |
|---|---|
| API | The sso.* settings through GET, PATCH /_rustybin/settings; GET /_rustybin/sso/status, GET /_rustybin/sso/start, GET /_rustybin/sso/callback, POST /_rustybin/sso/token (open); POST /_rustybin/sso/test (settings.write); "sso": true on POST /_rustybin/users, pinned_roles on PATCH /_rustybin/users/{id} |
| Console | The sign-in screen's Sign in with; Management, Sign-in, Single sign-on (a form from the settings schema and Test); Management, Users and roles (the single sign-on badge, pinned roles, Invite's Single sign-on user) |
| CLI | rustybin login --sso; rustybin sso status, rustybin sso test; rustybin users invite --sso, rustybin users update --pin-role (reference) |
| Management MCP | test_sso; the sso.* settings with update_settings (confirmed; never the client secret); invite_user with sso, update_user with pinned_roles (agent page) |
rustybin.yaml | The sso.* settings under settings:, the client secret under secrets: as a reference only (${RUSTYBIN_SSO_CLIENT_SECRET}); sso: true on a users: entry (its roles are the pinned ones). Refused from a document pulled from git (instance as code) |