Skip to content

CLI: expand config set with SecretRef/provider builders and dry-run - #49296

Merged
joshavant merged 2 commits into
mainfrom
feat/config-set-secretref-provider-builder-dryrun
Mar 17, 2026
Merged

joshavant merged 2 commits into
mainfrom
feat/config-set-secretref-provider-builder-dryrun

Conversation

@joshavant

Copy link
Copy Markdown
Collaborator

Summary

Implements the expanded openclaw config set surface discussed for SecretRef/provider assignment and dry-run validation.

This PR keeps the feature scoped to editing openclaw.json only (no secret-store write behavior) and extends the existing CLI surface rather than adding separate secret-writing commands.

What changed

  1. Added config set assignment modes with explicit mode resolution:
  • value mode (config set <path> <value>)
  • SecretRef builder mode (--ref-provider --ref-source --ref-id)
  • provider builder mode on secrets.providers.<alias> (--provider-*)
  • batch mode (--batch-json / --batch-file)
  1. Added strict --dry-run behavior:
  • builder mode: full resolvability required
  • JSON/batch mode: full resolvability + schema validation required
  • supports batch dry-run coverage
  • added structured output for --dry-run --json
  1. Refactored parsing/extraction into focused modules:
  • src/cli/config-set-parser.ts
  • src/cli/config-set-input.ts
  • src/cli/config-set-dryrun.ts
  1. Added target-path lookup helper for config-path-driven SecretRef checks:
  • src/secrets/target-registry-query.ts
  1. Added coverage for:
  • mode parsing
  • batch input parsing
  • dry-run result behavior
  • integration behavior against real config files (including negative dry-run failure)
  1. Updated docs for new CLI surface and examples:
  • docs/cli/config.md
  • docs/cli/index.md
  • docs/channels/discord.md
  • README.md

Usage examples

# SecretRef builder mode
openclaw config set channels.discord.token \
  --ref-provider default \
  --ref-source env \
  --ref-id DISCORD_BOT_TOKEN

# Provider builder mode
openclaw config set secrets.providers.vaultfile \
  --provider-source file \
  --provider-path /etc/openclaw/secrets.json \
  --provider-mode json

# Batch dry-run (schema + resolvability)
openclaw config set --batch-file ./config-set.batch.json --dry-run --json

Validation

  • pnpm test -- src/cli/config-set-mode.test.ts src/cli/config-set-input.test.ts src/cli/config-cli.test.ts src/cli/config-cli.integration.test.ts src/secrets/target-registry.test.ts

Scope notes

  • Does not add first-party managed writable backend behavior.
  • Does not write resolved secret plaintext into config for ref/provider assignment flows.

Linked issues

@joshavant
joshavant requested a review from a team as a code owner March 17, 2026 23:14
@aisle-research-bot

aisle-research-bot Bot commented Mar 17, 2026 •

Copy link
Copy Markdown

🔒 Aisle Security Analysis

We found 2 potential security issue(s) in this PR:

# Severity Title
1 🔵 Low config set --dry-run executes exec secret providers (command execution) and returns unredacted provider error messages
2 🔵 Low Unbounded synchronous read of --batch-file enables local denial of service

1. 🔵 config set --dry-run executes exec secret providers (command execution) and returns unredacted provider error messages

Property Value
Severity Low
CWE CWE-78
Location src/cli/config-cli.ts:795-812

Description

The new openclaw config set --dry-run path performs resolvability checks by calling resolveSecretRefValue() for each affected SecretRef.

This has two security impacts:

  • Unintended command execution / side effects in dry-run: resolveSecretRefValue() can invoke exec secret providers, which spawn a child process (spawn(...) in src/secrets/resolve.ts). As a result, running --dry-run (including on batch payloads) can execute configured commands, potentially causing network calls, state changes, or other side effects, contrary to typical “dry run” expectations.
  • Potential secret leakage via error strings: failures are captured as message: String(err) and emitted to the terminal (non-JSON mode) or included in errors[].message (JSON mode). For exec providers, the error message may incorporate provider-supplied text (e.g., entry.message from the exec provider response), which could include sensitive material (such as tokens embedded in provider error messages).

Vulnerable code (dry-run resolvability loop):

for (const ref of params.refs) {
  try {
    await resolveSecretRefValue(ref, {
      config: params.config,
      env: process.env,
    });
  } catch (err) {
    failures.push({ kind: "resolvability", message: String(err), ref: `${ref.source}:${ref.provider}:${ref.id}` });
  }
}

Because collectDryRunRefs() can include all refs that use a touched provider alias, a single provider update in dry-run may trigger many provider executions (and this code does not pass a cache/batch to coalesce calls), increasing the side-effect/DoS risk.

Recommendation

Safer dry-run behavior

  1. Do not execute exec providers by default in --dry-run (or require an explicit opt-in).

    • Add a flag such as --dry-run --check-resolvability or --dry-run --allow-exec.
    • In default --dry-run, restrict checks to:
      • config schema validation
      • SecretRef/provider shape validation
      • exec provider command path security checks (ownership/permissions/trustedDirs)
  2. Redact/limit error strings returned to users:

    • Prefer structured errors with safe fields (scope, source, provider, refId, and a fixed message).
    • Avoid embedding provider-supplied strings directly into CLI output.
  3. Reduce repeated executions if resolvability remains enabled:

    • Batch by provider and use the existing resolver’s grouping (resolveSecretRefValues(refs, { cache })) to execute each provider at most once per dry-run.

Example: avoid exec by default and sanitize messages:

try {
  if (ref.source === "exec" && !opts.allowExecInDryRun) {
    throw new Error("Exec SecretRef resolvability is disabled in --dry-run (use --allow-exec).")
  }
  await resolveSecretRefValue(ref, { config: params.config, env: process.env });
} catch (err) {
  failures.push({
    kind: "resolvability",
    message: err instanceof Error ? err.message : "SecretRef resolution failed",
    ref: `${ref.source}:${ref.provider}:${ref.id}`,
  });
}

2. 🔵 Unbounded synchronous read of --batch-file enables local denial of service

Property Value
Severity Low
CWE CWE-400
Location src/cli/config-set-input.ts:124-129

Description

The batch mode parser reads the user-supplied --batch-file path using fs.readFileSync() with no size limit and then parses it with JSON5.

Impact:

  • A very large file (or special file like /dev/zero on Unix) can cause excessive memory usage / blocking CPU, freezing the CLI process.
  • Because it is synchronous I/O, the process is blocked until the entire file is read.

Vulnerable code:

const raw = fs.readFileSync(pathname, "utf8");
return parseBatchEntries(raw, "--batch-file");

Recommendation

Add defensive limits and avoid reading unbounded/special files.

Suggested mitigation (size cap + clearer error):

import fs from "node:fs";

const MAX_BATCH_BYTES = 1024 * 1024; // 1 MiB (tune as needed)

const stat = fs.statSync(pathname);
if (!stat.isFile()) {
  throw new Error("--batch-file must point to a regular file.");
}
if (stat.size > MAX_BATCH_BYTES) {
  throw new Error(`--batch-file is too large (${stat.size} bytes > ${MAX_BATCH_BYTES}).`);
}
const raw = fs.readFileSync(pathname, "utf8");

Optionally:

  • make the limit configurable (e.g. --batch-max-bytes)
  • use async I/O (fs.promises.readFile) to reduce blocking (still keep a size cap).

Analyzed PR: #49296 at commit dc9f4ab

Last updated on: 2026-03-17T23:58:52Z

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation channel: discord Channel integration: discord cli CLI command changes size: XL maintainer Maintainer-authored PR labels Mar 17, 2026
@joshavant
joshavant merged commit e999631 into main Mar 17, 2026
11 of 13 checks passed
@joshavant
joshavant deleted the feat/config-set-secretref-provider-builder-dryrun branch March 17, 2026 23:15
@greptile-apps

greptile-apps Bot commented Mar 17, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR significantly expands the openclaw config set command to support four assignment modes (value, SecretRef builder, provider builder, and batch JSON), along with a --dry-run flag that validates changes before writing. The implementation is well-structured — parsing, mode resolution, and dry-run types are factored into dedicated modules, and the test coverage is thorough including integration tests against real config files.

Two issues worth addressing before merge:

  • Dead export / duplicated batch-detection logic: hasBatchMode is exported from src/cli/config-set-input.ts but is never imported by config-cli.ts. Instead, runConfigSet (lines 860–864) re-implements the identical boolean check inline. If the batch-detection logic ever changes in one place (e.g. a new --batch-url flag), the two copies will silently diverge and resolveConfigSetMode could receive an incorrect hasBatchMode: false signal.

  • --dry-run in plain value mode is a silent no-op: When all operations resolve to inputMode === "value" (no --strict-json, no builder flags, no batch payload), neither schema validation nor resolvability checking runs, and dry-run always reports success. A user who adds --dry-run to a plain config set gateway.port "bad-value" invocation will get a misleading success message. At minimum this should be surfaced in the --dry-run help text or emit a notice that no checks were run.

Confidence Score: 3/5

  • Functionally correct for documented modes, but the duplicated batch-detection logic and silent dry-run no-op in value mode are maintenance/UX hazards that should be addressed before merge.
  • Core functionality is well-implemented and tested. The two flagged issues — the unused hasBatchMode export causing a logic duplication risk, and the silent dry-run no-op for value mode — don't cause immediate breakage but are the kind of subtle inconsistencies that tend to create harder-to-diagnose bugs later. The rest of the PR (mode resolution, provider builder, batch parsing, target registry query) is solid.
  • src/cli/config-set-input.ts (unused export) and src/cli/config-cli.ts (value-mode dry-run no-op)
Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/cli/config-set-input.ts
Line: 38-44

Comment:
**Exported `hasBatchMode` is dead code — logic duplicated inline in `runConfigSet`**

`hasBatchMode` is exported here but is never imported by `config-cli.ts`. Instead, `config-cli.ts` (lines 860–864) contains an inline duplicate of the same boolean expression:

```ts
// config-cli.ts (duplicated inline, never uses the export)
const hasBatchMode = Boolean(
  (opts.cliOptions.batchJson && opts.cliOptions.batchJson.trim().length > 0) ||
  (opts.cliOptions.batchFile && opts.cliOptions.batchFile.trim().length > 0),
);
```

If the batch-detection logic changes in `config-set-input.ts` (e.g. adding a new batch flag), the change won't propagate to `runConfigSet`, and the two copies will silently diverge. Either import and call `hasBatchMode(opts.cliOptions)` inside `runConfigSet`, or remove the export entirely and keep the logic local.

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: src/cli/config-cli.ts
Line: 655-676

Comment:
**`--dry-run` in plain value mode performs no validation — always succeeds silently**

When all operations have `inputMode === "value"` (i.e. no `--strict-json`, no builder flags, no batch mode), both `hasJsonMode` and `hasBuilderMode` are `false`. As a result, neither `collectDryRunSchemaErrors` nor `collectDryRunResolvabilityErrors` is called, `errors` stays empty, and dry-run always reports success — regardless of whether the value is valid for the schema.

For example:
```bash
openclaw config set gateway.port '"not-a-number"' --dry-run
# ✓ Dry run successful: 1 update(s) validated  ← no schema check ran
```

The docs do note this scoping, but users who instinctively add `--dry-run` to any `config set` invocation will receive a false sense of safety. At a minimum, consider emitting a warning when dry-run is requested in value mode and no checks will be performed, or document this limitation prominently in the CLI help text for `--dry-run`.

How can I resolve this? If you propose a fix, please make it concise.

Last reviewed commit: "Docs: revert README ..."

Comment on lines +38 to +44
export function hasBatchMode(opts: ConfigSetOptions): boolean {
return Boolean(
(opts.batchJson && opts.batchJson.trim().length > 0) ||
(opts.batchFile && opts.batchFile.trim().length > 0),
);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Exported hasBatchMode is dead code — logic duplicated inline in runConfigSet

hasBatchMode is exported here but is never imported by config-cli.ts. Instead, config-cli.ts (lines 860–864) contains an inline duplicate of the same boolean expression:

// config-cli.ts (duplicated inline, never uses the export)
const hasBatchMode = Boolean(
  (opts.cliOptions.batchJson && opts.cliOptions.batchJson.trim().length > 0) ||
  (opts.cliOptions.batchFile && opts.cliOptions.batchFile.trim().length > 0),
);

If the batch-detection logic changes in config-set-input.ts (e.g. adding a new batch flag), the change won't propagate to runConfigSet, and the two copies will silently diverge. Either import and call hasBatchMode(opts.cliOptions) inside runConfigSet, or remove the export entirely and keep the logic local.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/cli/config-set-input.ts
Line: 38-44

Comment:
**Exported `hasBatchMode` is dead code — logic duplicated inline in `runConfigSet`**

`hasBatchMode` is exported here but is never imported by `config-cli.ts`. Instead, `config-cli.ts` (lines 860–864) contains an inline duplicate of the same boolean expression:

```ts
// config-cli.ts (duplicated inline, never uses the export)
const hasBatchMode = Boolean(
  (opts.cliOptions.batchJson && opts.cliOptions.batchJson.trim().length > 0) ||
  (opts.cliOptions.batchFile && opts.cliOptions.batchFile.trim().length > 0),
);
```

If the batch-detection logic changes in `config-set-input.ts` (e.g. adding a new batch flag), the change won't propagate to `runConfigSet`, and the two copies will silently diverge. Either import and call `hasBatchMode(opts.cliOptions)` inside `runConfigSet`, or remove the export entirely and keep the logic local.

How can I resolve this? If you propose a fix, please make it concise.

Comment thread src/cli/config-cli.ts
Comment on lines +655 to +676
});
continue;
}
operations.push(
buildValueAssignmentOperation({
requestedPath: path,
value: entry.value,
inputMode: "json",
}),
);
}
return operations;
}

function modeError(message: string): Error {
return new Error(`config set mode error: ${message}`);
}

function buildSingleSetOperations(params: {
path?: string;
value?: string;
opts: ConfigSetOptions;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 --dry-run in plain value mode performs no validation — always succeeds silently

When all operations have inputMode === "value" (i.e. no --strict-json, no builder flags, no batch mode), both hasJsonMode and hasBuilderMode are false. As a result, neither collectDryRunSchemaErrors nor collectDryRunResolvabilityErrors is called, errors stays empty, and dry-run always reports success — regardless of whether the value is valid for the schema.

For example:

openclaw config set gateway.port '"not-a-number"' --dry-run
# ✓ Dry run successful: 1 update(s) validated  ← no schema check ran

The docs do note this scoping, but users who instinctively add --dry-run to any config set invocation will receive a false sense of safety. At a minimum, consider emitting a warning when dry-run is requested in value mode and no checks will be performed, or document this limitation prominently in the CLI help text for --dry-run.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/cli/config-cli.ts
Line: 655-676

Comment:
**`--dry-run` in plain value mode performs no validation — always succeeds silently**

When all operations have `inputMode === "value"` (i.e. no `--strict-json`, no builder flags, no batch mode), both `hasJsonMode` and `hasBuilderMode` are `false`. As a result, neither `collectDryRunSchemaErrors` nor `collectDryRunResolvabilityErrors` is called, `errors` stays empty, and dry-run always reports success — regardless of whether the value is valid for the schema.

For example:
```bash
openclaw config set gateway.port '"not-a-number"' --dry-run
# ✓ Dry run successful: 1 update(s) validated  ← no schema check ran
```

The docs do note this scoping, but users who instinctively add `--dry-run` to any `config set` invocation will receive a false sense of safety. At a minimum, consider emitting a warning when dry-run is requested in value mode and no checks will be performed, or document this limitation prominently in the CLI help text for `--dry-run`.

How can I resolve this? If you propose a fix, please make it concise.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 754ef5ddcf

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/cli/config-cli.ts
Comment on lines +596 to +600
path.length === 3 &&
path[0] === SECRET_PROVIDER_PATH_PREFIX[0] &&
path[1] === SECRET_PROVIDER_PATH_PREFIX[1]
) {
return path[2] ?? null;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Track nested provider edits in dry-run ref checks

When config set updates a nested provider field (for example secrets.providers.default.path) in JSON/value mode, this helper returns null unless the path is exactly 3 segments, so buildValueAssignmentOperation never marks the provider alias as touched. As a result, collectDryRunRefs skips refs that depend on that provider and --dry-run can incorrectly succeed even though existing refs become unresolvable after the provider change; this contradicts the documented "full resolvability" dry-run behavior for JSON/batch mode.

Useful? React with 👍 / 👎.

nikolaisid pushed a commit to nikolaisid/openclaw that referenced this pull request Mar 18, 2026
…penclaw#49296)

* CLI: expand config set ref/provider builder and dry-run

* Docs: revert README Discord token example
fuller-stack-dev pushed a commit to fuller-stack-dev/openclaw that referenced this pull request Mar 20, 2026
…penclaw#49296)

* CLI: expand config set ref/provider builder and dry-run

* Docs: revert README Discord token example
fuller-stack-dev pushed a commit to fuller-stack-dev/openclaw that referenced this pull request Mar 20, 2026
…penclaw#49296)

* CLI: expand config set ref/provider builder and dry-run

* Docs: revert README Discord token example
lovewanwan pushed a commit to lovewanwan/openclaw that referenced this pull request Apr 28, 2026
…penclaw#49296)

* CLI: expand config set ref/provider builder and dry-run

* Docs: revert README Discord token example
ogt-redknie pushed a commit to ogt-redknie/OPENX that referenced this pull request May 2, 2026
…penclaw#49296)

* CLI: expand config set ref/provider builder and dry-run

* Docs: revert README Discord token example
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 24, 2026
…penclaw#49296)

* CLI: expand config set ref/provider builder and dry-run

* Docs: revert README Discord token example
Nachx639 pushed a commit to Nachx639/clawdbot that referenced this pull request Jun 17, 2026
…penclaw#49296)

* CLI: expand config set ref/provider builder and dry-run

* Docs: revert README Discord token example
vixco pushed a commit to vixco/openclaw that referenced this pull request Aug 16, 2026
…penclaw#49296)

* CLI: expand config set ref/provider builder and dry-run

* Docs: revert README Discord token example
globalcaos pushed a commit to globalcaos/tinkerclaw that referenced this pull request Sep 29, 2026
…penclaw#49296)

* CLI: expand config set ref/provider builder and dry-run

* Docs: revert README Discord token example
lhfer pushed a commit to lhfer/openclaw that referenced this pull request Oct 11, 2026
…penclaw#49296)

* CLI: expand config set ref/provider builder and dry-run

* Docs: revert README Discord token example
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

channel: discord Channel integration: discord cli CLI command changes docs Improvements or additions to documentation maintainer Maintainer-authored PR size: XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(secrets): add non-interactive openclaw secrets set for GUI/automation use

1 participant