Skip to content

fix(gateway): preserve canonical token SecretRefs (#249) - #306

Merged
KrasimirKralev merged 2 commits into
betafrom
fix/gateway-secretref-preserve
Aug 8, 2026
Merged

KrasimirKralev merged 2 commits into
betafrom
fix/gateway-secretref-preserve

Conversation

@KrasimirKralev

Copy link
Copy Markdown
Contributor

Fixes #249. Supersedes #296 — same fix (@jamesachurchill's commit, authorship preserved), re-homed onto current beta and run through our flow.

The bug

gateway-pre-start.sh's token predicate checked for keys literally named env/file/exec, but OpenClaw's canonical SecretRef uses {source, provider, id} (the source value is env/file/exec). So the predicate failed to recognize a valid ref and clobbered a secret-managed gateway.auth.token with a random literal on every gateway start — confirmed on-device.

The fix

Recognize the canonical {source, provider, id} shape (source ∈ env/file/exec, non-empty string provider+id, exact key set) across all four places the predicate is mirrored (gateway-pre-start.sh Python, install.sh, install-x64.sh, src/lib/gateway-proxy.ts), preserving the ref instead of overwriting it. Also hardens getGatewayToken() to return "" for an unresolved SecretRef/${ENV} rather than serialising it into the browser.

Verified on the Jetson (aarch64)

  • tsc --noEmit: clean (no errors in changed files; matches beta baseline).
  • Tests: 78 pass (gateway-pre-start-token.test.ts, gateway-proxy.test.ts, ai-models/configure.test.ts).
  • Earlier runtime validation on the box: canonical ref preserved byte-identical; a malformed ref correctly rotated to a fresh token.

@KrasimirKralev
KrasimirKralev requested a review from a team as a code owner August 8, 2026 14:43
@coderabbitai

coderabbitai Bot commented Aug 8, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@KrasimirKralev, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 2 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 88517491-b0a5-4690-87db-fc9199c13725

📥 Commits

Reviewing files that changed from the base of the PR and between 1e42d37 and 4c3f7ad.

📒 Files selected for processing (8)
  • install-x64.sh
  • install.sh
  • scripts/gateway-pre-start.sh
  • src/app/setup-api/ai-models/configure/route.ts
  • src/lib/gateway-proxy.ts
  • src/tests/routes/ai-models/configure.test.ts
  • src/tests/unit/gateway-pre-start-token.test.ts
  • src/tests/unit/gateway-proxy.test.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown

🦀 ClawReview

Fresh PR washed in with the tide — here's the gist.

Fixes a confirmed on-device bug where gateway-pre-start.sh was silently replacing externally-managed secret tokens with a random literal on every gateway start — because the predicate checked for keys literally named env/file/exec, but OpenClaw's canonical SecretRef shape uses {source, provider, id}. The fix brings the predicate into alignment with the actual schema across all four places it's mirrored (gateway-pre-start.sh, install.sh, install-x64.sh, gateway-proxy.ts), and also stops getGatewayToken() from serializing an unresolved ref object into the browser as an auth token. This re-homes @jamesachurchill's work from #296 onto current beta with tests passing.

At a glance

  • 🔧 Fix · touches gateway startup script + auth token lifecycle (install.sh, install-x64.sh, gateway-pre-start.sh, gateway-proxy.ts, ai-models configure route)
  • Base branch: beta · +83 source / +76 tests across 8 files
  • ✅ base beta matches the beta-first convention
  • ✅ conventional PR title
  • ✅ source changes come with test changes
  • ℹ️ touches security-sensitive paths (install-x64.sh, install.sh, scripts/gateway-pre-start.sh) — review with extra care

Good to know

  • 🟡 Touches the gateway startup path that runs on every gateway start on customer devices — the bug was actively clobbering tokens in production.
  • 🟡 getOrGenerateGatewayToken() return type changes from Promise to Promise<string | null>; the configure route is updated here, but any other callers in the wider codebase should be checked.
  • ℹ️ Supersedes fix(gateway): preserve canonical token SecretRefs #296 (same fix, same original author) — that PR is still open and should be closed once this lands.
  • ℹ️ Security-sensitive install scripts modified; also updates three test files covering the new SecretRef predicate behaviour.

— ClawReview 🦀, your resident reef crab. Just orientation — CodeRabbit does the line-by-line, humans do the merge. Conventions: docs.

@github-actions github-actions Bot added area: install Auto-triage area area: gateway Auto-triage area area: ui Auto-triage area labels Aug 8, 2026
@github-actions

github-actions Bot commented Aug 8, 2026

Copy link
Copy Markdown

CI Summary

✅ Tests

  • Result: passed
  • View run
  • Coverage: statements 70.16%, branches 60.37%, functions 65.65%, lines 72.11%

✅ E2E

❌ E2E Install

…retRef

/code-review: with source validated as an enum and id/provider as non-empty
strings, keys.length===3 already guarantees the keys are exactly
{source,id,provider}; the three keys.includes() calls were dead weight.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: gateway Auto-triage area area: install Auto-triage area area: ui Auto-triage area

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant