Authentication and authorization
Authentication
Signing in, with a password (POST /v1/auth/login) or through an identity provider, yields a pair of tokens:
| Token | Form | Lifetime | Notes |
|---|---|---|---|
| Access token | Signed JWT (HS256), audience access. | auth.access_token_ttl_s, 15 minutes by default. | Sent as Authorization: Bearer <token>. Verified without a database lookup of the token itself. |
| Refresh token | Opaque random string. Only its SHA-256 hash is stored, in Valkey. | auth.refresh_token_ttl_s, 7 days by default. | Rotated: POST /v1/auth/refresh returns a new pair. The old token then lives one more minute, during which it returns the same successor, derived from it with IDEKUBE_SECRET_KEY, so that a client that lost the answer to a reload or the network stays signed in. POST /v1/auth/logout ends the session, whichever of its tokens is presented. |
| API token | idk_ followed by 32 random bytes. Only its SHA-256 hash is stored, in PostgreSQL. | Until it expires, if it was given an expiry, or is deleted. | Sent like an access token. Acts with the permissions of its owner, narrowed to its scopes when it has any. Made by a session that confirmed who it is, or through the device flow. |
Sessions. Every sign-in starts a session; rotating the refresh token keeps it, and the access token carries its id (sid). A session records the method, address and browser, and is listed and revocable under /v1/users/me/sessions. Changing one's password ends every other session; DELETE /v1/users/{user_id}/sessions ends all sessions of an account. Ending a session deletes its refresh token: access tokens already issued keep working until they expire, at most auth.access_token_ttl_s.
Scoped tokens. An API token's scopes are of two kinds: areas (workspaces:read, workspaces:write, and so on; see API tokens) and permissions. A scoped token keeps only the permissions among its scopes (Principal.WithToken). On every request, an operation that requires a permission checks it as usual; any other is matched by its method and path to an area, and refused with insufficient_scope when the token lacks it, or when no area covers the path (Principal.MayAccessRoute). Reading variables takes the area's :write, since it returns their values. A token can never confirm who it is, so it can do nothing that asks for that, nor change its owner's password, second factors or sessions.
Device sign-in. POST /v1/auth/device stores a pending request in PostgreSQL (device_authorizations) under the digest of its device code, with a user code the person types or follows to /device. Authorizing it, from a confirmed session, makes the API token in the same transaction and keeps it sealed in the row, until the client's next poll takes it once; the row is locked while it changes, so that two replicas cannot both authorize, deny or hand it out. A request expires after 10 minutes, or 2 minutes after it was authorized or denied; every 15 minutes auth.prune_devices deletes those expired or taken.
Impersonation. A session made by POST /v1/users/{user_id}/impersonate is the account's, but its access tokens carry who acts as it in an RFC 8693 act claim (sub, name and until). It ends at until, an hour after it began: its refresh tokens and access tokens never outlive it, and every refresh checks again that the actor may still act as the account. Operations registered as api.Personal refuse such a session (impersonating), as does confirming who one is, and the audit log records the actor with every change.
On every request the user is loaded from the database and must be active, so disabling or deleting a user takes effect immediately even though the access token is still valid.
Two-step verification. A password sign-in of an account with a TOTP app or a WebAuthn key answers with a challenge instead of tokens: a ticket valid for 5 minutes and 5 attempts, completed with POST /v1/auth/mfa/verify (TOTP or recovery code) or POST /v1/auth/mfa/webauthn/options then /verify. TOTP seeds are encrypted with a key derived from IDEKUBE_SECRET_KEY, a TOTP code is accepted once, and recovery codes are stored as hashes. WebAuthn uses the host of platform.external_url as relying party, so passkeys stop working if that host changes. Holders of user:write can remove every factor of an account with DELETE /v1/users/{user_id}/mfa.
Passwords are hashed with Argon2. A login for an unknown account still verifies a hash, so the response time does not reveal whether the account exists.
Identity providers
The provider flow never puts tokens in a URL:
- The browser navigates to
GET /v1/auth/oidc/{name}/login. The API stores a state and a PKCE verifier in Valkey for 10 minutes and redirects to the provider. - The provider redirects back to
/v1/auth/oidc/{name}/callback. The API exchanges the code, reads the userinfo, applies the filter and matches the account. - The API redirects to the UI at
/login/callbackwith a single-use ticket that is valid for 60 seconds. - The UI trades the ticket for tokens with
POST /v1/auth/exchange.
Authorization
Routes ask for a permission, never a role. An operation is registered with api.Require("user:write"), which checks the caller's permissions before the input is even read. The caller's permissions are the union of what its roles grant, resolved on every request: built-in roles take theirs from the Grants of the loaded modules, custom roles from their row. Adding a role is therefore a change of data, and a new module's permissions reach the built-in roles on upgrade. super_admin holds *, which satisfies every check.
The permissions and roles are listed under Users and roles. GET /v1/users/me returns the caller's permissions, which is what the UI uses to decide what to show.
Team membership comes first for team resources. Workspace and volume routes need no platform permission: the service loads the row and asks team.Authorize, which admits
- for reading, any member of the resource's team, or a holder of the
:reador:managepermission of that kind of resource; - for changing or opening, the resource's creator if a
member, anyadminorownerof the team, or a holder of the:managepermission.
For everyone else the resource does not exist: the answer is 404. In list endpoints all=true is honoured only with the :read or :manage permission.
Nobody hands out more than they hold. An actor may assign a role, write a custom role, or manage an account only if it holds every permission involved. In a team, nobody gives a role above their own.
Workspace traffic is authorized separately, per request, by the ingress controller calling the API, with the same rule as opening a workspace. See Workspace access.