Fix gateway daemon token drift after token rotation#28428
Fix gateway daemon token drift after token rotation#28428l0cka wants to merge 5 commits intoopenclaw:mainfrom
Conversation
Greptile SummaryThis PR fixes gateway daemon token drift after token rotation by implementing a config-first token management strategy. Key Changes
Implementation QualityThe implementation is comprehensive and well-tested with 23 files changed. All critical paths have test coverage including credential precedence parity tests, service audit tests, install flow tests, and doctor repair tests. The migration path for legacy systems is sound - when doctor repair detects an embedded token and config token is missing, it persists the environment token to config before reinstalling. ImpactThis eliminates a critical failure mode where gateway services would fail authentication after token rotation because they were using stale embedded tokens. Users can now rotate tokens via config without needing to reinstall daemon services. Confidence Score: 5/5
Last reviewed commit: 211d145 |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 211d145223
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: f0491cb569
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 86665858ed
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 01e5b948aa
ℹ️ About Codex in GitHub
Your team has set up Codex to 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 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| }; | ||
| try { | ||
| await writeConfigFile(nextCfg); | ||
| cfgForServiceInstall = nextCfg; |
There was a problem hiding this comment.
Propagate persisted token config back to doctor state
After persisting nextCfg, this branch only assigns it to cfgForServiceInstall, so the caller’s cfg remains stale. In doctorCommand, a later writeConfigFile(cfg) (triggered when any other doctor fix is pending) can rewrite openclaw.json without the just-persisted token, undoing the repair. For legacy embedded-token services, that can leave a tokenless unit plus missing gateway.auth.token, causing token-mode restart/auth failures.
Useful? React with 👍 / 👎.
| }, | ||
| }; | ||
| try { | ||
| await writeConfigFile(nextCfg); |
There was a problem hiding this comment.
Block token persistence when doctor config is invalid
This repair path writes nextCfg directly without validating the current config snapshot first. Doctor explicitly runs in best-effort mode on invalid/parsing-failed configs, so cfg can be incomplete; accepting this repair can overwrite the user’s config with a minimal token-only structure and drop unrelated settings. Align this path with the install/configure flows by checking snapshot validity (or merging from snapshot.config) before writing.
Useful? React with 👍 / 👎.
|
This pull request has been automatically marked as stale due to inactivity. |
|
Landed on What changed while landing:
Commits:
Thanks @l0cka. |
Landed from contributor PR openclaw#28428 by @l0cka. Co-authored-by: Daniel Alkurdi <danielalkurdi@gmail.com>
Landed from contributor PR openclaw#28428 by @l0cka. Co-authored-by: Daniel Alkurdi <danielalkurdi@gmail.com>
Landed from contributor PR openclaw#28428 by @l0cka. Co-authored-by: Daniel Alkurdi <danielalkurdi@gmail.com>
Landed from contributor PR openclaw#28428 by @l0cka. Co-authored-by: Daniel Alkurdi <danielalkurdi@gmail.com>
Landed from contributor PR openclaw#28428 by @l0cka. Co-authored-by: Daniel Alkurdi <danielalkurdi@gmail.com>
Landed from contributor PR openclaw#28428 by @l0cka. Co-authored-by: Daniel Alkurdi <danielalkurdi@gmail.com>
Landed from contributor PR openclaw#28428 by @l0cka. Co-authored-by: Daniel Alkurdi <danielalkurdi@gmail.com>
Landed from contributor PR openclaw#28428 by @l0cka. Co-authored-by: Daniel Alkurdi <danielalkurdi@gmail.com> (cherry picked from commit 265367d)
Landed from contributor PR openclaw#28428 by @l0cka. Co-authored-by: Daniel Alkurdi <danielalkurdi@gmail.com> (cherry picked from commit 265367d)
Landed from contributor PR openclaw#28428 by @l0cka. Co-authored-by: Daniel Alkurdi <danielalkurdi@gmail.com> (cherry picked from commit 265367d)
Landed from contributor PR openclaw#28428 by @l0cka. Co-authored-by: Daniel Alkurdi <danielalkurdi@gmail.com> (cherry picked from commit 265367d)
Landed from contributor PR openclaw#28428 by @l0cka. Co-authored-by: Daniel Alkurdi <danielalkurdi@gmail.com>
Landed from contributor PR openclaw#28428 by @l0cka. Co-authored-by: Daniel Alkurdi <danielalkurdi@gmail.com>
Landed from contributor PR openclaw#28428 by @l0cka. Co-authored-by: Daniel Alkurdi <danielalkurdi@gmail.com>
Summary
OPENCLAW_GATEWAY_TOKENin generated daemon service environments and migrate legacy embedded-token units via audit/doctor repairOPENCLAW_SERVICE_KIND=gatewaygateway.auth.token(not env-injected token)tuiand status probe auth precedence to prefergateway.auth.tokenover stale shell/.env token overrides, preventing unauthorized token mismatch after token rotationTesting
pnpm -s vitest run src/daemon/service-env.test.ts src/daemon/service-audit.test.ts src/gateway/credentials.test.ts src/gateway/credential-precedence.parity.test.ts src/commands/doctor-gateway-services.test.ts src/commands/daemon-install-helpers.test.ts src/cli/daemon-cli/lifecycle-core.test.ts src/tui/gateway-chat.test.ts src/cli/daemon-cli/status.gather.test.tspnpm buildpnpm check