Skip to content

Authentication Overview

Rack Gateway uses a multi-layered authentication system combining OAuth 2.0 for identity, session tokens for authorization, and optional multi-factor authentication for additional security.

OAuth 2.0

For human users

Google Workspace OAuth with PKCE for secure sign-in. Domain restrictions ensure only authorized users can access.

Learn more →

API Tokens

For automation

Long-lived tokens for CI/CD pipelines, scripts, and integrations. Each token has an assigned role.

Learn more →

The gateway supports two authentication channels:

AspectWeb BrowserCLI
OAuth FlowStandard code flowPKCE code flow
Session StorageHTTP-only cookieLocal config file
Session LifetimeConfigurable (default 5 min idle)90 days
MFABrowser-based promptsTerminal prompts
CSRF ProtectionRequired (cookie-based)Not needed (token-based)
  1. User clicks “Sign in with Google”
  2. Redirected to Google OAuth consent screen
  3. After approval, redirected back with authorization code
  4. Gateway exchanges code for ID token
  5. Session created and stored in HTTP-only cookie
  6. If MFA enabled, prompted for verification
  1. User runs rack-gateway login
  2. CLI generates PKCE code verifier and challenge
  3. Browser opens to Google OAuth with challenge
  4. After approval, Google redirects back to the gateway callback
  5. CLI polls the gateway to complete login
  6. Gateway exchanges code + verifier for ID token and issues a session
  7. Session token stored in ~/.config/rack-gateway/config.json

Sessions are the primary authentication mechanism after initial OAuth:

  • Token-based: Opaque tokens stored in database, hashed
  • Revocable: Sessions can be revoked at any time
  • Sliding expiration: Activity refreshes the session
  • Device tracking: IP address and user agent logged

See Sessions for details.

Only users from your Google Workspace domain can authenticate:

# Environment variable
GOOGLE_ALLOWED_DOMAIN=yourcompany.com

Users from other domains receive an error during OAuth callback.

The gateway verifies that:

  • Email is verified in Google’s ID token
  • Email domain matches the allowed domain
  • User account exists and is not locked/suspended

Session tokens are never stored in plaintext:

Stored: SHA-256(session_token)
Client: session_token (raw)

Even if the database is compromised, tokens cannot be recovered.

Web requests require CSRF tokens to prevent cross-site request forgery:

  • Token derived from session using HMAC
  • Validated on all state-changing requests
  • Automatically handled by the web UI

MFA adds a second factor after OAuth authentication:

MFA can be:

  • Required for all users (recommended for production)
  • Required for specific roles (e.g., admins only)
  • Optional (user choice)

See MFA Overview for setup details.

CharacteristicSession (Human)API Token (Automation)
CreationOAuth flowAdmin creates in UI
LifetimeShort (idle timeout)Long (until revoked)
RevocationLogout or admin actionDelete token
MFARequired if enabledN/A
CSRFRequired (web)Not required
Use CaseInteractive accessCI/CD, scripts

Key authentication settings:

SettingDescriptionDefault
GOOGLE_CLIENT_IDOAuth client IDRequired
GOOGLE_CLIENT_SECRETOAuth client secretRequired
GOOGLE_ALLOWED_DOMAINAllowed email domainRequired
APP_SECRET_KEYSecret for sessions/CSRFRequired
RGW_SETTING_SESSION_TIMEOUT_MINUTESIdle session timeout5

See Configuration for complete reference.

  • HTTPS enabled with valid certificate
  • GOOGLE_ALLOWED_DOMAIN set to your domain
  • APP_SECRET_KEY is strong and unique
  • Session timeout appropriate for your security needs
  • MFA enabled for privileged users
  • Audit logging configured