Secrets management
OpenClaw supports additive secret references so credentials do not need to be stored as plaintext in config files. Plaintext still works. Secret refs are optional.Goals and runtime model
Secrets are resolved into an in-memory runtime snapshot.- Resolution is eager during activation, not lazy on request paths.
- Startup fails fast if any referenced credential cannot be resolved.
- Reload uses atomic swap: full success or keep last-known-good.
- Runtime requests read from the active in-memory snapshot.
Onboarding reference preflight
When onboarding runs in interactive mode and you choose secret reference storage, OpenClaw performs a fast preflight check before saving:- Env refs: validates env var name and confirms a non-empty value is visible during onboarding.
- Provider refs (
fileorexec): validates the selected provider, resolves the providedid, and checks value type.
SecretRef contract
Use one object shape everywhere:source: "env"
providermust match^[a-z][a-z0-9_-]{0,63}$idmust match^[A-Z][A-Z0-9_]{0,127}$
source: "file"
providermust match^[a-z][a-z0-9_-]{0,63}$idmust be an absolute JSON pointer (/...)- RFC6901 escaping in segments:
~=>~0,/=>~1
source: "exec"
providermust match^[a-z][a-z0-9_-]{0,63}$idmust match^[A-Za-z0-9][A-Za-z0-9._:/-]{0,255}$
Provider config
Define providers undersecrets.providers:
Env provider
- Optional allowlist via
allowlist. - Missing/empty env values fail resolution.
File provider
- Reads local file from
path. mode: "json"expects JSON object payload and resolvesidas pointer.mode: "singleValue"expects ref id"value"and returns file contents.- Path must pass ownership/permission checks.
Exec provider
- Runs configured absolute binary path, no shell.
- By default,
commandmust point to a regular file (not a symlink). - Set
allowSymlinkCommand: trueto allow symlink command paths (for example Homebrew shims). OpenClaw validates the resolved target path. - Enable
allowSymlinkCommandonly when required for trusted package-manager paths, and pair it withtrustedDirs(for example["/opt/homebrew"]). - When
trustedDirsis set, checks apply to the resolved target path. - Supports timeout, no-output timeout, output byte limits, env allowlist, and trusted dirs.
- Request payload (stdin):
- Response payload (stdout):
Exec integration examples
1Password CLI
HashiCorp Vault CLI
sops
In-scope fields (v1)
~/.openclaw/openclaw.json
models.providers.<provider>.apiKeyskills.entries.<skillKey>.apiKeychannels.googlechat.serviceAccountchannels.googlechat.serviceAccountRefchannels.googlechat.accounts.<accountId>.serviceAccountchannels.googlechat.accounts.<accountId>.serviceAccountRef
~/.openclaw/agents/<agentId>/agent/auth-profiles.json
profiles.<profileId>.keyReffortype: "api_key"profiles.<profileId>.tokenReffortype: "token"
Required behavior and precedence
- Field without ref: unchanged.
- Field with ref: required at activation time.
- If plaintext and ref both exist, ref wins at runtime and plaintext is ignored.
SECRETS_REF_OVERRIDES_PLAINTEXT
Activation triggers
Secret activation is attempted on:- Startup (preflight plus final activation)
- Config reload hot-apply path
- Config reload restart-check path
- Manual reload via
secrets.reload
- Success swaps the snapshot atomically.
- Startup failure aborts gateway startup.
- Runtime reload failure keeps last-known-good snapshot.
Degraded and recovered operator signals
When reload-time activation fails after a healthy state, OpenClaw enters degraded secrets state. One-shot system event and log codes:SECRETS_RELOADER_DEGRADEDSECRETS_RELOADER_RECOVERED
- Degraded: runtime keeps last-known-good snapshot.
- Recovered: emitted once after a successful activation.
- Repeated failures while already degraded log warnings but do not spam events.
- Startup fail-fast does not emit degraded events because no runtime snapshot exists yet.
Audit and configure workflow
Use this default operator flow:- Include
skills.entries.<skillKey>.apiKeytargets when those skills use API keys. - If
audit --checkstill reports plaintext findings after a partial migration, migrate the remaining reported paths and rerun audit.
secrets audit
Findings include:
- plaintext values at rest (
openclaw.json,auth-profiles.json,.env) - unresolved refs
- precedence shadowing (
auth-profilestaking priority over config refs) - legacy residues (
auth.json, OAuth out-of-scope reminders)
secrets configure
Interactive helper that:
- configures
secrets.providersfirst (env/file/exec, add/edit/remove) - lets you select secret-bearing fields in
openclaw.json - captures SecretRef details (
source,provider,id) - runs preflight resolution
- can apply immediately
openclaw secrets configure --providers-onlyopenclaw secrets configure --skip-provider-setup
configure apply defaults to:
- scrub matching static creds from
auth-profiles.jsonfor targeted providers - scrub legacy static
api_keyentries fromauth.json - scrub matching known secret lines from
<config-dir>/.env
secrets apply
Apply a saved plan:
One-way safety policy
OpenClaw intentionally does not write rollback backups that contain pre-migration plaintext secret values. Safety model:- preflight must succeed before write mode
- runtime activation is validated before commit
- apply updates files using atomic file replacement and best-effort in-memory restore on failure
auth.json compatibility notes
For static credentials, OpenClaw runtime no longer depends on plaintext auth.json.
- Runtime credential source is the resolved in-memory snapshot.
- Legacy
auth.jsonstaticapi_keyentries are scrubbed when discovered. - OAuth-related legacy compatibility behavior remains separate.
Related docs
- CLI commands: secrets
- Plan contract details: Secrets Apply Plan Contract
- Auth setup: Authentication
- Security posture: Security
- Environment precedence: Environment Variables