Skip to content

fix(doctor): warn when OPENCLAW_GATEWAY_TOKEN env overrides gateway.auth.token config#74433

Merged
sallyom merged 4 commits intoopenclaw:mainfrom
yelog:fix/doctor-env-token-override-warn-74271
May 5, 2026
Merged

fix(doctor): warn when OPENCLAW_GATEWAY_TOKEN env overrides gateway.auth.token config#74433
sallyom merged 4 commits intoopenclaw:mainfrom
yelog:fix/doctor-env-token-override-warn-74271

Conversation

@yelog
Copy link
Copy Markdown
Contributor

@yelog yelog commented Apr 29, 2026

Summary

Fixes #74271

When both OPENCLAW_GATEWAY_TOKEN (environment) and gateway.auth.token (config) are set, CLI commands (status, call, probe) use env-first precedence while the gateway server uses config-first. If the values differ, CLI commands silently fail to authenticate.

Changes

  • Added warning in noteSecurityWarnings() when both env and config tokens are set, explaining the precedence divergence
  • Added SecurityAuditFinding with checkId: "gateway.env_token_overrides_config" in auditGatewayConfig for openclaw security audit --deep
  • 2 new tests: warning appears on conflict, no warning for env-only

@yelog yelog requested a review from a team as a code owner April 29, 2026 15:07
@openclaw-barnacle openclaw-barnacle Bot added commands Command implementations size: S labels Apr 29, 2026
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 29, 2026

Greptile Summary

This PR adds a warning in noteSecurityWarnings() and a SecurityAuditFinding in collectGatewayConfigFindings() to surface the token precedence divergence between CLI commands (env-first) and the gateway server (config-first) when both OPENCLAW_GATEWAY_TOKEN and gateway.auth.token are set. The implementation is correct and the two new tests in doctor-security.test.ts cover the main cases for noteSecurityWarnings. The only gap is that the parallel SecurityAuditFinding path in audit-gateway-config.ts has no new test despite existing test infrastructure in audit-gateway.test.ts.

Confidence Score: 4/5

Safe to merge; the logic is correct and well-scoped, with only a missing test for the audit finding.

Only P2 findings — a missing test for the new collectGatewayConfigFindings path. Implementation logic and existing tests are sound.

src/security/audit-gateway-config.ts — needs a test in audit-gateway.test.ts for the new gateway.env_token_overrides_config finding.

Prompt To Fix All With AI
This is a comment left during a code review.
Path: src/security/audit-gateway-config.ts
Line: 119-132

Comment:
**Missing test coverage for new audit finding**

The new `gateway.env_token_overrides_config` finding in `collectGatewayConfigFindings` has no corresponding test. The existing `audit-gateway.test.ts` file already has helpers (`hasFinding`, `hasFindingWithSeverity`, `withEnvAsync`) that make it straightforward to add cases — one where both `OPENCLAW_GATEWAY_TOKEN` env and `sourceConfig.gateway.auth.token` are set (expecting the finding), and one where only the env token is set (expecting no finding). Without these tests the audit path could regress silently.

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

Reviews (1): Last reviewed commit: "fix(doctor): warn when OPENCLAW_GATEWAY_..." | Re-trigger Greptile

Comment thread src/security/audit-gateway-config.ts Outdated
Comment on lines +119 to +132
if (envTokenConfigured && tokenConfiguredFromConfig) {
findings.push({
checkId: "gateway.env_token_overrides_config",
severity: "warn",
title: "OPENCLAW_GATEWAY_TOKEN overrides gateway.auth.token for CLI commands",
detail:
"Both OPENCLAW_GATEWAY_TOKEN (environment) and gateway.auth.token (config) are set. " +
"CLI commands (status, call, probe) use env-first precedence, but the gateway server uses config-first. " +
"If the two values differ, CLI commands will fail to authenticate with the gateway.",
remediation:
"Remove OPENCLAW_GATEWAY_TOKEN from ~/.openclaw/.env if gateway.auth.token is the intended source, " +
"or remove gateway.auth.token from config if the env var is intentional.",
});
}
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.

P2 Missing test coverage for new audit finding

The new gateway.env_token_overrides_config finding in collectGatewayConfigFindings has no corresponding test. The existing audit-gateway.test.ts file already has helpers (hasFinding, hasFindingWithSeverity, withEnvAsync) that make it straightforward to add cases — one where both OPENCLAW_GATEWAY_TOKEN env and sourceConfig.gateway.auth.token are set (expecting the finding), and one where only the env token is set (expecting no finding). Without these tests the audit path could regress silently.

Prompt To Fix With AI
This is a comment left during a code review.
Path: src/security/audit-gateway-config.ts
Line: 119-132

Comment:
**Missing test coverage for new audit finding**

The new `gateway.env_token_overrides_config` finding in `collectGatewayConfigFindings` has no corresponding test. The existing `audit-gateway.test.ts` file already has helpers (`hasFinding`, `hasFindingWithSeverity`, `withEnvAsync`) that make it straightforward to add cases — one where both `OPENCLAW_GATEWAY_TOKEN` env and `sourceConfig.gateway.auth.token` are set (expecting the finding), and one where only the env token is set (expecting no finding). Without these tests the audit path could regress silently.

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

@clawsweeper
Copy link
Copy Markdown
Contributor

clawsweeper Bot commented Apr 29, 2026

Codex review: passed.

Summary
The PR adds a shared gateway token-source conflict diagnostic, wires it into doctor, status, and security audit, adds regression tests, and updates CHANGELOG.md.

Reproducibility: yes. Source inspection shows current main has the env-first CLI/config-first server precedence split and no conflict diagnostic; this read-only review did not run a live CLI scenario.

Real behavior proof
Override: The PR has the proof: override label, and the exact-head Real behavior proof check is now successful.

Next step before merge
No repair lane is needed: the PR is automerge-opted, proof override is present, and remaining work is exact-head CI/merge gating.

Security
Cleared: The diff adds redacted diagnostics, tests, and a changelog entry without new dependencies, workflow changes, secret exposure, or package-resolution changes.

Review details

Best possible solution:

Land this diagnostic after exact-head CI and mergeability are green, then let the merged PR close #74271.

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

Yes. Source inspection shows current main has the env-first CLI/config-first server precedence split and no conflict diagnostic; this read-only review did not run a live CLI scenario.

Is this the best way to solve the issue?

Yes. Centralizing the redacted conflict helper and reusing it in doctor, status, and audit is the narrow maintainable approach, with guards for same-source SecretRefs and remote mode.

What I checked:

  • Current-main CLI precedence: Local credential resolution reads OPENCLAW_GATEWAY_TOKEN and defaults token/password precedence to env-first for non-service CLI callers. (src/gateway/credentials.ts:82, 7d5ca3064a51)
  • Current-main server precedence: Gateway auth resolution calls resolveGatewayCredentialsFromValues with tokenPrecedence/passwordPrecedence set to config-first, which can diverge from local CLI callers. (src/gateway/auth-resolve.ts:63, 7d5ca3064a51)
  • Documented credential contract: The remote gateway docs document local-mode token precedence as OPENCLAW_GATEWAY_TOKEN before gateway.auth.token, and remote-mode precedence separately. Public docs: docs/gateway/remote.md. (docs/gateway/remote.md:115, 7d5ca3064a51)
  • Current-main diagnostic gap: Current main returns only existing config diagnostics from status scan and has no gateway.env_token_overrides_config/auth-token-source-conflict helper or override warning. (src/commands/status.scan.config-shared.ts:48, 7d5ca3064a51)
  • PR helper scope: The PR helper only reports a local-mode token-source conflict when OPENCLAW_GATEWAY_TOKEN is set, token auth can matter, config has a different token source/value, and config does not point at the same env SecretRef. (src/gateway/auth-token-source-conflict.ts:15, b665be3f6284)
  • PR wiring and tests: The diff wires the helper into doctor, status secretDiagnostics, and gateway security audit, with tests for conflict, env-only suppression, same-env SecretRef suppression, and remote-mode suppression. (src/commands/doctor-security.test.ts:151, b665be3f6284)

Likely related people:

  • steipete: Recent gateway credential, status helper, and gateway audit history repeatedly touches the precedence and diagnostic surfaces this PR extends. (role: recent maintainer and feature-history owner; confidence: high; commits: 1dd5fea7599d, e0cc374b07c1, 72dcf9422138; files: src/gateway/credentials.ts, src/gateway/auth-resolve.ts, src/commands/status.scan.config-shared.ts)
  • vincentkoc: Recent commits touch gateway startup/auth import structure, gateway audit behavior, and remote/auth override behavior adjacent to this diagnostic. (role: adjacent gateway auth and audit maintainer; confidence: medium; commits: 1497425b8dbb, 7b18bd03bb6c, a19a7f5e6e4f; files: src/gateway/auth-resolve.ts, src/security/audit-gateway-config.ts, src/gateway/credentials.ts)
  • joshavant: The gateway SecretRef expansion work added or maintained the config SecretRef helpers and gateway credential paths that this PR deliberately preserves. (role: SecretRef contract owner; confidence: medium; commits: 806803b7efe2; files: src/config/types.secrets.ts, src/gateway/credentials.ts, src/gateway/startup-auth.ts)

Remaining risk / open question:

  • This read-only review did not run local tests; at inspection, 25 of 88 exact-head GitHub check runs for b665be3 were still queued.

Codex review notes: model gpt-5.5, reasoning high; reviewed against 7d5ca3064a51.

@yelog yelog force-pushed the fix/doctor-env-token-override-warn-74271 branch from 3bef7ca to bdb5df8 Compare April 30, 2026 01:33
@yelog yelog force-pushed the fix/doctor-env-token-override-warn-74271 branch from bdb5df8 to 90b5b51 Compare May 5, 2026 03:22
@openclaw-barnacle openclaw-barnacle Bot added the gateway Gateway runtime label May 5, 2026
@sallyom sallyom self-assigned this May 5, 2026
@sallyom sallyom force-pushed the fix/doctor-env-token-override-warn-74271 branch from 472bd6a to 9929dd0 Compare May 5, 2026 16:02
@sallyom
Copy link
Copy Markdown
Contributor

sallyom commented May 5, 2026

@clawsweeper re-review

@openclaw-barnacle openclaw-barnacle Bot added size: M triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. and removed size: S labels May 5, 2026
@clawsweeper
Copy link
Copy Markdown
Contributor

clawsweeper Bot commented May 5, 2026

🦞🧹
ClawSweeper re-review requested.

I asked ClawSweeper to review this item again.
Action: item re-review queued (workflow sweep.yml, event repository_dispatch).
Result: the existing ClawSweeper review comment will be edited in place when the review finishes.

Re-review progress:

@sallyom sallyom added the proof: override Maintainer override for the external PR real behavior proof gate. label May 5, 2026
@openclaw-barnacle openclaw-barnacle Bot removed the triage: needs-real-behavior-proof Candidate: external PR needs after-fix proof from a real setup. label May 5, 2026
@sallyom
Copy link
Copy Markdown
Contributor

sallyom commented May 5, 2026

@clawsweeper automerge

@clawsweeper clawsweeper Bot added the clawsweeper:automerge Maintainer opted this PR into bounded ClawSweeper-reviewed automerge label May 5, 2026
@clawsweeper
Copy link
Copy Markdown
Contributor

clawsweeper Bot commented May 5, 2026

ClawSweeper 🐠 automerge status

ClawSweeper finished this automerge repair pass without changing the branch.

Executor outcome: no planned fix actions.
Worker summary: No repair artifact is needed. The hydrated preflight shows this PR is already closed as merged and #74271 is already closed immediately after that merge. The current checkout is on main at the artifact main SHA and contains the gateway token conflict diagnostic plus the audit/doctor/status regression coverage, including the Greptile-requested audit test path.

Worker actions:

  • keep_closed on this PR: skipped - Already merged and closed; merge is blocked for this worker and there is no remaining repair action to emit.
  • keep_closed on #74271: skipped - Already closed by the merged canonical PR; closure actions are blocked by job policy and invalid for already-closed refs.

This pass stayed observational only. No branch push, replacement, merge, or re-review was started.

fish notes: model gpt-5.5, reasoning high.

Automerge progress:

  • 2026-05-05 16:54:14 UTC review queued 9929dd00ab52 (queued)
  • 2026-05-05 16:56:12 UTC review passed 9929dd00ab52 (structured ClawSweeper verdict: pass (sha=9929dd00ab528f30e8d9cbec28442370afc32...)
  • 2026-05-05 18:47:59 UTC review passed b665be3f6284 (structured ClawSweeper verdict: pass (sha=b665be3f6284a1f00c97ab87a1d0260c4c6b9...)
  • 2026-05-05 18:54:28 UTC review queued b665be3f6284 (queued)

@sallyom sallyom force-pushed the fix/doctor-env-token-override-warn-74271 branch from 9929dd0 to b665be3 Compare May 5, 2026 18:40
@sallyom sallyom merged commit 7dc6007 into openclaw:main May 5, 2026
86 of 88 checks passed
github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request May 9, 2026
…uth.token config (openclaw#74433)

* fix(doctor): warn when OPENCLAW_GATEWAY_TOKEN env overrides gateway.auth.token config (openclaw#74271)

* fix(doctor): narrow gateway token source warning

* test(status): type env secret provider fixture

* fix(doctor): scope gateway token conflict warning to local mode

Signed-off-by: sallyom <somalley@redhat.com>

---------

Signed-off-by: sallyom <somalley@redhat.com>
Co-authored-by: sallyom <somalley@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clawsweeper:automerge Maintainer opted this PR into bounded ClawSweeper-reviewed automerge commands Command implementations gateway Gateway runtime proof: override Maintainer override for the external PR real behavior proof gate. size: M

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: doctor/status should warn when OPENCLAW_GATEWAY_TOKEN in ~/.openclaw/.env overrides gateway.auth.token

2 participants