Skip to content

fix(secrets): keep store entry kind when rotating a value - #144143

Closed
yetval wants to merge 1 commit into
openclaw:mainfrom
yetval:fix/secrets-store-set-preserve-kind
Closed

yetval wants to merge 1 commit into
openclaw:mainfrom
yetval:fix/secrets-store-set-preserve-kind

Conversation

@yetval

@yetval yetval commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Summary

openclaw secrets store set <NAME> --value-file <path> silently converts a write-only secret entry into a readable env entry when only the value is rotated.

The trigger is the ordinary credential-rotation path: an entry that was explicitly created with --kind secret under a name the automatic suffix heuristic does not classify as sensitive (OPENAI_KEY, ANTHROPIC_ADMIN_KEY, GH_PAT, AWS_ACCESS_KEY_ID), rotated with no --kind and no --allow-host / --clear-allowed-hosts.

After the rotation the entry is no longer write-only. openclaw secrets store list prints a preview of the rotated credential, openclaw secrets store get returns it instead of refusing, every agent subprocess receives it as plaintext in its environment rather than a sealed sentinel, and the --allow-host egress destination allowlist that bound the secret is deleted. Nothing warns the operator; set reports Stored OPENAI_KEY (env). and exits 0.

openclaw secrets store import has the same root cause and reclassifies every existing entry it rewrites.

Root cause

src/cli/secrets-store-cli.ts looks the existing entry up only when a host-policy flag was passed, so the resolved kind falls back to the name heuristic on a plain value rotation:

// before
const requestedHosts = options.allowHost ?? [];
const hostPolicyRequested = requestedHosts.length > 0 || options.clearAllowedHosts === true;
const existingEntry = hostPolicyRequested
  ? storeModule.listSecretStoreEntries({ scope }).find((entry) => entry.name === name)
  : undefined;
const kind = options.kind
  ? storeKind(options.kind, name)
  : (existingEntry?.kind ?? storeKind(undefined, name));

With no host flags existingEntry is undefined, so storeKind(undefined, name) applies isSensitiveEnvName (src/secrets/secret-env-name.ts, /_?(API_KEY|TOKEN|PASSWORD|PRIVATE_KEY|SECRET)$/i). OPENAI_KEY does not match, so the operator's explicit --kind secret is replaced by "env". import never looks an existing entry up at all.

The upsert in writeSecretStoreEntryInternal then rewrites the stored kind and, for env, nulls the host allowlist. Every consumer branches on the stored row.kind, so one wrong resolution breaks four boundaries at once: readSecretStoreExecEnvironment hands env rows to agent subprocesses as plaintext instead of sealing a sentinel and registering an egress binding, store get drops its write-only refusal, renderList prints valuePreview, and the refusal of --value on argv stops applying.

The conditional lookup shows the intent was already to inherit the stored kind; it was scoped to the host-policy branch by accident.

Fix

Both CLI paths now inherit the stored kind, and that inheritance is resolved inside the authoritative store write transaction rather than captured in the CLI before it awaits input.

SecretStoreWriteParams gains an optional inheritExistingKind. When set, the store reads the live row inside the transaction it already opens, resolves the kind from that row, and drives value validation, the allowed-host refusal, and the allowed_hosts clearing from the resolved kind rather than the requested one:

// after
const kind =
  inheritExistingKind && previous ? (previous.kind as SecretStoreKind) : entry.kind;
if (inheritExistingKind) {
  assertSecretStoreWriteShape(entry.value, kind, entry.allowedHosts);
}

set and import pass inheritExistingKind: options.kind === undefined, and writeSecretStoreEntry returns the kind it committed so set reports what actually landed.

This is correct because the name heuristic is a classifier for names that have never been seen before. Once an entry exists, its stored kind is a recorded operator choice and outranks a guess made from the name. An explicit --kind still wins over both, in either direction, so the operator keeps full control.

Resolving at the write boundary rather than at the start of the command closes the replay window. set awaits readSecretStoreInput and import awaits confirmMutation, and both waits are human-scale. A kind captured before those waits could be replayed over a protection change committed during them, which would downgrade a freshly protected entry and delete the host allowlist the operator had just attached. Because the resolution now happens inside the same transaction as the insert, no store state can change between reading the kind and writing the row.

Import writes its batch under one transaction

Resolving the kind at write time means a value the CLI already accepted can become invalid by the time it is written: an empty value is legal for an env entry and refused for a secret one, so an entry that a concurrent protection change turns into a secret must fail. import previously wrote one entry per transaction, so that failure could arrive after earlier entries of the same batch had already committed, which breaks the no-write-on-validation-failure contract the existing empty-secret refusal in src/cli/secrets-store-cli.test.ts relies on.

import now hands its whole batch to the store as one call. writeSecretStoreEntries resolves every live kind and validates every resulting entry before it writes any of them, inside the single runOpenClawStateWriteTransaction it already opened:

const resolved = params.entries.map((entry) => {
  /* live row lookup, kind resolution and assertSecretStoreWriteShape */
});
for (const { entry, kind, allowedHosts } of resolved) {
  /* upsert */
}

writeSecretStoreEntry is now a single-entry call into the same code, so the two paths cannot drift, and writeSecretStoreEntryWithRollback keeps its previous-value snapshot unchanged.

Why this is the right boundary

The CLI is the only kind resolver in the codebase. The other writer of the store, the Gateway RPC secrets.store.set, takes kind as a required field of SecretsStoreSetParamsSchema and passes it straight through, so it never infers a kind. It does not set inheritExistingKind, so its behavior is unchanged and writeSecretStoreEntry still receives a kind its caller decided.

I considered instead refusing any secret -> env transition inside the store. That is wrong: an explicit --kind env downgrade is a legitimate operator action, and the store cannot tell an explicit downgrade from an inferred one without being told. inheritExistingKind is exactly that missing signal, and it keeps the policy choice with the CLI while giving the store the atomicity only the store can provide. The same reasoning puts the batch in the store rather than in the CLI: only the store owns the transaction, and a CLI-side pre-check would just recreate the window it is meant to close.

import is fixed in the same commit rather than left as a one-sided fix; it shares the root cause and reclassifies every existing entry it rewrites. docs/cli/secrets.md states that automatic detection applies to new names, that an existing entry keeps its kind, and that the inherited kind is resolved as the write commits.

Verification

  • src/cli/secrets-store-cli.kind-inheritance.test.ts drives the real commander program through registerSecretsCli against a real SQLite store in a temp directory. Eight cases pass: value-only rotation keeps a secret write-only and host-bound; an explicit --kind env still downgrades; a brand-new name is still classified from its name; import keeps an existing secret while classifying new names; a protection change made while set waits for its value is applied; the same while import waits for confirmation; a protection change that invalidates a later entry of an import batch leaves every entry of that batch unwritten; and an explicit --kind is still honored across that interleaving.
  • The three interleaving cases fail on earlier heads of this PR and pass here, so they are regressions against the exact defects reported rather than restatements of the fix. Reverting only the batch call site to the previous per-entry loop fails the new case with expected { name: 'SERVICE_MODE', ... } to be undefined.
  • src/secrets/store/secret-store.test.ts passes against the changed store, covering the existing empty-secret refusal, the allowed-host validation, the exec projection, and the hidden GitHub record paths.
  • src/cli/secrets-store-cli.test.ts passes 15 of 15. Its import assertion now reads the single batch call instead of three separate writes, and its empty-secret refusal additionally asserts that the batch write was never reached.
  • No existing assertion depended on the old fallback, so nothing had to be relaxed or rewritten.
  • tsgo and oxlint were not run on this host: this box cannot hold them without exhausting memory. Only the repository formatter and the two targeted suites above were run here, so a type error confined to new code would first surface in the repository's automated checks rather than locally.
  • Values used throughout are synthetic (sk-protected-credential, sk-rotated-credential, plain-original-value, production-next).

Real behavior proof

Behavior addressed: a value-only openclaw secrets store set downgraded a write-only secret entry to a readable env entry, handed the credential to agent subprocesses as plaintext, and deleted its --allow-host egress allowlist. Inheriting the kind at write time then introduced a second failure, reported as the remaining review finding: openclaw secrets store import could commit an earlier entry of its batch and then fail on a later one whose kind had just been changed by another process.
Real environment tested: the real openclaw secrets store command line entry point (src/entry.ts) run as separate processes against a real SQLite secret store in a scratch OPENCLAW_STATE_DIR, plus a real child process spawned from the environment readSecretStoreExecEnvironment resolves, which is the same projection createExecTool gives agent commands in src/agents/bash-tools.exec-run.ts. The interfering process is a second real openclaw secrets store set run while the first command holds its confirmation prompt on a pseudo terminal. Captured on pristine main d23730ee7c54975df5f50294dca34a06592b3590, on the previous head of this PR 13c7014552c3e43dd8f76a235c1aee6264e8c8d2, and on this head 66a8c01c8db76bf63ab79c506880f462856b2d1e, with identical inputs and identical scripted timing. Only the credential values are synthetic.
Exact steps or command run after this patch: scenario A creates OPENAI_KEY with --kind secret --allow-host api.openai.com, rotates it with openclaw secrets store set OPENAI_KEY --value-file <rotated>, then spawns a real child from the resolved agent environment. Scenario B creates SERVICE_API_KEY as --kind env, starts openclaw secrets store import --from values.env where values.env holds SERVICE_MODE=production-next and an empty SERVICE_API_KEY=, leaves it waiting at its confirmation prompt for 12 seconds, protects SERVICE_API_KEY from a second process with --kind secret --allow-host api.example.com during that wait, answers the prompt, and then lists the store. Scenario C imports the same file with --yes and no interference. Each listing prints name, kind, allowed hosts and whether the value is withheld.
Evidence after fix:

######## pristine main d23730ee7c54
### tree: base (d23730ee7c54975df5f50294dca34a06592b3590)
--- A. protect OPENAI_KEY, then rotate only its value
Stored OPENAI_KEY (secret).
  after create:
   OPENAI_KEY kind=secret allowedHosts=["api.openai.com"] valuePreview=(withheld)
Stored OPENAI_KEY (env).
  after value-only rotation:
   OPENAI_KEY kind=env allowedHosts=[] valuePreview="sk-rotated-credential"
  what a real child process receives:
   child process sees OPENAI_KEY: PLAINTEXT sk-rotated-credential
   sealed sentinel offered: false
   egress bindings: []
--- B. import while a second process protects one of its names
Stored SERVICE_API_KEY (env).
  before import:
   SERVICE_API_KEY kind=env allowedHosts=[] valuePreview="plain-original-value"
  second process protects SERVICE_API_KEY while the import prompt is pending:
   Stored SERVICE_API_KEY (secret).
  store while the prompt is still pending:
   SERVICE_API_KEY kind=secret allowedHosts=["api.example.com"] valuePreview=(withheld)
  import command exit code: 2
  import command output: Secret store value is empty. Secret entries require a value; check the command that produced it.
  store after the import command returned:
   SERVICE_API_KEY kind=secret allowedHosts=["api.example.com"] valuePreview=(withheld)

######## previous head of this PR 13c7014552c3
### tree: prev (13c7014552c3e43dd8f76a235c1aee6264e8c8d2)
--- A. protect OPENAI_KEY, then rotate only its value
Stored OPENAI_KEY (secret).
  after create:
   OPENAI_KEY kind=secret allowedHosts=["api.openai.com"] valuePreview=(withheld)
Stored OPENAI_KEY (secret).
  after value-only rotation:
   OPENAI_KEY kind=secret allowedHosts=["api.openai.com"] valuePreview=(withheld)
  what a real child process receives:
   child process sees OPENAI_KEY: absent
   sealed sentinel offered: true
   egress bindings: [{"name":"OPENAI_KEY","allowedHosts":["api.openai.com"]}]
--- B. import while a second process protects one of its names
Stored SERVICE_API_KEY (env).
  before import:
   SERVICE_API_KEY kind=env allowedHosts=[] valuePreview="plain-original-value"
  second process protects SERVICE_API_KEY while the import prompt is pending:
   Stored SERVICE_API_KEY (secret).
  store while the prompt is still pending:
   SERVICE_API_KEY kind=secret allowedHosts=["api.example.com"] valuePreview=(withheld)
  import command exit code: 2
  import command output: Secret store value is empty. Secret entries require a value; check the command that produced it.
  store after the import command returned:
   SERVICE_API_KEY kind=secret allowedHosts=["api.example.com"] valuePreview=(withheld)
   SERVICE_MODE kind=env allowedHosts=[] valuePreview="production-next"

######## this head 66a8c01c8db76bf63ab79c506880f462856b2d1e
### tree: new (66a8c01c8db76bf63ab79c506880f462856b2d1e)
--- A. protect OPENAI_KEY, then rotate only its value
Stored OPENAI_KEY (secret).
  after create:
   OPENAI_KEY kind=secret allowedHosts=["api.openai.com"] valuePreview=(withheld)
Stored OPENAI_KEY (secret).
  after value-only rotation:
   OPENAI_KEY kind=secret allowedHosts=["api.openai.com"] valuePreview=(withheld)
  what a real child process receives:
   child process sees OPENAI_KEY: absent
   sealed sentinel offered: true
   egress bindings: [{"name":"OPENAI_KEY","allowedHosts":["api.openai.com"]}]
--- B. import while a second process protects one of its names
Stored SERVICE_API_KEY (env).
  before import:
   SERVICE_API_KEY kind=env allowedHosts=[] valuePreview="plain-original-value"
  second process protects SERVICE_API_KEY while the import prompt is pending:
   Stored SERVICE_API_KEY (secret).
  store while the prompt is still pending:
   SERVICE_API_KEY kind=secret allowedHosts=["api.example.com"] valuePreview=(withheld)
  import command exit code: 2
  import command output: Secret store value is empty. Secret entries require a value; check the command that produced it.
  store after the import command returned:
   SERVICE_API_KEY kind=secret allowedHosts=["api.example.com"] valuePreview=(withheld)

######## this head 66a8c01c8db76bf63ab79c506880f462856b2d1e, scenario C: the same import with no interference
Stored OPENAI_KEY (secret).
Imported 2 team store entries.
   OPENAI_KEY kind=secret allowedHosts=["api.openai.com"] valuePreview=(withheld)
   SERVICE_MODE kind=env allowedHosts=[] valuePreview="production-next"

Observed result after fix: in scenario A the rotated entry stays secret on this head instead of flipping to env, keeps its api.openai.com egress binding instead of losing it, withholds the value from the listing, and hands the spawned child nothing rather than sk-rotated-credential. In scenario B all three runs exit 2 with the same message, but the store afterwards differs: pristine main and this head contain only the protected SERVICE_API_KEY, while the previous head of this PR also contains SERVICE_MODE=production-next, a durable write from a command that failed. This head restores the all-or-nothing behavior pristine main had, now with the kind resolved from the live row. Scenario C shows the batch still writes every entry of an uninterfered import, so the repair did not trade partial writes for no writes.
What was not tested: only the team scope was exercised, because it is the only scope the command line accepts today. The egress proxy was not driven end to end against a live upstream host, so the proof shows the restored binding and its allowed hosts rather than an intercepted outbound request. The Gateway RPC path was read but not driven, since it carries an explicit kind and does not request inheritance.

@clawsweeper

clawsweeper Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation cli CLI command changes size: M labels Sep 10, 2026
@clawsweeper clawsweeper Bot added P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 10, 2026
@clawsweeper

clawsweeper Bot commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Codex review: blocked before merge. Reviewed September 12, 2026, 3:56 PM ET / 19:56 UTC (Revision 3).

ClawSweeper review

What this changes

The secrets CLI preserves an existing entry’s protection mode during rotation, commits imports atomically, and adds regression coverage and documentation.

Merge readiness

⛔ Blocked before merge - 4 items remain

This remains a useful fix for behavior still present on main. Both prior findings are addressed, including atomic import validation, and the refreshed runtime evidence supports the repair. No blocking code defect remains.

Priority: P1
Reviewed head: 66a8c01c8db76bf63ab79c506880f462856b2d1e
Owner decision: Required. See Decision needed.

Review scores

Measure Result What it means
Overall readiness 🐚 platinum hermit (4/6) A focused repair with convincing real-process evidence and resolved prior findings; owner acceptance remains a separate merge requirement.
Proof confidence 🦞 diamond lobster (5/6) Sufficient (terminal): The complete, identity-matched PR body records exact-head CLI processes against SQLite: rotation withholds plaintext from a real child and retains host bindings, concurrent protection makes an invalid import fail without partial writes, and an ordinary import succeeds. Earlier pending-input proof remains relevant; upstream proxy forwarding and Gateway RPC execution are outside the demonstrated coverage.
Patch quality 🐚 platinum hermit (4/6) No actionable review findings were identified.

Verification

Check Result Evidence
Real behavior Verified Sufficient (terminal): The complete, identity-matched PR body records exact-head CLI processes against SQLite: rotation withholds plaintext from a real child and retains host bindings, concurrent protection makes an invalid import fail without partial writes, and an ordinary import succeeds. Earlier pending-input proof remains relevant; upstream proxy forwarding and Gateway RPC execution are outside the demonstrated coverage.
Evidence reviewed 10 items Verified introduced change: The complete merge-base-to-head store diff consolidates single and batch writes under one transaction, resolves inherited kinds from live rows, and validates all entries before the upsert loop. The host-verified test merge contains the same five changed paths.
Current main still needs the fix: Fetched main still looks up existing kinds only when host-policy flags are supplied, and import still classifies every entry from its name. The central rotation defect therefore remains.
Latest supplied release retains the trigger: The supplied v2026.9.4 release commit contains the conditional existing-entry lookup responsible for value-only rotations reverting to name-based classification.
Findings None None.
Security None None.

How this fits together

The shared secret store holds protected credentials and agent-readable environment values in SQLite. CLI writes determine whether later listings and Gateway-hosted subprocesses receive plaintext or protected secret references.

flowchart TD
  A[CLI set or import] --> B[Read value and confirm]
  B --> C[Store write transaction]
  D[Current stored protection] --> C
  C --> E{All entries valid?}
  E -->|No| F[Reject without batch writes]
  E -->|Yes| G[Commit values and protection]
  G --> H[List output and agent environment]
Loading

Decision needed

Question Recommendation
Will the listed security owners sponsor this repair, accepting protected-entry argv refusal and the store-owned atomic import transaction? Accept the bounded repair: Record listed-owner sponsorship and storage acceptance, retaining safe input alternatives and explicit kind overrides.

Why: The source and runtime evidence support the repair, but repository policy reserves security-path involvement and material transaction acceptance for human owners.

Before merge

  • Resolve merge risk (P1) - Existing scripts rotating protected entries with --value will now exit 2 and require a safe input method; listed-owner acceptance of this intentional compatibility change is not recorded.
  • Resolve merge risk (P1) - The import transaction boundary changes without a recorded accepted storage decision or narrowly scoped exception.
  • Complete next step (P2) - Obtain recorded openclaw/openclaw-secops involvement and acceptance of stored-kind inheritance, protected-entry argv refusal, and the atomic import transaction.
  • Resolve maintainer decision - Resolve the maintainer decision shown above before merge.
Agent review details

Security

None.

PR surface

Source +94, Tests +419, Docs 0. Total +513 across 5 files.

View PR surface stats
Area Files Added Removed Net
Source 2 172 78 +94
Tests 2 435 16 +419
Docs 1 1 1 0
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 5 608 95 +513

Review metrics

Metric Value Why it matters
Import atomicity 1 transaction per import, previously 1 per entry A late validation failure now leaves the entire submitted batch unwritten.
Production versus test growth production +94 net lines; tests +419 net lines Production growth is justified by live-kind validation and a shared atomic writer; tests cover the exposure and interleaving regressions.

Merge-risk options

Maintainer options:

  1. Accept the protected-entry input restriction (recommended)
    Security owners can accept the intentional exit-2 change for argv rotations with the documented stdin, file, and interactive recovery paths.
  2. Hold for an owner-approved transition
    Pause landing if existing automation needs a transition beyond the already supported safe inputs and explicit kind override.

Technical review

Best possible solution:

Keep stored protection authoritative during value rotation, preserve explicit operator overrides, and reject invalid imports without partial writes.

Do we have a high-confidence way to reproduce the issue?

Yes: current main still reclassifies an explicitly protected, non-suffix name during value-only rotation. Contributor process traces demonstrate the same mechanism; this read-only review did not execute it.

Is this the best way to solve the issue?

Yes: resolving protection inside the existing store transaction and validating the complete import batch is the appropriate owner-level repair; explicit operator overrides remain available.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against fe565dd968a3.

Labels

Label changes:

  • add rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • add status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The complete, identity-matched PR body records exact-head CLI processes against SQLite: rotation withholds plaintext from a real child and retains host bindings, concurrent protection makes an invalid import fail without partial writes, and an ordinary import succeeds. Earlier pending-input proof remains relevant; upstream proxy forwarding and Gateway RPC execution are outside the demonstrated coverage.
  • remove rating: 🦐 gold shrimp: Current PR rating is rating: 🐚 platinum hermit, so this older rating label is no longer current.
  • remove status: ⏳ waiting on author: Current PR status label is status: 👀 ready for maintainer look.

Label justifications:

  • P1: Ordinary credential rotation can currently remove protection and expose the new value to listings and Gateway-hosted subprocesses.
  • merge-risk: 🚨 compatibility: Previously accepted argv rotations of protected entries will now fail with exit 2 and require a safe input method.
  • rating: 🐚 platinum hermit: Overall readiness is 🐚 platinum hermit; proof is 🦞 diamond lobster and patch quality is 🐚 platinum hermit.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (terminal): The complete, identity-matched PR body records exact-head CLI processes against SQLite: rotation withholds plaintext from a real child and retains host bindings, concurrent protection makes an invalid import fail without partial writes, and an ordinary import succeeds. Earlier pending-input proof remains relevant; upstream proxy forwarding and Gateway RPC execution are outside the demonstrated coverage.
  • proof: sufficient: Contributor real behavior proof is sufficient. The complete, identity-matched PR body records exact-head CLI processes against SQLite: rotation withholds plaintext from a real child and retains host bindings, concurrent protection makes an invalid import fail without partial writes, and an ordinary import succeeds. Earlier pending-input proof remains relevant; upstream proxy forwarding and Gateway RPC execution are outside the demonstrated coverage.

Evidence

What I checked:

  • Verified introduced change: The complete merge-base-to-head store diff consolidates single and batch writes under one transaction, resolves inherited kinds from live rows, and validates all entries before the upsert loop. The host-verified test merge contains the same five changed paths. (src/secrets/store/secret-store.ts:439, 66a8c01c8db7)
  • Current main still needs the fix: Fetched main still looks up existing kinds only when host-policy flags are supplied, and import still classifies every entry from its name. The central rotation defect therefore remains. (src/cli/secrets-store-cli.ts:212, fe565dd968a3)
  • Latest supplied release retains the trigger: The supplied v2026.9.4 release commit contains the conditional existing-entry lookup responsible for value-only rotations reverting to name-based classification. (src/cli/secrets-store-cli.ts:212, 3a9d69db306c)
  • Complete runtime proof inspected: Retrieved and read the complete PR body; its SHA-256 matches the captured source identity fb3e0ebae76e8626f281c5faa9bb99e8caae4acad7478fdc1ad8d1d636902ce5, covering all 16,933 UTF-16 units. Exact-head traces show a rotated secret withheld from a real child process with its host binding retained, an interleaved invalid import leaving no earlier batch write, and an uninterfered import succeeding. The author explicitly excludes end-to-end upstream proxy and Gateway RPC coverage. (66a8c01c8db7)
  • Prior review findings resolved: The registered import command now calls the batch owner once. Eight boundary tests cover preserved kinds, explicit overrides, new names, concurrent protection changes, and rejection without partial import writes. The author’s response at fix(secrets): keep store entry kind when rotating a value #144143 (comment) supplies the requested failing-before/passing-after regression and process trace. The earlier head object was unavailable locally; continuity was checked against the structured prior finding and current implementation. (src/cli/secrets-store-cli.kind-inheritance.test.ts:334, 66a8c01c8db7)
  • Protection and implementation boundary: The store projection sends env rows as plaintext and seals secret rows; Gateway-hosted exec consumes this projection. The change does not alter Codex-native execution or depend on its implementation. Explicit-kind Gateway and provider-auth writers retain their existing behavior, including owner-checked rollback. (src/secrets/store/secret-store.ts:332, 66a8c01c8db7)

Likely related people:

  • openclaw/openclaw-secops: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)
  • steipete: Suggested for follow-up; no historical authorship or introduction is verified. (role: unverified routing candidate; confidence: low)

Rating scale

Score Internal tier Crab rank Meaning
6/6 S 🦀 challenger crab Exceptional readiness
5/6 A 🦞 diamond lobster Very strong readiness
4/6 B 🐚 platinum hermit Good normal PR; ordinary maintainer review
3/6 C 🦐 gold shrimp Useful, but confidence is limited
2/6 D 🦪 silver shellfish Proof or implementation needs work
1/6 F 🧂 unranked krab Not merge-ready
N/A NA 🌊 off-meta tidepool Rating does not apply

Overall follows the weaker of proof and patch quality.
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

Workflow

  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.

History

Review history (2 earlier review cycles)
  • reviewed 2026-09-10T15:43:25.245Z sha e1f3ee8f1efafe762e6ebe3df4cebb2f63f38554 :: needs real behavior proof before merge. :: [P1] [P1] Revalidate inherited kinds inside the authoritative write
  • reviewed 2026-09-12T01:07:13.032Z sha 13c7014552c3e43dd8f76a235c1aee6264e8c8d2 :: blocked before merge. :: [P2] [P2] Validate and commit inherited import kinds as one batch

@yetval
yetval force-pushed the fix/secrets-store-set-preserve-kind branch from e1f3ee8 to 13c7014 Compare September 12, 2026 00:58
@yetval

yetval commented Sep 12, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto current main and pushed 13c7014552c3e43dd8f76a235c1aee6264e8c8d2. The body now carries proof pinned to that head. Item by item against the last verdict:

[P1] Revalidate inherited kinds inside the authoritative write - fixed, and thank you, the finding was correct. set awaits readSecretStoreInput and import awaits confirmMutation, and the previous head captured the inherited kind before both waits, so a protection change committed during one of them was replayed away. SecretStoreWriteParams now takes an optional inheritExistingKind, and writeSecretStoreEntryInternal resolves the kind from the live row inside the transaction it already opens, then drives value validation, the allowed-host refusal, and the allowed_hosts clearing from the resolved kind. No store state can change between reading the kind and writing the row. set and import request inheritance only when the operator passed no --kind, so an explicit override still wins in either direction.

Security: concurrent protection changes can be overwritten - resolved by the same change, and proved as a final effect rather than by reading the source. Scenario B in the body starts a real openclaw secrets store set SERVICE_API_KEY --value-file - process, leaves it blocked on stdin, protects the entry from a second real process with --kind secret --allow-host api.example.com, then releases the pending value. On the previous head the pending write restored env, deleted the host allowlist, and a real child process spawned from the resolved agent environment received sk-rotated-credential. On this head the same interleaving lands the value under the newer secret policy, keeps api.example.com, and the child receives nothing but a sealed sentinel.

Add real behavior proof, authority chain - the body now carries five traces across three trees: pristine main db2666090f19, the previous head e1f3ee8f1efa, and this head. Each ends with store list --plain, store get, and a real child process spawned from readSecretStoreExecEnvironment, which is the same projection createExecTool gives agent commands in src/agents/bash-tools.exec-run.ts. That is the plaintext-reaching-a-child-process effect you asked for, on both the sequential rotation and the stale-policy interleaving. The original sequential trace is preserved and re-captured against current main.

Merge risk: runtime evidence does not cover a protection change during pending input or confirmation - covered by scenario B above. The interleaving is real rather than simulated: two separate CLI processes against one SQLite store, with the protecting write confirmed committed before the pending value is released.

Merge risk: incomplete broader CLI and store validation - re-run and clean on this head. src/secrets/store/secret-store.test.ts passes 25 of 25 against the changed store, and src/cli/secrets-store-cli.test.ts passes 15 of 15. The two cases I previously reported as timing out were load on my host; both exercise store list and store get and are unaffected by this change.

Explicit permitted overrides - scenario C shows an operator-supplied --kind env still downgrades a protected entry and still yields a readable value, so inheritance never traps an entry in its current kind. There is also a regression covering an explicit --kind applied across the same interleaving.

Regression coverage: the two interleaving cases in src/cli/secrets-store-cli.kind-inheritance.test.ts fail on the previous head and pass here, so they pin the exact defect you identified rather than restating the fix.

Left to maintainers: the request for openclaw/openclaw-secops involvement is yours to route; I cannot add reviewers. One intended behavior change is also worth an explicit look, since it is a policy call rather than a bug fix: openclaw secrets store set <NAME> --value <literal> against an existing secret entry now hits the pre-existing argv refusal with exit 2 instead of silently downgrading the entry and accepting the credential on the command line.

@yetval
yetval marked this pull request as ready for review September 12, 2026 01:00
@yetval
yetval requested a review from a team as a code owner September 12, 2026 01:00
@clawsweeper clawsweeper Bot added merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. proof: sufficient ClawSweeper judged the real behavior proof convincing. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. and removed merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. labels Sep 12, 2026
`secrets store set <NAME> --value-file <path>` resolved the entry kind
from the name heuristic whenever no host-policy flag was passed, so
rotating the value of an entry created with `--kind secret` under a name
the heuristic does not classify as sensitive silently converted it into a
readable `env` entry and deleted its `--allow-host` allowlist. `import`
classified every entry from its name for the same reason.

Both paths now inherit the stored kind, and that inheritance is resolved
inside the authoritative store write transaction rather than captured
before the CLI awaits its value or its confirmation. A protection change
committed while one of those waits is pending is therefore no longer
overwritten by the pending write, and the value it carries lands under
the newer policy instead of reaching agent subprocesses as plaintext.

Because a kind resolved at write time can invalidate a value the CLI
already accepted, `import` now hands its whole batch to a single
store-owned write. `writeSecretStoreEntries` resolves every live kind and
validates every resulting entry inside one transaction before it writes
any of them, so an entry that a concurrent protection change turns into
an empty secret still fails the command with nothing committed, matching
the existing no-write-on-validation-failure contract.

An explicit `--kind` still overrides both the stored kind and the name
heuristic in either direction.
@yetval
yetval force-pushed the fix/secrets-store-set-preserve-kind branch from 13c7014 to 66a8c01 Compare September 12, 2026 19:45
@yetval

yetval commented Sep 12, 2026

Copy link
Copy Markdown
Contributor Author

Rebased onto main at d23730ee7c54975df5f50294dca34a06592b3590 and pushed as 66a8c01c8db76bf63ab79c506880f462856b2d1e. The body carries refreshed real behavior proof pinned to that head. Item by item against the review of 13c7014552c3:

[P2] Validate and commit inherited import kinds as one batch (src/cli/secrets-store-cli.ts:419-424). Fixed, and the interleaving you described reproduces exactly as written. import no longer loops over writeSecretStoreEntry; it hands the whole batch to a new writeSecretStoreEntries, which resolves every live kind and runs assertSecretStoreWriteShape on every resulting entry before it writes any of them, inside the single runOpenClawStateWriteTransaction the store already opened. writeSecretStoreEntry is now a one-entry call into the same code, so the single and batch paths cannot drift, and writeSecretStoreEntryWithRollback keeps its previous-value snapshot.

Real-process evidence is in the body. With an existing env-kind SERVICE_API_KEY, importing SERVICE_MODE=production-next plus an empty SERVICE_API_KEY= while a second process protects SERVICE_API_KEY during the confirmation prompt: on 13c7014552c3 the command exits 2 and SERVICE_MODE is durably written; on this head the command exits 2 with the same message and nothing from the batch is written, which matches what pristine main does. An uninterfered import --yes still writes every entry.

Rank-up move, the regression you asked for. src/cli/secrets-store-cli.kind-inheritance.test.ts gains a case that drives the real commander program against a real SQLite store, protects the entry during the confirmation wait, and asserts both that the command fails and that no earlier entry of the batch exists afterwards. Reverting only the batch call site to the previous per-entry loop fails it with expected { name: 'SERVICE_MODE', ... } to be undefined. src/cli/secrets-store-cli.test.ts is updated in the same commit: its import assertion now reads the single batch call, and its existing empty-secret refusal additionally asserts the batch write was never reached.

Merge risk (P1), argv value rotations of protected entries. Unchanged and still intended. secrets store set <NAME> --value <literal> against an existing secret entry now hits the pre-existing argv refusal and exits 2 rather than silently downgrading the entry, and the documented alternatives are stdin and --value-file. I have not softened this, because softening it is the defect. It needs listed-owner acceptance rather than an author change.

Decision needed, secops sponsorship. Still open and still not author-actionable. I cannot add reviewers to this PR, so routing it to openclaw/openclaw-secops is a maintainer step. The scope to accept is the two behavior changes above: an existing entry's kind is inherited when no --kind is given, and an argv value against a protected entry is refused instead of downgrading it.

Reviewed head. The verdict above was written against 13c7014552c3, which is no longer the head. The prior P1 about resolving inheritance inside the authoritative write stays fixed; this push only adds the batch transaction, its regression, and the proof refresh.

Not run on this host: tsgo and oxlint, which this box cannot hold without exhausting memory. Only the repository formatter and the two suites named above were run locally, so a type error confined to new code would first surface in the repository's automated checks.

@clawsweeper clawsweeper Bot added rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. and removed rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: ⏳ waiting on author ClawSweeper has contributor-facing work open and is waiting for author action. labels Sep 12, 2026
@fuller-stack-dev fuller-stack-dev self-assigned this Sep 17, 2026
@yetval

yetval commented Sep 26, 2026

Copy link
Copy Markdown
Contributor Author

Closing this implementation PR at the author's request and moving the unresolved defect to #158968: #158968

The follow-up report records a fresh check on main b7cf7d9098538044d2e65fbde916458f013c7b73, current reproduction evidence, related work, and explicit proof limits. This closure does not claim the bug is fixed or reject the proposed repair.

The candidate at 66a8c01c8db76bf63ab79c506880f462856b2d1e, its review discussion, and earlier before/after evidence remain available here for maintainers or a future implementation. Please use the linked issue as the canonical open report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cli CLI command changes docs Improvements or additions to documentation merge-risk: 🚨 compatibility 🚨 May break existing users, config, migrations, defaults, or upgrade paths. P1 High-priority user-facing bug, regression, or broken workflow. proof: sufficient ClawSweeper judged the real behavior proof convincing. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. size: M status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants