// CONTENTS Part 09 · Security

// PART 09

Authentication and authorization

Chapter 38 / 60 2 min read English Part 09 of 15

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):

  1. requires exactly three dot-separated segments;
  2. requires HS256 in the header — none, a missing algorithm, and asymmetric algorithms (RS256, ES256, PS512, EdDSA) are refused;
  3. recomputes HMAC-SHA256 over header.payload with the persisted saas_jwt_secret, compared in constant time;
  4. requires non-empty sub, a future exp, and rejects nbf more 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_only entries for non-admin users and the executor enforces the same rule server-side; bot scripts gate on the role scope 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_id claim 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.

Found a mistake? Open an issue · All books

// SEARCH ESC
Pagefind · 236 pages · 4 books Enter to open ↑ ↓ to move