Guides

SSO, RBAC & Audit Log

Every licensed deployment includes single sign-on (SAML 2.0 and OIDC), a four-role RBAC model (viewer < member < admin < owner), and an auth audit log with ordinary append writes and scheduled retention. All three ship inside the web container's auth layer — self-hosted, no external identity service of ours in the path. This guide covers the environment-variable surface that turns them on and the security invariants that hold once they are.

What ships, and where

SSO, RBAC, and the audit log live in the ghost-web container — the same control-plane process that serves the dashboard and the /v1/* API. There is no separate auth service to deploy and no callback to a Gostly-hosted endpoint: the SAML SP and the OIDC client run in your own stack and talk only to your identity provider. Multi-user role management and the team activity surface are gated behind the multi_user_workspace and team_activity features (Team tier).

SSO

SAML 2.0 and OIDC auth-code flow, selected per deployment via GOSTLY_AUTH_MODE. Password auth stays available unless you disable it.

RBAC

Four ranked roles with operation-specific role floors and mock content visibility. IdP group claims map to roles; owner is never granted by a group.

Audit log

An auth_audit_events table records authentication and user-management events. Ordinary auth writers append; scheduled retention can remove old events. Access reductions can commit before best-effort audit delivery.

Single-tenant deployment

Each licensed deployment has one workspace identity. Application queries are tenant-scoped, and Postgres enforces RLS beneath them: request handlers use the non-owner gostly_app role with no RLS bypass, transaction-bound tenant context and FORCE ROW LEVEL SECURITY on covered tables. Cross-tenant maintenance has a separate privileged role. See the security model for the full posture.

Selecting auth methods

The set of enabled login methods is a comma-separated list in GOSTLY_AUTH_MODE. The default is password, which preserves the local-admin login. Adding saml or oidc enables that backend alongside the password form; listing only an SSO method hides the password form entirely.

# Password only (default)
GOSTLY_AUTH_MODE=password

# Password form + an SSO button on the login page
GOSTLY_AUTH_MODE=password,saml

# SSO only — the password form is hidden in the dashboard
GOSTLY_AUTH_MODE=oidc

The dashboard's login page renders itself from GET /v1/auth/methods, which returns the enabled backends (and their display names) with no secrets. Start with password sign-in enabled and bootstrap the local administrator using GOSTLY_ADMIN_EMAIL and GOSTLY_ADMIN_PASSWORD. Enable the intended SSO method alongside password, then sign in through SSO as an active owner or admin before removing password.

Startup refuses an operator change of sign-in methods that would remove the last available administrator sign-in. If the last active SSO administrator binding is later lost under methods the API already runs with, the API continues serving and can restart in that degraded state. /health reports admin_sign_in.status: no_admin_can_sign_in, and doctor and Settings identify the recovery. Identity-provider availability is reported separately on Settings → Sign-in; a local administrator binding alone does not prove a working IdP login.

Sessions, not bearer tokens for the dashboard

On success any IdP mints a server-side session: a 256-bit random token is set as the gostly_session cookie (HttpOnly, Secure, SameSite=Lax), and the server stores only its SHA-256 hash. A database leak yields no usable session credentials. Session TTL is GOSTLY_AUTH_SESSION_TTL_HOURS (default 12). Control-plane routes accept sessions or keys according to their credential policy, then apply role and scope checks. For routes accepting either method, a valid login session takes precedence when a request also carries a key. See API authentication. A break-glass recovery session lasts at most one hour, even when the normal session TTL is longer.

Recover administrator access

If SSO is unavailable or no administrator can sign in, an operator with host Docker access can issue a one-time link for an existing active owner. Run this from the installation directory while ghost-web is running:

docker compose exec -w /app/api ghost-web python -m admin break-glass --url https://gostly.example.com

Replace the example with the origin where you open the dashboard. If the tenant has several active owners, add --email owner@example.com to select one. The command cannot recover a deleted, suspended or demoted owner.

The link can be used once within 15 minutes. Issuing another link replaces the previous one. The named account must still be an active owner when the link is used. It opens an owner session for at most one hour, or the configured session TTL if shorter. It works with password sign-in disabled and the identity provider down.

Treat the printed link as a password until it is used or expires. Link issuance and redemption are audited as auth.break_glass; refused link uses are recorded with their reason. Once signed in, repair the SSO configuration or administrator binding and verify a normal SSO login.

On the separate no-Gostly-egress build, break-glass remains available after an already-admitted license expires. It does not bypass first license admission or exempt other commands from their checks. The recovery session still has only the existing authorized admin data-out access; it does not reopen customer traffic.

SAML 2.0

The SAML backend is a standard SP-initiated flow. Configure the SP and point it at your IdP's metadata; the SP exposes its own metadata XML for you to import on the IdP side.

Serve the browser-facing deployment over HTTPS and set GOSTLY_SAML_SP_ACS_URL to its HTTPS callback address. SAML uses a Secure browser cookie to bind the response to the sign-in request; changing the general session-cookie setting does not relax this requirement. Plain HTTP callback addresses are refused except for localhost development, where sign-in still depends on the browser's Secure-cookie behavior.

GOSTLY_AUTH_MODE=password,saml

# IdP — supply either a metadata URL or inline metadata XML
GOSTLY_SAML_IDP_METADATA_URL=https://idp.example.com/app/metadata
# (or) GOSTLY_SAML_IDP_METADATA_XML=<...>
GOSTLY_SAML_IDP_ENTITY_ID=https://idp.example.com/saml

# SP — this deployment
GOSTLY_SAML_SP_ENTITY_ID=https://gostly.your-co.internal/saml
GOSTLY_SAML_SP_ACS_URL=https://gostly.your-co.internal/v1/auth/saml/acs

# Assertion attribute names (defaults shown)
GOSTLY_SAML_EMAIL_ATTRIBUTE=email
GOSTLY_SAML_NAME_ATTRIBUTE=displayName
GOSTLY_SAML_GROUP_ATTRIBUTE=memberOf

Start sign-in from Gostly

Start from the Gostly login page. A valid unsolicited response from an IdP dashboard tile restarts a fresh SP-initiated exchange instead of signing in directly. Your IdP must support that exchange. If saml_sign_in_loop appears, check that support and restart from Gostly's login page.

Each accepted assertion can be used only once. After successful sign-in, check that the expected account appears in the dashboard.

The SAML surface is three endpoints:

GET /v1/auth/saml/metadata

Renders the SP metadata XML. Import this on the IdP side to register Gostly as a service provider.

GET /v1/auth/saml/login

Initiates the AuthnRequest and 303-redirects the browser to the IdP. Accepts a relay_state query param for post-login return.

POST /v1/auth/saml/acs

The Assertion Consumer Service callback. Requires a valid signed, browser-bound, unused assertion, resolves the user, mints a session, and returns to a same-origin RelayState path (open-redirects are rejected).

The IdP's group attribute (memberOf by default) feeds the group-to-role mapping described under RBAC.

OIDC

The OIDC backend runs the authorization-code flow with provider discovery and id_token validation. Point it at your issuer and supply the client credentials registered with your IdP.

GOSTLY_AUTH_MODE=oidc

GOSTLY_OIDC_ISSUER=https://idp.example.com
GOSTLY_OIDC_CLIENT_ID=gostly
GOSTLY_OIDC_CLIENT_SECRET=<client-secret>
GOSTLY_OIDC_REDIRECT_URI=https://gostly.your-co.internal/v1/auth/oidc/callback
GOSTLY_OIDC_SCOPES="openid email profile groups"

# Claim names (defaults shown)
GOSTLY_OIDC_EMAIL_CLAIM=email
GOSTLY_OIDC_NAME_CLAIM=name
GOSTLY_OIDC_GROUP_CLAIM=groups

The address comes from GOSTLY_OIDC_EMAIL_CLAIM, falling back to email. The email_verified verdict applies to the email claim, not a configured alternative such as upn. Userinfo may supply a missing address or verdict only for the same sub; a verdict added to an ID-token address must describe that same address. preferred_username is a username, even when configured as the email claim, and cannot link or create an account.

Two endpoints carry the flow:

GET /v1/auth/oidc/login

Builds the authorization URL, sets a short-lived gostly_oidc_state cookie (HttpOnly, Secure, 10-minute Max-Age) for CSRF protection, and 303-redirects to the IdP.

GET /v1/auth/oidc/callback

Exchanges the authorization code, validates the id_token against the discovered JWKS and the round-tripped state, resolves the user, mints a session, and clears the state cookie.

The groups claim feeds the same group-to-role mapping SAML uses — one mapping config covers both backends.

Use the Full Compose file for SSO. It forwards the SAML and OIDC settings from .env to ghost-web and to ghost-migrate, where doctor inspects them. This includes OIDC email/name claims, the SAML IdP entity ID and SP logout URL, SAML signing certificate/key settings, and the OIDC/SAML _FILE variants. A _FILE value names a path inside the container: mount the file at that path in both containers and make it readable by their user, UID 10001. The template does not create or mount those secret files for you. Use an inline value or its _FILE alternative, not both. Lite's shipped file does not forward the full SSO configuration.

Just-in-time provisioning

SAML and OIDC share one provisioning path. When GOSTLY_AUTH_AUTO_PROVISION=true (the default), a first-time SSO login JIT-creates the local user; with it off, an admin must pre-create the user before SSO login is allowed. On every login the user's name, group memberships, and derived role are refreshed from the assertion — IdP-side group changes propagate to Gostly on the next login, with no manual re-sync. To have the IdP create and remove users without waiting for a login, add SCIM provisioning.

Within the deployment and SSO backend, users are matched first by the IdP's stable subject identifier. If that misses, email can link an unbound account or create a user only when the IdP reports a verified address or supplies no verification verdict. An absent verdict trusts the configured IdP's email attribute; it is not proof of verification. An explicit false verdict refuses this email lookup with HTTP 403. An email match to an account bound to another identity is also refused.

If your IdP omits the verdict and users can edit the asserted email, a user can claim someone else's address and take over an unlinked Gostly account at first sign-in, including the bootstrap owner. Disabling auto-provisioning does not prevent this linking of existing accounts.

Configure the IdP to verify addresses and emit email with its email_verified verdict, or set GOSTLY_OIDC_EMAIL_CLAIM to an email-valued claim that only IdP administrators can set. Confirm that users cannot edit that claim; the name upn alone provides no such guarantee. Immediately after enabling SSO, sign in once as the owner through the intended IdP identity to bind the bootstrap owner account. That binding protects this account from another identity's first email-based link; it does not secure other unlinked accounts.

An already-bound subject can resolve its account even with a false email verdict; email format, allowed domain, account status, and other sign-in checks still apply. Email format and domain checks run before either lookup. Configure the optional domain allowlist with:

GOSTLY_AUTH_AUTO_PROVISION=true
GOSTLY_AUTH_ALLOWED_DOMAINS=your-co.com,your-co.internal

An assertion whose email domain is outside the allowlist is rejected before any user row is touched, and the rejection is recorded in the audit log.

SCIM user provisioning

SCIM requires a license with multi_user_workspace enabled; standard Team and Enterprise licenses enable it by default. Provisioning manages local user records separately from browser sign-in. Configure SAML or OIDC for sign-in, then expose the deployment API's /scim/v2 over reachable HTTPS for your IdP. A loopback-only API address cannot receive an external IdP's requests.

  1. In an admin or owner session, create a named service account under Settings → Service accounts and issue a key with scim alone. Deselect the dashboard's preselected read scope and every other scope. Store the once-shown key in your secret store and supply it to the IdP as a Bearer token. Mixed scopes, login sessions and system or legacy keys do not authenticate SCIM requests.
  2. Set the IdP's SCIM base URL to the HTTPS deployment API address ending in /scim/v2. Use userName for matching; enable user creation, profile updates and deactivation. Disable group provisioning and password synchronization.
  3. Check discovery and a filtered user lookup before provisioning a designated test user. Keep that user distinct from the provisioning account's owner, whose suspension could disable the provisioning key itself.
# Supply SCIM_KEY from your secret store; do not save its value here.
SCIM_BASE=https://gostly.your-co.internal/scim/v2

curl --fail-with-body --silent --show-error \
  -H "Authorization: Bearer $SCIM_KEY" \
  "$SCIM_BASE/ServiceProviderConfig"

curl --fail-with-body --silent --show-error --get \
  -H "Authorization: Bearer $SCIM_KEY" \
  --data-urlencode 'filter=userName eq "scim-test@your-co.com"' \
  "$SCIM_BASE/Users"

Read back one controlled lifecycle

  1. Provision the test user through your IdP. Retain the returned user ID and Location from the 201 response, then read GET /scim/v2/Users/{id} and compare the intended fields. Email addresses must satisfy the deployment's allowed-domain policy.
  2. Deliver a controlled deactivation. After Gostly processes it, read back active: false and inspect the user and any owned service-account status. Check a subsequent user-session or owned-key request is refused. Deactivation revokes sessions and suspends owned accounts; it does not interrupt requests already admitted.
  3. Inspect the audit trail alongside current status. Access reductions commit before best-effort audit delivery, so a missing audit event is not evidence that access remained active. Rotate the provisioning key by issuing a replacement, updating the IdP and revoking the old key.

User provisioning boundaries

SCIM supports user resources, not Groups, password synchronization or role synchronization. New users use GOSTLY_AUTH_DEFAULT_ROLE (viewer by default; owner is reduced to admin). IdP group-to-role mapping remains a sign-in operation. Unsupported attributes may be ignored rather than stored. SCIM never changes an owner's email and never deactivates or deletes the last active owner.

PATCH active=true can restore a user suspended by SCIM, but cannot override an administrator's suspension; PUT does not reactivate users. Restoring the user does not restore owned service accounts: an admin must separately reassign or unsuspend them. Only unexpired, unrevoked keys can resume. See service-account recovery.

RBAC — the four roles

Roles are ranked, not flat. A check is a floor comparison — "at least admin" rather than "exactly admin" — so a higher role satisfies a lower role floor. A request below the required floor gets 403. Credential type, scopes and licensed capabilities are additional admission conditions; role rank alone does not authorize every operation.

viewer

rank 0

View permitted product data. Mock content is limited to rows processed by the scrub pipeline and authored manual, MCP or OpenAPI rows; exports and replay have separate role requirements. The default role for an SSO user whose groups map to nothing.

member

rank 1

Create and update permitted services, mocks and recordings. Member sessions can read the full mock library; bulk exports containing unprocessed rows require admin. Ordinary user-management routes require admin.

admin

rank 2

Manage users, scrub config, license, and the audit log. The floor for ordinary user-management routes; dedicated SCIM provisioning uses separate authority.

owner

rank 3

Full control plus owner-only actions. Bootstrap role; cannot be demoted while last in the tenant, and only an existing owner can grant or revoke owner.

Mock visibility tracks processing status and source classification; it does not guarantee that all sensitive data has been removed. Service-account keys have their own content-scope rule below.

Roles are mapped from IdP group claims per deployment via GOSTLY_AUTH_GROUP_TO_ROLE_MAP (JSON). A user gets the highest role any of their groups map to; a user with no matching group falls back to GOSTLY_AUTH_DEFAULT_ROLE (default viewer).

GOSTLY_AUTH_GROUP_TO_ROLE_MAP={"gostly-admins":"admin","engineering":"member"}
GOSTLY_AUTH_DEFAULT_ROLE=viewer

Owner cannot be granted by a group

The single inviolable mapping rule: no group claim can ever map a user to owner — a group literally named owner is silently demoted to admin. Owner is only ever granted by an existing owner through the dashboard. This closes the "add me to the owner group at the IdP" privilege-escalation path. A role change also revokes the user's active sessions, so an open browser tab can't keep an escalated role.

User-management endpoints (Team tier, behind multi_user_workspace):

GET /v1/users

List users in the tenant. Admin+.

POST /v1/users

Create a local-password user. Admin+.

PATCH /v1/users/{id}/role

Change a user's role. Admin+; owner-only for any change touching owner; cannot demote the last owner (409).

PATCH /v1/users/{id}/status

Suspend or reactivate. Admin+; cannot suspend the last owner. Suspending revokes the user's sessions.

DELETE /v1/users/{id}

Soft-delete a user. Admin+; cannot delete the last owner.

POST /v1/users/{id}/sessions/revoke

Kick a user — revoke all of their active sessions. Admin+.

Pro deployments run single-user; the multi-user mutations above are gated to Team. Pair the role floor with a feature gate so a tenant without Team gets a license-shaped 403, not an auth-shaped one.

Service accounts for automation

Use a named service account for each pipeline or agent rather than sharing an administrator's session or the stack's system service key. An admin or owner session issues scoped, expiring keys. Ordinary API keys act as members within their scopes, without inheriting their owner's administrator privileges. Without mocks:read_unscrubbed, their mock content reads use the viewer projection even if they hold write; the extra content scope does not grant a route or raise the role ceiling. A dedicated SCIM key instead authorizes user provisioning and must hold only scim.

Demoting an owner below admin, suspending them or deleting them suspends their active service accounts. Later requests authenticating with those keys get 401 with api_key_suspended. Restoring the human owner alone does not restore the accounts: an admin must reassign an account to an eligible active admin/owner or explicitly unsuspend it once its current owner is eligible again. Existing keys resume only if they are unexpired and unrevoked.

See service accounts for scope, expiry, suspension and restoration routes. Account/key revocation and expiry remain separate from reversible suspension.

The audit log

Authentication and user-management events are recorded in the legacy auth_audit_events table. Ordinary auth writers append events; separate scheduled cleanup can remove old records. The database itself does not block updates or deletes on this table, so treat it as an application-level record. Recorded events include successful and failed authentication. Each row records the actor (user id + email), the event type, the IdP kind, client IP and user-agent (best-effort), a success flag, an error message on failures, a JSON metadata blob, and the timestamp.

Representative event types written today:

Login / logout

login.password.success, login.saml.success, login.oidc.success, the matching .fail variants, and logout.

User management

user.created, user.role.changed (metadata carries the new role), user.suspended, user.deleted, and session.revoked.admin.

The event-type set is enforced by a database CHECK constraint, so a typo'd or unrecognised event type fails the insert rather than landing silently. Successful SAML sign-in and SCIM grants or profile changes require an audit write in their transaction. SCIM access reductions commit before best-effort audit delivery; an audit failure must not retain access. A no-op profile update need not create an event. Inspect user and key status as well as the audit trail.

GOSTLY_AUDIT_RETENTION_DAYS configures the cleanup age; legacy authentication events use an age cutoff of at least 30 days. Expired or revoked login sessions are cleaned up independently of that age policy. Cleanup is scheduled and bounded; locks, backlogs and downtime can delay removal. See audit retention for configuration, retained-feed expiry and maintenance limits.

What is and isn't here

The legacy auth trail lives in your deployment's Postgres. It is distinct from the operator activity feed (the activity_log table that backs GET /v1/activity), which records mock-library operations rather than auth events. The deployment audit API reads and exports a separate retained feed; its JSON and NDJSON exports do not export this legacy auth trail. Both are separate from the organization audit log that /pricing lists under Team, which records gostly.ai account events such as account sign-ins and license and billing changes. Backups and SIEM exports of the legacy auth trail still use your Postgres tooling.

Production hardening checklist

  • Keep GOSTLY_AUTH_COOKIE_SECURE=true (the default). Only set it false for local-dev HTTP on localhost — never in a deployment reachable over the network.
  • Serve the dashboard over HTTPS. SAML and OIDC redirect URLs are derived from the request scheme, and the session cookie is Secure.
  • Scope provisioning with GOSTLY_AUTH_ALLOWED_DOMAINS so only your organisation's domains can JIT-create accounts, and consider GOSTLY_AUTH_AUTO_PROVISION=false for tightly-controlled tenants.
  • Map IdP groups deliberately. Default everyone to viewer and grant member/admin by group — never widen the default role.
  • Keep more than one active owner and verify that an owner or administrator can sign in through the enabled SSO methods. Keep host access available for the break-glass recovery procedure if SSO access is lost.
  • Tune GOSTLY_AUTH_SESSION_TTL_HOURS to your policy; sessions are revocable centrally (admin kick, role change, suspend, delete).

Next steps