// PART 09
Authentication and authorization
Authentication answers who is calling; authorization answers what they may touch. This page follows a request through both, with the exact verification steps the server performs.
Authentication paths
| Surface | Mechanism |
|---|---|
| Suite/cloud/login (browser) | directory (Zitadel) OIDC; the login UI on port 5000 is the only domain serving login/signup — port 4000 redirects /login and /signup to it |
| REST API | Bearer token; the cloud JWT is HMAC-verified with the SaaS secret |
| Chat WebSocket | token (cookie gb-access-token, or the access_token/token query field) resolved by anonymous_auth::resolve_token_user; else the user_id query value; else a new guest (guest_<id>@anonymous.local) |
| Desktop / GB Lite | the first-run wizard’s administrator record (admin-credentials.json in the stack), checked first; sign-in via /api/auth/login |
Every WebSocket handshake logs which of the three identities it used
(WS handshake: identity=...). A socket opened before /api/auth has
answered carries empty ids and can silently run as one fixed guest — the
shell gates the connection on auth readiness for exactly this reason.
Token verification, precisely
verify_saas_jwt (the same function the SaasJwtAuthProvider uses and the
tenant resolver calls):
- requires exactly three dot-separated segments;
- requires
HS256in the header —none, a missing algorithm, and asymmetric algorithms (RS256,ES256,PS512,EdDSA) are refused; - recomputes HMAC-SHA256 over
header.payloadwith the persistedsaas_jwt_secret, compared in constant time; - requires non-empty
sub, a futureexp, and rejectsnbfmore than 60 seconds ahead.
The secret’s resolution order: the persisted saas_jwt_secret in
botserver-stack/conf/system/directory_config.json, then SAAS_JWT_SECRET,
then JWT_SECRET, then a random secret generated and persisted. Once
persisted, cloud tokens survive botserver restarts — before that fix, a
per-boot random secret invalidated every token at each restart.
Cloud login issues a token only after the directory’s sessions check
verifies the password (or the desktop admin-credentials.json fallback with a
matching password); JWT sub is the directory user id, resolved via the
sessions endpoint’s factors.user.id.
Authorization
- Roles resolve from
rbac_user_groups→ a group whose name contains “admin”. - The command catalog filters
admin_onlyentries for non-admin users and the executor enforces the same rule server-side; bot scripts gate on therolescope variable (IF role = "admin" THEN … END IF). - Route-level RBAC: every route declares a permission (metrics endpoints are
read-only
GETs requiring a Bearer token). - Tenant scoping: the verified JWT’s
branch_idclaim is the only tenant source (see Tenants and organizations).
Session lifetime
GB_SESSION_TTL_SECS sets the session lifetime used by the directory auth
routes. Refresh tokens are invalidated by a JWT-secret rotation; access tokens
expire naturally (short-lived by design). SCIM tokens fail closed: an unset or
malformed SCIM_TOKENS value yields an empty map, so every SCIM route rejects
requests until an operator provisions a token.