You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 2bd3590
Browse filesBrowse the repository at this point in the historyBrowse files
fix(secrets): bind env-ref .env retention to the validated source
Retention selects each dotenv file's runtime-effective assignment for a planned env SecretRef and drops the other assignments of that name in that file, so a same-file duplicate cannot leave a fresh process authenticating with a credential apply never validated.
Copy file name to clipboardExpand all lines: docs/gateway/secrets-plan-contract.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -127,7 +127,7 @@ No writes are committed for an invalid plan: target resolution and path validati
127
127
## Runtime and audit scope notes
128
128
129
129
- Ref-only `auth-profiles.json` entries (`keyRef`/`tokenRef`) are included in runtime credential resolution and audit coverage.
130
-
-`secrets apply` writes supported `openclaw.json` targets, supported `auth-profiles.json` targets, and three optional scrub passes, each on by default: `scrubEnv` (removes migrated plaintext values from `.env` files in the effective state and active-config directories), `scrubAuthProfilesForProviderTargets` (clears plaintext/unused-ref residue in `auth-profiles.json` for providers a plan just migrated), and `scrubLegacyAuthJson` (drops migrated `api_key` entries from legacy `auth.json` stores). Set any of `options.scrubEnv`, `options.scrubAuthProfilesForProviderTargets`, `options.scrubLegacyAuthJson` to `false` in the plan to skip that pass.
130
+
- `secrets apply` writes supported `openclaw.json` targets, supported `auth-profiles.json` targets, and three optional scrub passes, each on by default: `scrubEnv` (removes migrated plaintext values from `.env` files in the effective state and active-config directories, except one retained assignment per `env` SecretRef the same plan writes: the first of those files, in the order the gateway loads them, whose effective value for the ref's name is the value the plan validated the ref against. That assignment is the ref's durable source, so removing it would leave the ref unresolvable after restart; the other assignments of that name in the same file are removed so the durable source is also the effective one, and non-matching values under the same name in other files are still removed), `scrubAuthProfilesForProviderTargets` (clears plaintext/unused-ref residue in `auth-profiles.json` for providers a plan just migrated), and `scrubLegacyAuthJson` (drops migrated `api_key` entries from legacy `auth.json` stores). Set any of `options.scrubEnv`, `options.scrubAuthProfilesForProviderTargets`, `options.scrubLegacyAuthJson` to `false` in the plan to skip that pass.
Copy file name to clipboardExpand all lines: docs/gateway/secrets.md
+19Lines changed: 19 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -58,6 +58,8 @@ For production deployments where agent-accessible files are in scope, treat migr
58
58
-`openclaw secrets audit --check` is clean after migration.
59
59
- Any remaining unsupported or rotating credentials are protected by OS isolation, container isolation, or an external credential proxy.
60
60
61
+
An `env` SecretRef does not satisfy this boundary. It resolves by reading its variable from the process environment, which a fresh process hydrates from the dotenv files described in [Retained dotenv sources](#retained-dotenv-sources), so `secrets apply` keeps the backing line in whichever of those files supplies it and the re-audit keeps reporting it as `PLAINTEXT_FOUND`. Migrating to `env` removes the credential from `openclaw.json` and from generated `models.json` files, which is a real config-exposure reduction, but the value stays readable by any agent file or shell tool. Where agent-accessible files are in scope, use `file` or `exec` SecretRefs, or isolate the directories holding those dotenv files, before calling the migration complete.
62
+
61
63
This is why the audit/configure/apply workflow is a security migration gate, not just a convenience helper.
62
64
63
65
<Warning>
@@ -811,6 +813,23 @@ Default operator flow:
811
813
812
814
Do not treat the migration as complete until the re-audit is clean. If the audit still reports plaintext values at rest, the agent-access risk remains even when runtime APIs return redacted values.
813
815
816
+
### Retained dotenv sources
817
+
818
+
An `env` SecretRef leaves its backing value on disk by design, so the re-audit keeps reporting that `.env` key as `PLAINTEXT_FOUND`. `secrets apply` retains exactly one assignment per ref: in the first file it scrubs whose effective value for that name equals the value apply validated the ref against. Deleting that line leaves the ref unresolvable in a fresh process that has no other source for the name.
819
+
820
+
`secrets apply` scrubs two files, in the order the gateway loads them:
821
+
822
+
1. The state-directory `.env` (`OPENCLAW_STATE_DIR`, otherwise `~/.openclaw`).
823
+
2. The active config directory's `.env`, when `OPENCLAW_CONFIG_PATH` points outside the state directory.
824
+
825
+
Only `openclaw gateway run` loads both. Normal CLI commands load the working-directory `.env` and the state-directory `.env`, and never the active config directory's `.env`, so a ref whose only retained source is the config-directory file resolves in the gateway but not in a fresh CLI such as the post-apply `openclaw secrets audit`. Move that assignment into the state-directory `.env` if you need both.
826
+
827
+
Across files the first assignment of a name wins, and an inherited process-environment value wins over every file. Within one file the last assignment of a name wins, so apply removes the other assignments of a retained name in that file; without that removal the ref could resolve after restart to a value apply never validated. A ref validated against a value exported only in the operator's shell has no retained file source at all, and that shell export has to keep supplying it. Working-directory `.env` files are never scrubbed and never retained.
828
+
829
+
Everything else is still scrubbed: a stale value under the same name, a duplicate of the same name, and any redundant copy in a lower-precedence source.
830
+
831
+
The retained line is unmigrated plaintext, not a completed migration, so both a clean re-audit and the agent-access boundary above still require `file` or `exec` SecretRefs, whose values live outside the agent-readable dotenv directories.
832
+
814
833
If you save a plan instead of applying during `configure`, apply that saved plan with `openclaw secrets apply --from <plan-path>` before the re-audit.
0 commit comments