Skip to content

CLI Authentication

The rack-gateway CLI uses OAuth to authenticate you with the gateway. This page covers the login flow, session management, and troubleshooting authentication issues.

  1. Run the login command

    Terminal window
    rack-gateway login production https://gateway.example.com
    • production is an alias you choose for this rack
    • The URL is your gateway’s address
  2. Browser opens automatically

    Your default browser opens to the gateway’s OAuth page. If it doesn’t open automatically, the CLI prints a URL you can copy.

  3. Sign in with Google

    Authenticate with your Google Workspace account. The gateway validates that your email domain is allowed.

  4. Return to terminal

    After successful authentication, you can close the browser. The CLI receives a session token and stores it locally.

  5. Verify connection

    Terminal window
    rack-gateway rack
    # Shows rack information if authentication succeeded

The CLI:

  1. Requests a login URL from the gateway
  2. Opens your browser to Google’s OAuth consent page
  3. The gateway receives the OAuth callback and stores the auth code
  4. The CLI polls the gateway to complete login
  5. Stores the session token in your config file

Session tokens are stored in ~/.config/rack-gateway/config.json:

{
"current": "production",
"gateways": {
"production": {
"url": "https://gateway.example.com",
"token": "rgw_sess_...",
"email": "developer@company.com",
"expires_at": "2024-02-15T10:30:00Z",
"session_id": 1024,
"channel": "cli",
"device_id": "8f4c4b8c-...",
"device_name": "dev-mbp",
"mfa_verified": true
}
}
}

CLI sessions are long-lived by default (currently 90 days). Sessions can be:

  • Revoked by an administrator via the web UI
  • Expired after a period of inactivity
  • Invalidated if MFA enforcement changes
Terminal window
# Test your current session
rack-gateway test-auth
# Output shows authentication status
Authenticated as developer@company.com
Role: deployer
Session expires: 2024-02-15 10:30:00 UTC

When your session expires, you’ll see an error like:

Error: session expired or invalid
Please run: rack-gateway login production https://gateway.example.com

Simply re-run the login command to get a new session.

To remove your session:

Terminal window
# Logout from current rack
rack-gateway logout
# The session is revoked on the server and removed locally

This:

  1. Notifies the gateway to invalidate your session
  2. Removes the session token from your local config
  3. Keeps the rack configuration so you can easily log in again

For CI/CD or automation, you can use API tokens instead of OAuth sessions:

Terminal window
# Set via environment variable
export RACK_GATEWAY_API_TOKEN="rgw_token_..."
rack-gateway apps
# Or pass directly
rack-gateway apps --api-token "rgw_token_..."

API tokens:

  • Don’t require interactive login
  • Have their own role and permissions
  • Can be scoped to specific operations
  • Should be created via the web UI or api-token command

See API Tokens for creating and managing tokens.

If MFA is required for your account, you’ll be prompted after OAuth:

Terminal window
rack-gateway login production https://gateway.example.com
Opening browser for authentication...
OAuth successful
MFA verification required.
Enter TOTP code: 123456
MFA verified
Logged in as developer@company.com

The CLI supports:

  • TOTP - Enter the code from your authenticator app
  • WebAuthn - Touch your security key when prompted
  • Backup codes - Enter a backup code if you’ve lost access to your device

See MFA Verification for details.

The CLI tries to open your default browser. If it fails:

Terminal window
# Copy the printed URL and open it manually
rack-gateway login production https://gateway.example.com
# Output: Open this URL in your browser: https://gateway.example.com/api/v1/auth/cli/start?...

The gateway receives the OAuth callback, then the CLI polls until completion. Issues can include:

  • Gateway not reachable: DNS/VPN/Tailscale issues
  • Browser blocked the redirect: allow the callback URL
  • Stale login state: retry rack-gateway login
Error: email domain not allowed

Your Google Workspace domain isn’t configured in the gateway. Contact your administrator to add your domain to GOOGLE_ALLOWED_DOMAIN.

”Session invalid” after working previously

Section titled “”Session invalid” after working previously”

Possible causes:

  1. Administrator revoked your session - Log in again
  2. MFA enforcement changed - You may need to enroll in MFA
  3. Gateway restarted with new secret - All sessions invalidated; log in again

You’re authenticated but your role doesn’t allow the operation:

Error: permission denied: convox:app:delete requires admin role

Contact your administrator to adjust your role if needed.

VariableDescription
RACK_GATEWAY_API_TOKENAPI token for authentication (bypasses OAuth)
GATEWAY_CLI_CONFIG_DIROverride config directory location
RACK_GATEWAY_RACKOverride current rack for this command
RACK_GATEWAY_URLOverride gateway URL (used with API token)