skip to content

In OpenClaw, how do the `gateway.auth` token and password modes work, and how do you set and rotate the secret safely?

level: middleimportance: should knowfreq 9%

answer

  1. fail-closed by default
  2. token unless a password resolves
  3. environment variables over config
  4. 24 characters and placeholder checks
  5. clients carry their own copy

basics

~20 s

OpenClaw's Gateway requires auth by default: token mode, the default, or password mode holds one shared secret every client presents. Generate a long random value, update each client's gateway.remote copy when rotating, and verify the old one fails.

solid answer

~40 s

`gateway.auth.mode` selects `"token"`, `"password"`, `"trusted-proxy"` or `"none"`. Unset, it resolves to password if a password is configured, otherwise token; with both set, you set the mode explicitly. The secret comes from `gateway.auth.token` / `OPENCLAW_GATEWAY_TOKEN` or `gateway.auth.password` / `OPENCLAW_GATEWAY_PASSWORD`. With no valid auth path the Gateway refuses WebSocket connections, startup rejects blank values, `undefined`, `null` and published placeholders, and the audit warns below 24 characters. `openclaw doctor --generate-gateway-token` or `openssl rand -hex 32` gives a real value. To rotate: set the new secret, update clients' `gateway.remote.token`/`password`, confirm the old one fails. A token change hot-applies while the mode stays the same; a mode change or a changed environment variable needs a restart. Treat the secret as full operator access.

code

bash · 2 lines
bash
openclaw doctor --generate-gateway-token
openclaw security audit

go deeper

for a junior

Remember the Gateway refuses unauthenticated connections by default and that token mode, with a generated token, is the normal setup.

for a middle

Explain how the mode resolves, where the secret can live, the client-side gateway.remote copy, and the rotation steps with their reload rules.

for a senior

Show why the shared secret is full operator access over HTTP, and catch reuse with hooks.token, passwords in config and placeholder values in review.

for a principal

Decide when a shared secret stops being enough for a team and identity-bearing trusted-proxy auth, or separate Gateways, are worth the operational cost.

## What Gateway auth protects Every client of an OpenClaw Gateway (the CLI, the browser Control UI, the phone and desktop apps, scripts calling its HTTP API) connects to the same port. **Gateway auth** decides which of those connections becomes an operator. It is configured under `gateway.auth`, and it is **required by default**: with no valid auth path configured, the Gateway refuses WebSocket connections rather than running open. ## The modes | `gateway.auth.mode` | Secret / identity | Typical use | |---|---|---| | `"token"` (default) | Shared bearer token: `gateway.auth.token` or `OPENCLAW_GATEWAY_TOKEN` | Most setups | | `"password"` | Shared password: `gateway.auth.password` or `OPENCLAW_GATEWAY_PASSWORD` | Required for Tailscale Funnel | | `"trusted-proxy"` | Identity from an identity-aware reverse proxy, from IPs in `gateway.trustedProxies` | Team SSO in front of the Gateway | | `"none"` | Nothing | Private ingress only; logged as a warning | When the mode is unset, a resolved password selects password mode and otherwise token mode applies. If both a token and a password are configured, set the mode explicitly so there is no ambiguity. ## Setting the secret - **Generate it, never type it.** Onboarding generates a token by default, even for loopback. `openclaw doctor --generate-gateway-token` creates one later; any long random value (for example 32 random bytes in hex) works. - **Startup rejects bad values:** blank strings, the literal strings `undefined` and `null`, and published example placeholders. - **The audit grades strength:** `gateway.token_placeholder_value` and `gateway.password_placeholder_value` are critical; `gateway.token_too_short` and `gateway.password_too_short` warn below 24 characters. - **Prefer the environment for passwords.** A password written into `openclaw.json` raises `config.secrets.gateway_password_in_config`; `OPENCLAW_GATEWAY_PASSWORD` or a SecretRef keeps it out of the file. - **Do not reuse it elsewhere.** If `hooks.token` equals the Gateway secret, the audit raises `hooks.token_reuse_gateway_token` as critical, because the webhook token would also unlock the Gateway. ## Server secret versus client copy `gateway.remote.token` and `gateway.remote.password` are **client** settings: what the CLI or app sends when it connects to a remote Gateway. They do not protect local WebSocket access by themselves. A local CLI falls back to them only when `gateway.auth.*` is unset, and an explicitly configured SecretRef that fails to resolve fails closed instead of silently using the remote copy. ## Rotation The documented checklist: 1. Generate and set the new `gateway.auth.token` (or password, or its external source). 2. Update every client's `gateway.remote.token` / `gateway.remote.password`. 3. Verify the old credential no longer works. Reload rules matter here: - A configured token or password change **hot-applies** as long as the effective auth mode stays the same. - Changing `gateway.auth.mode` **requires a Gateway restart**. - A secret supplied through the process environment (such as `OPENCLAW_GATEWAY_PASSWORD`) also needs a restart with the new environment. ## Why the secret is worth this care Shared-secret HTTP bearer auth is **all-or-nothing operator access**. A caller holding the token can call `/tools/invoke`, `/api/channels/*` and any enabled `/v1/*` endpoint (the OpenAI-compatible ones are off by default) with the full default operator scopes, and an `x-openclaw-scopes` header does not narrow that path. Per-request scopes only apply with an identity-bearing mode such as trusted-proxy. So the token is not a "dashboard password"; it is the keys to the assistant, its channels and its tools. Share it only inside the trust boundary, and rotate it whenever it may have left that boundary. ## Where the secret ends up on disk A token written into config lives in `~/.openclaw/openclaw.json`, next to channel credentials under `~/.openclaw/credentials/` and model auth in per-agent SQLite stores. OpenClaw's guidance is to assume anything under `~/.openclaw` may hold secrets: - keep `openclaw.json` at `600` and `~/.openclaw` at `700`; the audit raises `fs.config.perms_world_readable` as critical when the config is world-readable, and `--fix` tightens it; - avoid state in synced folders (`fs.synced_dir`), which copies tokens and transcripts to another provider; - use full-disk encryption on the host and a dedicated OS user if the machine is shared; - prefer environment variables or SecretRef providers over literal values, so a config backup or a pasted snippet does not leak the secret. When sharing diagnostics, `openclaw status --all` gives a pasteable, redacted report instead of raw config.

  • Why does a token sent with `x-openclaw-scopes: operator.read` still get full access to OpenClaw's HTTP API?
    Shared-secret bearer auth restores the full default operator scopes and owner semantics, and narrower `x-openclaw-scopes` values do not reduce that path. Per-request scopes apply only to identity-bearing modes such as trusted-proxy auth, or an explicitly no-auth private ingress. Anyone holding the token is a full operator.
  • After changing `gateway.auth.mode` from token to password, why can clients still not connect with the new password?
    An auth-mode change does not hot-apply; it needs a Gateway restart. Token or password rotation within the same mode hot-applies, but switching modes, or changing a secret supplied only through the process environment, takes effect after the Gateway (or its supervising app) restarts.

  • Loopback installs run without auth, so a token is optional there.
  • gateway.remote.token is what protects the Gateway from remote clients.
  • Sending x-openclaw-scopes makes a shared token read-only.
  • Changing the auth mode hot-reloads like any other config change.
  • Reusing the Gateway token as hooks.token saves managing two secrets.