Skip to content

feat(cloud-workers): pinned SSH tunnel runtime and provider-owned key resolution - #104553

Merged
steipete merged 3 commits into
mainfrom
claude/cloud-workers-ssh-tunnel
Jul 11, 2026
Merged

steipete merged 3 commits into
mainfrom
claude/cloud-workers-ssh-tunnel

Conversation

@steipete

Copy link
Copy Markdown
Contributor

Part of #104294 (cloud workers, milestone 1, PR 4 — final PR of the milestone). Builds on #104401, #104465, #104532. Design: docs/plan/cloud-workers.md.

What Problem This Solves

A bootstrapped worker still has no communication path: the design routes everything (worker protocol, transcript ingestion, inference proxy) over a gateway-initiated SSH reverse tunnel, so the box needs zero network reachability in either direction beyond its sshd. This PR adds that tunnel runtime, plus the two provider key contracts PR 3 left fail-closed.

Why This Change Was Made

  • Tunnel runtime (src/gateway/worker-environments/tunnel.ts): gateway-initiated reverse tunnel forwarding a worker-local unix socket (randomized 0700 directory, 0177 umask — no port collisions, multi-user isolation) to the gateway's WS endpoint. Keepalives (ServerAlive), capped reconnect backoff, owner-epoch fencing (a reconnect cannot resurrect a tunnel for a drained/replaced environment — new epoch publishes before old teardown awaits, every await re-checks currency), clean teardown, and a separate SSH connection for workspace transfer so rsync cannot head-of-line-block control traffic. Socket cleanup ownership was decided against OpenSSH source behavior (OpenSSH unlinks before listener bind; channel teardown does not unlink), so the manager owns cleanup and never unlinks a replacement's socket.
  • Shared hardened SSH preparation extracted to ssh.ts — bootstrap, tunnel, and workspace paths share the pinned trust material and option set instead of duplicating it. No connection multiplexing; pinning always strict.
  • Provider-owned SSH identity resolution (contract addition): the provider that minted a keyRef resolves it. The crabbox provider resolves its opaque per-lease reference to the current key path; static-ssh continues through the generic SecretRef resolver. Closes the "dynamic key path" gap from PR 2/3.
  • Crabbox host-key exposure: direct inspection of the crabbox source shows inspect --json cannot expose host-key material today (StatusView carries host/user/port/client-key path only; existing trust is TOFU in its own ssh path; workspace provisioning already generates host keys). OpenClaw now consumes the designed optional sshHostKey field ("algorithm base64", authoritative pre-first-boot key) when present and remains fail-closed when absent. The required crabbox-side plumbing is specified precisely in this PR's review notes and tracked as a companion change in the crabbox repo.
  • Tunnel status projects into environments.list/status summaries; no SQLite persistence because connection state is process-owned and ephemeral (lifecycle-owned, per the freshness rules).

User Impact

Opt-in only. Static-ssh environments gain a working, pinned, self-healing tunnel runtime with start/stop APIs (consumed by the milestone-2 worker role). Crabbox environments remain fail-closed on bootstrap until the crabbox CLI ships sshHostKey. Configuration reference and plan docs updated.

Evidence

  • Blacksmith Testbox: 4 Vitest shards green (tunnel lifecycle against a fake ssh runner — establish/keepalive args/reconnect backoff/teardown/no-resurrect-after-drain/epoch fencing; shared SSH prep; provider-owned + generic key resolution; crabbox fail-closed and sshHostKey wiring; environments projections; lint-suppressions guard).
  • Fresh autoreview on the final rebased diff: clean, no actionable findings ("patch is correct", 0.78). Codex-side pre-commit verification: 462 targeted tests, oxlint, test-types, madge zero, SDK/protocol/docs generation checks.
  • Dependency contracts verified against source, not memory: crabbox Go internals (inspect/status/run/ssh paths, workspace host-key generation) and openssh-portable (listener bind unlink semantics, channel teardown).

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation app: web-ui App: web-ui gateway Gateway runtime scripts Repository scripts extensions: crabbox size: XL maintainer Maintainer-authored PR labels Jul 11, 2026

@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: d73a128082

ℹ️ 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".

ageMs: Type.Integer({ minimum: 0 }),
idleMs: Type.Optional(Type.Integer({ minimum: 0 })),
attachedSessionIds: Type.Array(NonEmptyString),
tunnelStatus: WorkerTunnelStatusSchema,

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 Badge Keep tunnelStatus backward-compatible

When a newer client talks to an older gateway that still negotiates protocol v4 (the generated native constants remain at version 4), older worker summaries do not include worker.tunnelStatus; making this field required here also makes the SDK and Swift WorkerEnvironmentMetadata require it, so environments.list/status/create/destroy responses containing a worker from an older v4 gateway can fail validation or decoding. For this protocol-4 additive field, make it optional/default to stopped on clients or version-gate it before requiring it.

Useful? React with 👍 / 👎.

@clawsweeper clawsweeper Bot added rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. feature: ✨ showcase ClawSweeper spotlight: unusually compelling feature idea for maintainer attention. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. P2 Normal backlog priority with limited blast radius. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. labels Jul 11, 2026
@clawsweeper

clawsweeper Bot commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge. Reviewed July 11, 2026, 12:23 PM ET / 16:23 UTC.

Summary
Adds a pinned SSH reverse-tunnel runtime for cloud workers, provider-owned SSH identity resolution, tunnel-status protocol projection, Crabbox host-key/key-path integration, and supporting docs/tests.

PR surface: Source +915, Tests +704, Docs +4, Generated 0, Other +11. Total +1634 across 37 files.

Reproducibility: not applicable. This PR implements a staged new capability rather than fixing broken established behavior; the relevant validation path is a real SSH worker scenario.

Review metrics: 2 noteworthy metrics.

  • Plugin API additions: 1 optional provider hook, 2 public identity types. The provider-owned SSH identity contract becomes a public plugin security surface before merge.
  • Protocol additions: 1 tunnel-status enum, 1 required worker metadata field. Gateway, TypeScript SDK, protocol schemas, and generated Swift models must stay aligned across the staged rollout.

Stored data model
Persistent data-model change detected: durable storage schema: src/gateway/worker-environments/bootstrap.ts, durable storage schema: src/gateway/worker-environments/identity.test.ts, durable storage schema: src/gateway/worker-environments/identity.ts, durable storage schema: src/gateway/worker-environments/service-contract.ts, durable storage schema: src/gateway/worker-environments/service.test.ts, durable storage schema: src/gateway/worker-environments/service.ts, and 15 more. Confirm migration or upgrade compatibility proof before merge.

Root-cause cluster
Relationship: fixed_by_candidate
Canonical: #104294
Summary: This PR is the final milestone-1 implementation candidate under the canonical cloud-workers feature issue; the three related PRs are merged foundations rather than competing fixes.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🦪 silver shellfish
Proof: 🦪 silver shellfish
Patch quality: 🦞 diamond lobster
Result: blocked until real behavior proof from a real setup is added.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Rank-up moves:

  • [P1] Add redacted live proof of pinned connection, forced reconnect, separate workspace command execution, stop fencing, and socket cleanup.
  • [P1] Link the concrete Crabbox change or tracker that will add authoritative sshHostKey output.

Proof guidance:

  • [P1] Needs real behavior proof before merge: The PR provides fake-runner lifecycle tests and CI but no after-fix run on a real SSH worker; add redacted terminal/log or linked-artifact proof, update the PR body to trigger review, or ask a maintainer to comment @clawsweeper re-review.

Risk before merge

  • [P1] Crabbox workers remain intentionally fail-closed and unusable until a separate Crabbox release exposes authoritative sshHostKey material; no open companion PR was found in the live Crabbox search.
  • [P1] The new SSH security boundary is covered by fake-runner tests and CI, but no submitted live setup proves real OpenSSH connection, reconnect, workspace-command isolation, and teardown behavior on this head.

Maintainer options:

  1. Prove the staged SSH boundary (recommended)
    Add redacted live static-SSH evidence and link the exact Crabbox host-key companion while retaining fail-closed behavior.
  2. Accept milestone-only staging
    Merge after proof while explicitly owning that the public seams are currently unconsumed and Crabbox remains unavailable.
  3. Pause for a complete production slice
    Hold the PR until Crabbox host-key output or the milestone-2 caller can demonstrate the full worker path.

Next step before merge

  • [P1] No narrow code defect is available for automated repair; maintainers need live behavior proof and an explicit decision on staging the SSH security boundary before its Crabbox dependency and first caller ship.

Maintainer decision needed

  • Question: Should this milestone-1 SSH security boundary merge before the Crabbox host-key companion and milestone-2 caller exist, once live static-SSH proof is added?
  • Rationale: The implementation is technically coherent and fail-closed, but maintainers must explicitly accept staging a public plugin/protocol security boundary whose production Crabbox path remains unavailable until external companion work ships.
  • Likely owner: steipete — The feature owner authored and merged the preceding cloud-worker milestones and is best positioned to choose whether this boundary should stage independently.
  • Options:
    • Merge after live static-SSH proof (recommended): Accept the staged boundary after a real pinned tunnel run and an explicit link to the Crabbox host-key companion establish the upgrade and dependency story.
    • Wait for Crabbox companion: Hold the PR until authoritative sshHostKey output is implemented and the complete Crabbox path can be demonstrated.
    • Wait for milestone 2: Keep the tunnel private to the series until its first production caller can prove the end-to-end worker communication path.

Security
Cleared: The patch strengthens the SSH boundary with strict pinning and authoritative identity ownership; no concrete security or supply-chain defect was found.

Review details

Best possible solution:

Keep the pinned, gateway-owned tunnel and provider-owned identity design, but require a redacted live static-SSH run covering initial connection, forced reconnect, a separate workspace command, epoch-safe stop, and remote socket cleanup; also link the exact Crabbox host-key companion before merge.

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

Not applicable: this PR implements a staged new capability rather than fixing broken established behavior; the relevant validation path is a real SSH worker scenario.

Is this the best way to solve the issue?

Yes, conditionally: the gateway-owned pinned reverse tunnel and provider-owned opaque identity resolver are the narrowest design-consistent solution, and no duplicate supported path exists, but live proof and an explicit staging decision are still required.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against b769964e82ab.

Label changes

Label changes:

  • add P2: The opt-in feature has limited current blast radius but materially changes gateway, plugin, protocol, and SSH security surfaces.
  • add merge-risk: 🚨 security-boundary: Merging establishes host-key pinning, SSH identity resolution, reverse forwarding, and remote socket ownership contracts that green CI alone cannot validate.
  • add rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦞 diamond lobster.
  • add feature: ✨ showcase: ClawSweeper spotlight: unusually compelling feature idea for maintainer attention. A credential-free, gateway-owned SSH transport for ephemeral worker execution is an unusually strategic capability with strong operator value if the full design lands safely.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR provides fake-runner lifecycle tests and CI but no after-fix run on a real SSH worker; add redacted terminal/log or linked-artifact proof, update the PR body to trigger review, or ask a maintainer to comment @clawsweeper re-review.

Label justifications:

  • P2: The opt-in feature has limited current blast radius but materially changes gateway, plugin, protocol, and SSH security surfaces.
  • merge-risk: 🚨 security-boundary: Merging establishes host-key pinning, SSH identity resolution, reverse forwarding, and remote socket ownership contracts that green CI alone cannot validate.
  • rating: 🦪 silver shellfish: Overall readiness is 🦪 silver shellfish; proof is 🦪 silver shellfish and patch quality is 🦞 diamond lobster.
  • feature: ✨ showcase: ClawSweeper spotlight: unusually compelling feature idea for maintainer attention. A credential-free, gateway-owned SSH transport for ephemeral worker execution is an unusually strategic capability with strong operator value if the full design lands safely.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask. Needs real behavior proof before merge: The PR provides fake-runner lifecycle tests and CI but no after-fix run on a real SSH worker; add redacted terminal/log or linked-artifact proof, update the PR body to trigger review, or ask a maintainer to comment @clawsweeper re-review.
Evidence reviewed

PR surface:

Source +915, Tests +704, Docs +4, Generated 0, Other +11. Total +1634 across 37 files.

View PR surface stats
Area Files Added Removed Net
Source 19 1161 246 +915
Tests 10 710 6 +704
Docs 5 12 8 +4
Config 0 0 0 0
Generated 1 2 2 0
Other 2 13 2 +11
Total 37 1898 264 +1634

What I checked:

  • Tunnel lifecycle and fencing: The manager creates owner-only randomized remote socket directories, waits for a post-forward readiness marker, reconnects with bounded backoff, publishes replacement epochs before old teardown, aborts delayed work on stop, and cleans only the owning epoch's socket. (src/gateway/worker-environments/tunnel.ts:243, d73a12808224)
  • Gateway and service ownership: Gateway startup injects the tunnel manager and provider-aware identity resolver; the service releases its durable-state lock during connection, permits starts only for usable leases, and stops tunnels before provider destruction or service shutdown. (src/gateway/worker-environments/service.ts:391, d73a12808224)
  • Shared SSH security boundary: Bootstrap, tunnel control, and workspace commands share isolated pinned known_hosts and identity material, enforce public-key-only authentication, disable agent/X11 and multiplexing, and enable forwarding only for the tunnel process. (src/gateway/worker-environments/ssh.ts:92, d73a12808224)
  • Provider-owned identity contract: The optional WorkerProvider hook is authoritative when present, receives durable lease/profile context, validates its opaque lease-bound reference, and otherwise leaves existing providers on the generic SecretRef resolver. (src/gateway/worker-environments/identity.ts:32, d73a12808224)
  • Crabbox upstream contract: Crabbox current source exposes host, user, port, and client key path in StatusView but no authoritative host-key field, supporting the PR's intentional fail-closed behavior until the companion Crabbox change ships. (extensions/crabbox/src/crabbox-worker-provider.ts:529, d73a12808224)
  • OpenSSH upstream contract: OpenSSH stream-local listener setup unlinks before bind when requested, while remote listener cancellation closes the channel without unlinking the socket path, matching the manager-owned cleanup design. (src/gateway/worker-environments/tunnel.ts:295, d73a12808224)

Likely related people:

  • steipete: Introduced and carried the merged cloud-worker environment, provider, bootstrap, and current tunnel series across the central gateway, plugin, protocol, and Crabbox paths. (role: feature owner; confidence: high; commits: 90e465833b30, e681646834e6, 03cab2950525; files: src/gateway/worker-environments/service.ts, src/gateway/worker-environments/bootstrap.ts, src/plugins/types.ts)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

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.

How this review workflow works
  • 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.

@steipete
steipete merged commit 5ca46a6 into main Jul 11, 2026
186 of 195 checks passed
@steipete
steipete deleted the claude/cloud-workers-ssh-tunnel branch July 11, 2026 16:26
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

github-actions Bot pushed a commit to Desicool/openclaw that referenced this pull request Jul 12, 2026
… resolution (openclaw#104553)

* feat(cloud-workers): add pinned SSH tunnel runtime

* feat(crabbox): resolve cloud worker SSH identities

* docs(cloud-workers): document SSH tunnel contracts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

app: web-ui App: web-ui docs Improvements or additions to documentation extensions: crabbox feature: ✨ showcase ClawSweeper spotlight: unusually compelling feature idea for maintainer attention. gateway Gateway runtime maintainer Maintainer-authored PR merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P2 Normal backlog priority with limited blast radius. rating: 🦪 silver shellfish Thin PR readiness signal; proof, validation, or implementation needs work. scripts Repository scripts size: XL status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant