Skip to content

fix(secrets): route protected egress through Gateway env proxies - #178080

Merged
steipete merged 2 commits into
mainfrom
fix/secret-egress-proxy-env-upstream
Oct 20, 2026
Merged

steipete merged 2 commits into
mainfrom
fix/secret-egress-proxy-env-upstream

Conversation

@steipete

@steipete steipete commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #170145

What Problem This Solves

Fixes protected exec requests returning 502 when their destination is reachable only through the Gateway's environment proxy.

User Impact

Secret egress now honors the Gateway's HTTPS_PROXY/HTTP_PROXY and NO_PROXY, including loopback exclusions, for HTTPS requests, permitted loopback HTTP, and bypassHosts tunnels. No new configuration is required; restart the Gateway after changing its proxy environment. Connections remain direct when no proxy is configured.

Why This Change Was Made

The secret proxy previously used a direct HTTPS agent, direct HTTP requests, and direct bypass sockets. Reuse the existing Node env-proxy adapter and shared NO_PROXY owner, with Proxyline's CONNECT implementation for blind tunnels. This implements the maintainer product decision: “Honor env proxy (Recommended).”

Destination allowlists and secret bindings still authorize the destination before forwarding. HTTPS keeps substituted secrets inside destination TLS; blind tunnels never substitute. Per-grant TLS trust, connection ownership, and revocation remain intact, including cancellation while a proxy tunnel is pending.

Evidence

  • Source/history confirmation against main e20f553f4f88: direct forwarding originated in b9c6789560bc; 668eef75225b added the per-grant TLS pools retained here. That main revision still bypassed env routing in all three upstream paths.
  • Added routes HTTPS through $route (bypass=$bypass): real local proxy/origin fixtures cover HTTPS proxying, HTTP proxy fallback, loopback NO_PROXY, no-env direct routing, blind tunnels, successful substitution, and rejection of a destination-denied sentinel before opening another upstream connection.
  • Added routes loopback HTTP through HTTP_PROXY unless NO_PROXY excludes it: observes proxy requests and CIDR bypass at the actual forwarding boundary.
  • Changed-file oxlint, oxfmt, and whitespace checks passed. Codex branch autoreview: scoped-clean, no actionable P0–P2 findings. Hosted Codex review also completed with no findings on the published head.
  • PR CI is the test gate and covers the new routing regressions plus the existing egress authorization, substitution, lifecycle, and WebSocket tests and repository checks. Tests and typechecks were intentionally not run locally; live Gateway proof was intentionally skipped per maintainer policy. Exact-head CI run 39373365459 passed on 4af5cbeeb8df4065a3e747369e9c1052fda735df: 35 successful jobs, no failures. Per-file timings were not measured locally.
  • Simplification: no new dependency, config, env parser, or handshake implementation. Production +65/-20 (net +45), tests +100/-2, docs +2/-0. The necessary growth handles asynchronous blind-tunnel cancellation/errors and grant-owned proxy agents; no policy checks were removed to offset it.

@clawsweeper

clawsweeper Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

🦞👀
ClawSweeper picked this up.

Pull request received. I will update this pull request when review starts.

ClawSweeper review complete

ClawSweeper finished reviewing this revision. The review result is being finalized.

View the workflow run.

@steipete
steipete marked this pull request as ready for review October 20, 2026 05:09
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-20T05:13:38.482490Z 4af5cbe Draft marked ready
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Security sensitive changes

This maintainer PR changes sensitive security components.

No secops approval is required. This comment is informational because the PR author has Maintain or Admin access.

  • Current SHA: 4af5cbeeb8df4065a3e747369e9c1052fda735df
  • Maintainer: @steipete
  • Repository role: admin

These security sensitive changes were made:

  • src/secrets/egress-proxy/proxy-forward.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.
  • src/secrets/egress-proxy/proxy-server.ts: Controls credential persistence, secret resolution, or redaction. Check storage permissions, credential scope, and exposure in logs or responses.

Carefully review these changes before merging.

@openclaw-barnacle openclaw-barnacle Bot added docs Improvements or additions to documentation gateway Gateway runtime size: S labels Oct 20, 2026
@clawsweeper clawsweeper Bot added clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. P1 High-priority user-facing bug, regression, or broken workflow. merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. status: 📣 needs proof The PR needs real behavior proof before ClawSweeper can clear the contributor ask. and removed clawsweeper:intake:bug Preliminary submission classification; full source review pending. clawsweeper:intake:needs-environment Preliminary submission classification; full source review pending. clawsweeper:intake:needs-repro Preliminary submission classification; full source review pending. labels Oct 20, 2026
@clawsweeper

clawsweeper Bot commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Codex review: needs real behavior proof before merge.

What this changes

This PR routes protected egress through the Gateway’s existing environment proxies while preserving destination checks and grant-owned connections.

Example: The Gateway has HTTPS_PROXY=http://127.0.0.1:1055, and an HTTPS destination is reachable only through that proxy.

  • Before: A protected exec request dials the destination directly and returns 502.
  • After: The request uses an upstream CONNECT tunnel and substitutes the bound secret inside destination TLS.

Review scores

Measure Result What it means
Overall readiness 🦐 gold shrimp (3/6) Useful, focused implementation with successful exact-head CI and real transport fixtures, capped by unresolved authority evidence.
Proof confidence 🦐 gold shrimp (3/6) Real behavior proof is necessary before merge. See Before merge.
Patch quality 🦐 gold shrimp (3/6) Security review found an item that needs attention.

Product

Kind: Bug fix · Worth it: Yes · Fix scope: Complete
User problem: Protected exec requests return 502 when their destination is reachable only through the Gateway’s configured proxy.
Reason: The reported workflow failure is concrete, and the maintainer-authored direction resolves proxy inheritance using existing configuration and transport owners.

Merge readiness

⛔ Blocked before merge - 3 items remain

Keep open: this maintainer-authored PR addresses a verified routing defect with a focused change, and source review found no actionable introduced bug.

Priority: P1
Reviewed head: 4af5cbeeb8df4065a3e747369e9c1052fda735df

Before merge

  • Add real behavior proof - Authority-chain proof required: the real socket fixtures and exact-head CI support routing and destination denial, but do not exercise shared revocation during pending upstream CONNECT or queued credential delivery; provide a production-owner trace showing an allowed grant succeeds, a denied grant causes no destination request, and revocation before handshake release prevents destination payload while preserving an authorized sibling, with credentials and private endpoints redacted. After adding proof, update the PR body, then request a new review with @clawsweeper re-review. The PR author or someone with repository write access can request it.
  • Resolve security concern: Verify authority through asynchronous proxy establishment - The new CONNECT await and proxy-agent queues extend the interval between grant admission and upstream forwarding; the supplied scenarios demonstrate destination denial but do not show revoked grants remaining unable to send destination bytes after a held proxy handshake completes.
  • Resolve merge risk - The new asynchronous proxy hop carries grant-bound traffic, but final-effect fencing of pending handshakes and queued credentials after shared revocation remains unverified.

Findings

  • [medium] Verify authority through asynchronous proxy establishment — src/secrets/egress-proxy/proxy-server.ts:568

Tests

  • Missing end-to-end proof: Supply final-effect evidence for denied and revoked grants across the new pending-proxy path; the added regressions’ red-on-base run is also not shown.
Agent review details

How this fits together

The Gateway’s secret-egress Worker authenticates subprocess grants, checks destination bindings, substitutes sentinels, and forwards requests to upstream services.

flowchart LR
  A[Managed subprocess] --> B[Authenticated egress Worker]
  B --> C[Grant and destination checks]
  C --> D[Secret substitution]
  D --> E[Environment proxy routing]
  E --> F[Destination TLS service]
  C --> G[Blind bypass tunnel]
  G --> E
Loading

Technical review

Best possible solution:

Keep the existing routing adapters and grant lifecycle, with final-effect authority evidence covering the new upstream-proxy path.

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

Current-main source establishes direct dialing despite the Gateway proxy environment, and mogol supplies deployment controls and a successful local workaround; no target code was executed during this read-only review.

Is this the best way to solve the issue?

Reusing the existing environment-proxy adapter addresses the transport owner directly, preserves the shared NO_PROXY policy, and avoids another parser or handshake implementation.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning medium; reviewed against d97b12486899.

Merge-risk options

Maintainer options:

  1. Verify revocation across pending proxy connections (recommended)
    Exercise the real forwarding owner and transport with a held CONNECT response, revoke the grant before release, and show that no queued credential or tunnel payload reaches the destination while an authorized sibling still works.

Provenance checked

  • Authenticated upstream forwarding and destination binding changes intended behavior with a stated reason (b9c6789: Provide authenticated subprocess egress with destination-bound secret substitution; the original direct connection was transport implementation rather than an established requirement to bypass operator proxies.)
  • Per-grant TLS pools and socket authority checks keeps the original intent (668eef7: Reuse parsed trust and connections while preserving origin isolation, grant cleanup, and revocation checks before queued credentials are flushed.)
  • Literal loopback HTTP keeps the original intent (8b5c5dd: Keep loopback traffic under authentication and destination policy while refusing cleartext sentinel substitution.)
  • Shared HTTP and WebSocket forwarding owner keeps the original intent (0762f59: Share authorization, substitution, and resource ownership between HTTPS requests and WebSocket upgrades.)

Testing

Proof path: in-process harness.

Security

Needs attention: Source inspection preserves the security checks, but pending-proxy revocation needs final-effect evidence.

Evidence

Security concerns:

  • [medium] Verify authority through asynchronous proxy establishment — src/secrets/egress-proxy/proxy-server.ts:568
    The new CONNECT await and proxy-agent queues extend the interval between grant admission and upstream forwarding; the supplied scenarios demonstrate destination denial but do not show revoked grants remaining unable to send destination bytes after a held proxy handshake completes.
    Confidence: 0.94

What I checked:

PR surface

Source +45, Tests +98, Docs +2. Total +145 across 4 files. Added test files: 0.

View PR surface stats
Area Files Added Removed Net
Source 2 65 20 +45
Tests 1 100 2 +98
Docs 1 2 0 +2
Config 0 0 0 0
Generated 0 0 0 0
Other 0 0 0 0
Total 4 167 22 +145

Labels

Label changes:

  • add P1: The linked official-release report establishes that protected exec requests fail consistently on deployments whose destinations require the configured upstream proxy.
  • add merge-risk: 🚨 security-boundary: The change routes credential-bearing requests through new asynchronous transport paths whose pending-connection revocation behavior has not been demonstrated.
  • add rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • add status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Label justifications:

  • P1: The linked official-release report establishes that protected exec requests fail consistently on deployments whose destinations require the configured upstream proxy.
  • merge-risk: 🚨 security-boundary: The change routes credential-bearing requests through new asynchronous transport paths whose pending-connection revocation behavior has not been demonstrated.
  • rating: 🦐 gold shrimp: Overall readiness is 🦐 gold shrimp; proof is 🦐 gold shrimp and patch quality is 🦐 gold shrimp.
  • status: 📣 needs proof: The PR needs real behavior proof before ClawSweeper can clear the contributor ask.

Rank-up moves

Optional improvements that raise the rating; they are not merge blockers.

  • Add final-effect proof that denied and revoked grants cannot forward destination bytes through pending proxy connections, while an authorized sibling remains functional.

Rating scale

6/6 🦀 challenger crab · 5/6 🦞 diamond lobster · 4/6 🐚 platinum hermit · 3/6 🦐 gold shrimp · 2/6 🦪 silver shellfish · 1/6 🧂 unranked krab. Overall follows the weaker of proof and patch quality; ✨ marks media proof (a screenshot, video, or linked artifact) that directly shows the changed behavior.

Workflow

ClawSweeper edits this one comment on every review. Comment @clawsweeper re-review for a fresh review only. Repair and merge execution lanes are retired.

Reviewed October 20, 2026, 1:33 AM ET / 05:33 UTC.

@steipete
steipete merged commit e6a1ed1 into main Oct 20, 2026
216 of 219 checks passed
@steipete
steipete deleted the fix/secret-egress-proxy-env-upstream branch October 20, 2026 05:47
@steipete

Copy link
Copy Markdown
Contributor Author

Merged via squash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation gateway Gateway runtime merge-risk: 🚨 security-boundary 🚨 May affect sandboxing, authorization, credentials, or sensitive data. P1 High-priority user-facing bug, regression, or broken workflow. rating: 🦐 gold shrimp Decent PR readiness signal, but merge confidence is limited. security-sensitive-changed size: S 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.

[Bug]: Secret egress proxy ignores the Gateway's HTTPS_PROXY for upstream connections

1 participant