Skip to content

feat: runtime forward proxy rulesets for outbound egress routing - #248

Merged
goodtune merged 11 commits into
mainfrom
claude/forward-proxy-rulesets-akpkt9
Sep 24, 2026
Merged

goodtune merged 11 commits into
mainfrom
claude/forward-proxy-rulesets-akpkt9

Conversation

@goodtune

@goodtune goodtune commented Aug 15, 2026 •

Copy link
Copy Markdown
Owner

Summary

Outbound GitHub traffic keeps its existing default — the ambient environment (HTTPS_PROXY et al.) — but operators can now build forward proxy rulesets at runtime to deliberately steer GitHub-destined traffic across egress paths. Motivating case: CI fleets whose concentrated API/clone traffic gets an egress IP throttled or banned; splitting or pinning that traffic contains the blast radius.

What's included

Data model & storage

  • ForwardProxyRuleset (name, description, algorithm, proxy targets with weights, rules, enabled) with CRUD Store methods on all three backends (SQLite, Postgres, Vault) and migration 011_add_forward_proxy_rulesets (unique name index, algorithm CHECK constraint).
  • Contract test testForwardProxyRulesetCRUD covering every field, name uniqueness, rename, ErrNotFound paths.

Selection engine (internal/proxy/forwardproxy.go)

  • ForwardProxyRouter compiles enabled rulesets into an immutable route table; Reload swaps atomically.
  • Rule layers, most-specific first: client header → token → app → net (CIDR, longest prefix wins) → system → ambient environment.
  • Algorithms: round_robin (atomic counter), weighted (random over weight distribution, e.g. 80/20), sticky (FNV hash of client source IP over the weighted target list).
  • Fail-open: disabled rulesets, invalid URLs/CIDRs, or load failures skip with a warning and never block egress.

Control-plane routing

  • A control rule type routes ghp's own outbound calls — OAuth login flows and token refresh, App installation token minting, username resolution lookups — via a dedicated egress path. This is ghp's most important traffic: losing it to a banned egress IP takes down every client behind the proxy.
  • Control traffic resolves control → system → ambient; token/app/net layers never apply (not attributable to a client). A dedicated control transport is installed on the app registry, auth handler, and username resolver; OAuth refresh triggered inside a proxied request is re-classified so it doesn't inherit the client's routing.
  • Non-GitHub control destinations go direct by default. Release redirect HEAD probes target the operator's mirror, which is typically internal — they are sent with no proxy at all (not even ambient). Setting include_non_github: true on the control rule opts them into control-layer routing, giving non-GitHub domains the same treatment as GitHub targets.

Per-request client selection

  • With forward_proxy.allow_request_header: true (default false; GHP_FORWARD_PROXY_ALLOW_REQUEST_HEADER), a client may pick the forward proxy for a single request via X-GitHub-Proxy-Forward-HTTP/-HTTPS (http/https proxies) or X-GitHub-Proxy-Forward-SOCKS (socks5/socks5h). Use case: a team with its own egress (e.g. IP allow-listed on the far side) that only needs it on particular requests.
  • The client choice beats every ruleset layer while still flowing through ghp — scoping, audit logs, and metrics all apply. At most one proxy per request; invalid or conflicting values → 400; headers are always stripped before forwarding upstream. Counted in ghp_forward_proxy_client_specified_total{scheme,token_type} (proxy URL deliberately never a label).

Wiring

  • One shared http.Transport whose per-request Proxy function consults the router; installed on the API proxy, github.com passthrough, codeload, and Copilot backends — connection pools are kept per selected proxy.
  • Route info is seeded per request (client IP via server.client_ip_header) and enriched with token/app identity after token resolution in both the API handler and the git passthrough.

Runtime management

  • Admin-only CRUD at /api/forward-proxy-rulesets (list/create/get/PATCH/delete) following the repo's validation conventions (UUID checks, MaxBytesReader/413, pointer-based PATCH semantics, 409 on duplicate names).
  • Mutations reload the route table immediately; a periodic refresh (1 min) converges other instances in HA deployments.

Observability

  • New decision stage forward_proxy_selection, counters ghp_forward_proxy_select_total{ruleset,layer} (layer ∈ header/token/app/net/system/control/ambient/direct) and ghp_forward_proxy_client_specified_total{scheme,token_type}, gauge ghp_forward_proxy_rulesets_active — all with tests; CLAUDE.md metric tables updated.

Docs

  • New page docs/features/forward-proxy-rulesets.md (concepts, API examples, control-plane routing, per-request client selection, failure modes, known limitations), configuration reference, how-it-works summary, mkdocs nav.

Testing

  • go build ./..., go vet ./... clean.
  • New unit tests: router (precedence, CIDR specificity, all three algorithms, ambient fallback, reload swap, ProxyFunc context flow, control layer + control transport, non-GitHub direct default + opt-in, client-header extraction/validation/stripping and precedence), admin API handlers (CRUD, validation matrix, 404/400/409/413), metrics, SQLite store contract.
  • Full suite green except the Docker-based Postgres/Vault container tests, which cannot run in this sandbox (no Docker provider) — unrelated to this change; CI's SQLite path covers the store contract.

Known limitations

  • Round-robin/sticky state is per-instance; HA instances cycle independently.
  • Token/app rules require ghp-resolved tokens; raw-credential passthrough traffic is covered by net/system rules.
  • Admin-UI convenience lookups through the GitHub SDK (installation/repository listings) use the ambient environment; all request-path control calls follow control-layer routing, and release HEAD probes follow it only with include_non_github.

🤖 Generated with Claude Code

Deployments that generate heavy GitHub traffic (CI fleets in particular)
can get their egress IP throttled or banned. Forward proxy rulesets let
operators steer GitHub-destined traffic out through specific upstream
forward proxies at runtime, splitting or pinning load across egress paths.

- ForwardProxyRuleset model + CRUD store methods on all three backends
  (SQLite, Postgres, Vault) with migration 011 and contract tests.
- ForwardProxyRouter compiles enabled rulesets into an immutable route
  table and selects a proxy per outbound request via http.Transport.Proxy.
  Rule layers resolve most-specific first: token -> app -> net (CIDR,
  longest prefix) -> system -> ambient environment (ProxyFromEnvironment).
  Algorithms: round_robin, weighted, sticky (FNV hash of client IP over
  the weighted target list). Invalid targets/rules fail open to ambient.
- All outbound GitHub backends (API proxy, github.com passthrough,
  codeload, Copilot) share one router-driven transport; route info is
  seeded per request (client IP) and enriched after token resolution.
- Admin API: /api/forward-proxy-rulesets CRUD with validation, PATCH
  partial-update semantics, immediate route-table reload on mutation,
  and a periodic refresh for HA convergence.
- Metrics: forward_proxy_selection decision stage,
  ghp_forward_proxy_select_total{ruleset,layer},
  ghp_forward_proxy_rulesets_active gauge, with tests.
- Docs: features/forward-proxy-rulesets.md, how-it-works summary,
  CLAUDE.md metric tables.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MWmuf2JwYiQ5VFeXHPWHxG
@github-actions

github-actions Bot commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

✅ E2E Test Results — Passed

Total Passed Failed Skipped
135 135 0 0
Test Details
Test Browser Status Duration
admin-apps.spec.ts › Admin - Multi-App Management › admin page shows Apps section with empty state chromium ✅ Pass 0.8s
admin-apps.spec.ts › Admin - Multi-App Management › can create an app and form collapses after chromium ✅ Pass 1.1s
admin-apps.spec.ts › Admin - Multi-App Management › token sections appear after creating an app chromium ✅ Pass 0.8s
admin-apps.spec.ts › Admin - Multi-App Management › can edit an app via inline edit form chromium ✅ Pass 1.0s
admin-apps.spec.ts › Admin - Multi-App Management › edit form cancel closes without saving chromium ✅ Pass 0.8s
admin-apps.spec.ts › Admin - Multi-App Management › agent token fields hidden until app selected with multiple apps chromium ✅ Pass 0.7s
admin-apps.spec.ts › Admin - Multi-App Management › created app appears in the apps table with correct details chromium ✅ Pass 0.7s
admin-apps.spec.ts › Admin - Multi-App Management › can delete an app via the admin UI chromium ✅ Pass 0.8s
admin-apps.spec.ts › Admin - Multi-App Management › multiple apps appear in the apps table chromium ✅ Pass 0.8s
admin-apps.spec.ts › Admin - Multi-App Management › app selector is hidden when only one app exists chromium ✅ Pass 0.7s
admin-apps.spec.ts › Admin - Multi-App Management › app selector appears when multiple apps exist chromium ✅ Pass 0.8s
admin-apps.spec.ts › Admin - Multi-App Management › app selector auto-selects the default app chromium ✅ Pass 0.8s
admin-apps.spec.ts › Admin - Multi-App Management › admin page shows Apps section with empty state firefox ✅ Pass 1.7s
admin-apps.spec.ts › Admin - Multi-App Management › can create an app and form collapses after firefox ✅ Pass 1.3s
admin-apps.spec.ts › Admin - Multi-App Management › token sections appear after creating an app firefox ✅ Pass 0.9s
admin-apps.spec.ts › Admin - Multi-App Management › can edit an app via inline edit form firefox ✅ Pass 1.4s
admin-apps.spec.ts › Admin - Multi-App Management › edit form cancel closes without saving firefox ✅ Pass 1.8s
admin-apps.spec.ts › Admin - Multi-App Management › agent token fields hidden until app selected with multiple apps firefox ✅ Pass 0.9s
admin-apps.spec.ts › Admin - Multi-App Management › created app appears in the apps table with correct details firefox ✅ Pass 1.0s
admin-apps.spec.ts › Admin - Multi-App Management › can delete an app via the admin UI firefox ✅ Pass 1.3s
admin-apps.spec.ts › Admin - Multi-App Management › multiple apps appear in the apps table firefox ✅ Pass 1.0s
admin-apps.spec.ts › Admin - Multi-App Management › app selector is hidden when only one app exists firefox ✅ Pass 1.8s
admin-apps.spec.ts › Admin - Multi-App Management › app selector appears when multiple apps exist firefox ✅ Pass 1.0s
admin-apps.spec.ts › Admin - Multi-App Management › app selector auto-selects the default app firefox ✅ Pass 1.0s
admin-apps.spec.ts › Admin - Multi-App Management › admin page shows Apps section with empty state webkit ✅ Pass 1.6s
admin-apps.spec.ts › Admin - Multi-App Management › can create an app and form collapses after webkit ✅ Pass 2.6s
admin-apps.spec.ts › Admin - Multi-App Management › token sections appear after creating an app webkit ✅ Pass 1.3s
admin-apps.spec.ts › Admin - Multi-App Management › can edit an app via inline edit form webkit ✅ Pass 2.3s
admin-apps.spec.ts › Admin - Multi-App Management › edit form cancel closes without saving webkit ✅ Pass 1.3s
admin-apps.spec.ts › Admin - Multi-App Management › agent token fields hidden until app selected with multiple apps webkit ✅ Pass 1.2s
admin-apps.spec.ts › Admin - Multi-App Management › created app appears in the apps table with correct details webkit ✅ Pass 1.2s
admin-apps.spec.ts › Admin - Multi-App Management › can delete an app via the admin UI webkit ✅ Pass 1.5s
admin-apps.spec.ts › Admin - Multi-App Management › multiple apps appear in the apps table webkit ✅ Pass 1.2s
admin-apps.spec.ts › Admin - Multi-App Management › app selector is hidden when only one app exists webkit ✅ Pass 1.1s
admin-apps.spec.ts › Admin - Multi-App Management › app selector appears when multiple apps exist webkit ✅ Pass 1.2s
admin-apps.spec.ts › Admin - Multi-App Management › app selector auto-selects the default app webkit ✅ Pass 1.2s
admin-apps.spec.ts › Admin - App API endpoints › GET /api/apps returns empty array when no apps exist chromium ✅ Pass 0.1s
admin-apps.spec.ts › Admin - App API endpoints › POST /api/apps creates an app and returns it chromium ✅ Pass 0.0s
admin-apps.spec.ts › Admin - App API endpoints › GET /api/apps/{id} returns app details chromium ✅ Pass 0.1s
admin-apps.spec.ts › Admin - App API endpoints › DELETE /api/apps/{id} removes the app chromium ✅ Pass 0.1s
admin-apps.spec.ts › Admin - App API endpoints › POST /api/apps rejects missing required fields chromium ✅ Pass 0.0s
admin-apps.spec.ts › Admin - App API endpoints › app API endpoints require admin role chromium ✅ Pass 0.0s
admin-apps.spec.ts › Admin - App API endpoints › GET /api/apps returns empty array when no apps exist firefox ✅ Pass 0.1s
admin-apps.spec.ts › Admin - App API endpoints › POST /api/apps creates an app and returns it firefox ✅ Pass 0.0s
admin-apps.spec.ts › Admin - App API endpoints › GET /api/apps/{id} returns app details firefox ✅ Pass 0.1s
admin-apps.spec.ts › Admin - App API endpoints › DELETE /api/apps/{id} removes the app firefox ✅ Pass 0.1s
admin-apps.spec.ts › Admin - App API endpoints › POST /api/apps rejects missing required fields firefox ✅ Pass 0.0s
admin-apps.spec.ts › Admin - App API endpoints › app API endpoints require admin role firefox ✅ Pass 0.0s
admin-apps.spec.ts › Admin - App API endpoints › GET /api/apps returns empty array when no apps exist webkit ✅ Pass 0.1s
admin-apps.spec.ts › Admin - App API endpoints › POST /api/apps creates an app and returns it webkit ✅ Pass 0.1s
admin-apps.spec.ts › Admin - App API endpoints › GET /api/apps/{id} returns app details webkit ✅ Pass 0.1s
admin-apps.spec.ts › Admin - App API endpoints › DELETE /api/apps/{id} removes the app webkit ✅ Pass 0.1s
admin-apps.spec.ts › Admin - App API endpoints › POST /api/apps rejects missing required fields webkit ✅ Pass 0.1s
admin-apps.spec.ts › Admin - App API endpoints › app API endpoints require admin role webkit ✅ Pass 0.1s
auth-api.spec.ts › Auth API › GET /auth/status returns unauthenticated without session chromium ✅ Pass 0.0s
auth-api.spec.ts › Auth API › GET /auth/status returns authenticated with session chromium ✅ Pass 0.0s
auth-api.spec.ts › Auth API › GET /auth/github redirects to GitHub OAuth chromium ✅ Pass 0.0s
auth-api.spec.ts › Auth API › POST /auth/logout clears session chromium ✅ Pass 0.0s
auth-api.spec.ts › Auth API › API endpoints require authentication chromium ✅ Pass 0.0s
auth-api.spec.ts › Auth API › GET /auth/status returns unauthenticated without session firefox ✅ Pass 0.0s
auth-api.spec.ts › Auth API › GET /auth/status returns authenticated with session firefox ✅ Pass 0.0s
auth-api.spec.ts › Auth API › GET /auth/github redirects to GitHub OAuth firefox ✅ Pass 0.0s
auth-api.spec.ts › Auth API › POST /auth/logout clears session firefox ✅ Pass 0.5s
auth-api.spec.ts › Auth API › API endpoints require authentication firefox ✅ Pass 0.0s
auth-api.spec.ts › Auth API › GET /auth/status returns unauthenticated without session webkit ✅ Pass 0.0s
auth-api.spec.ts › Auth API › GET /auth/status returns authenticated with session webkit ✅ Pass 0.1s
auth-api.spec.ts › Auth API › GET /auth/github redirects to GitHub OAuth webkit ✅ Pass 0.0s
auth-api.spec.ts › Auth API › POST /auth/logout clears session webkit ✅ Pass 0.1s
auth-api.spec.ts › Auth API › API endpoints require authentication webkit ✅ Pass 0.0s
dashboard.spec.ts › Dashboard - no apps configured › hides token sections when no apps exist chromium ✅ Pass 0.8s
dashboard.spec.ts › Dashboard - no apps configured › hides token sections when no apps exist firefox ✅ Pass 1.0s
dashboard.spec.ts › Dashboard - no apps configured › hides token sections when no apps exist webkit ✅ Pass 1.1s
dashboard.spec.ts › Dashboard › renders dashboard with user info chromium ✅ Pass 0.4s
dashboard.spec.ts › Dashboard › shows Create Token section with form fields chromium ✅ Pass 0.2s
dashboard.spec.ts › Dashboard › shows Active Tokens section chromium ✅ Pass 0.2s
dashboard.spec.ts › Dashboard › duration dropdown has expected options chromium ✅ Pass 0.3s
dashboard.spec.ts › Dashboard › renders dashboard with user info firefox ✅ Pass 0.5s
dashboard.spec.ts › Dashboard › shows Create Token section with form fields firefox ✅ Pass 0.4s
dashboard.spec.ts › Dashboard › shows Active Tokens section firefox ✅ Pass 0.4s
dashboard.spec.ts › Dashboard › duration dropdown has expected options firefox ✅ Pass 0.4s
dashboard.spec.ts › Dashboard › renders dashboard with user info webkit ✅ Pass 1.3s
dashboard.spec.ts › Dashboard › shows Create Token section with form fields webkit ✅ Pass 0.8s
dashboard.spec.ts › Dashboard › shows Active Tokens section webkit ✅ Pass 0.7s
dashboard.spec.ts › Dashboard › duration dropdown has expected options webkit ✅ Pass 0.8s
dashboard.spec.ts › Dashboard - multi-app selection › requires app selection before showing token form with multiple apps chromium ✅ Pass 0.8s
dashboard.spec.ts › Dashboard - multi-app selection › auto-selects and shows form with single app chromium ✅ Pass 0.7s
dashboard.spec.ts › Dashboard - multi-app selection › requires app selection before showing token form with multiple apps firefox ✅ Pass 1.0s
dashboard.spec.ts › Dashboard - multi-app selection › auto-selects and shows form with single app firefox ✅ Pass 0.9s
dashboard.spec.ts › Dashboard - multi-app selection › requires app selection before showing token form with multiple apps webkit ✅ Pass 1.3s
dashboard.spec.ts › Dashboard - multi-app selection › auto-selects and shows form with single app webkit ✅ Pass 1.2s
login.spec.ts › Login page › renders the login page with branding chromium ✅ Pass 0.2s
login.spec.ts › Login page › displays the build version beneath the login form chromium ✅ Pass 0.1s
login.spec.ts › Login page › has a Sign in with GitHub button linking to OAuth chromium ✅ Pass 0.1s
login.spec.ts › Login page › unauthenticated root redirects to login chromium ✅ Pass 0.1s
login.spec.ts › Login page › renders the login page with branding firefox ✅ Pass 0.3s
login.spec.ts › Login page › displays the build version beneath the login form firefox ✅ Pass 0.3s
login.spec.ts › Login page › has a Sign in with GitHub button linking to OAuth firefox ✅ Pass 1.4s
login.spec.ts › Login page › unauthenticated root redirects to login firefox ✅ Pass 0.4s
login.spec.ts › Login page › renders the login page with branding webkit ✅ Pass 0.7s
login.spec.ts › Login page › displays the build version beneath the login form webkit ✅ Pass 0.5s
login.spec.ts › Login page › has a Sign in with GitHub button linking to OAuth webkit ✅ Pass 0.5s
login.spec.ts › Login page › unauthenticated root redirects to login webkit ✅ Pass 0.5s
logout.spec.ts › Logout › sign out button logs user out and redirects to login chromium ✅ Pass 0.5s
logout.spec.ts › Logout › sign out button logs user out and redirects to login firefox ✅ Pass 0.6s
logout.spec.ts › Logout › sign out button logs user out and redirects to login webkit ✅ Pass 1.5s
tokens.spec.ts › Token management › can create an open-scoped token (no repos, no permissions) chromium ✅ Pass 1.1s
tokens.spec.ts › Token management › can create a scoped token with repository and permissions chromium ✅ Pass 1.1s
tokens.spec.ts › Token management › can create a token with multiple repositories chromium ✅ Pass 1.0s
tokens.spec.ts › Token management › created token appears in the Active Tokens list chromium ✅ Pass 0.8s
tokens.spec.ts › Token management › can revoke a token chromium ✅ Pass 1.0s
tokens.spec.ts › Token management › repo select uses multi mode chromium ✅ Pass 0.7s
tokens.spec.ts › Token management › form labels indicate optional fields chromium ✅ Pass 0.2s
tokens.spec.ts › Token management › permission select loads from API and shows available scopes chromium ✅ Pass 0.7s
tokens.spec.ts › Token management › permission select respects API-returned scope restrictions chromium ✅ Pass 0.7s
tokens.spec.ts › Token management › can create a scoped token with pull_requests permission chromium ✅ Pass 1.0s
tokens.spec.ts › Token management › can create an open-scoped token (no repos, no permissions) firefox ✅ Pass 1.2s
tokens.spec.ts › Token management › can create a scoped token with repository and permissions firefox ✅ Pass 1.2s
tokens.spec.ts › Token management › can create a token with multiple repositories firefox ✅ Pass 1.1s
tokens.spec.ts › Token management › created token appears in the Active Tokens list firefox ✅ Pass 1.0s
tokens.spec.ts › Token management › can revoke a token firefox ✅ Pass 1.2s
tokens.spec.ts › Token management › repo select uses multi mode firefox ✅ Pass 0.9s
tokens.spec.ts › Token management › form labels indicate optional fields firefox ✅ Pass 0.4s
tokens.spec.ts › Token management › permission select loads from API and shows available scopes firefox ✅ Pass 1.9s
tokens.spec.ts › Token management › permission select respects API-returned scope restrictions firefox ✅ Pass 0.9s
tokens.spec.ts › Token management › can create a scoped token with pull_requests permission firefox ✅ Pass 1.1s
tokens.spec.ts › Token management › can create an open-scoped token (no repos, no permissions) webkit ✅ Pass 2.6s
tokens.spec.ts › Token management › can create a scoped token with repository and permissions webkit ✅ Pass 2.6s
tokens.spec.ts › Token management › can create a token with multiple repositories webkit ✅ Pass 2.0s
tokens.spec.ts › Token management › created token appears in the Active Tokens list webkit ✅ Pass 1.3s
tokens.spec.ts › Token management › can revoke a token webkit ✅ Pass 1.8s
tokens.spec.ts › Token management › repo select uses multi mode webkit ✅ Pass 1.0s
tokens.spec.ts › Token management › form labels indicate optional fields webkit ✅ Pass 0.6s
tokens.spec.ts › Token management › permission select loads from API and shows available scopes webkit ✅ Pass 1.1s
tokens.spec.ts › Token management › permission select respects API-returned scope restrictions webkit ✅ Pass 1.1s
tokens.spec.ts › Token management › can create a scoped token with pull_requests permission webkit ✅ Pass 2.0s

📸 Screenshots & report: Download artifacts
📊 Workflow run: View details

Run #746 · 2026-09-17 00:13:17 UTC

claude added 4 commits August 15, 2026 01:11
ghp's own outbound calls — OAuth login flows and token refresh, GitHub App
installation token minting, username resolution lookups, and release
redirect HEAD probes — are some of the most important traffic it emits:
losing them to a banned egress IP takes down every client behind the
proxy. Give operators the ability to pin this control traffic to its own
egress path instead of always using the ambient environment.

- New rule type "control" (no value, like "system"). Control traffic
  resolves control rule -> system rule -> ambient; token/app/net layers
  never apply since control calls are not attributable to a client.
- NewForwardProxyControlTransport routes every request as control; it is
  installed on the app registry (and config-fallback provider), the auth
  handler's OAuth client, the username resolver, and the release HEAD
  probe client via new SetTransport hooks / an optional transport arg.
- OAuth token refresh triggered inside a proxied request is re-classified
  via WithForwardProxyControl so it no longer inherits the triggering
  client's token/app/net routing.
- Admin API accepts "control" rules (value must be empty); docs, metric
  label docs, and CLAUDE.md updated; router/API/metrics tests extended.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MWmuf2JwYiQ5VFeXHPWHxG
Release redirect HEAD probes target the operator's redirect mirror, not
GitHub, and mirrors are typically internal — routing them through a
GitHub egress proxy by default is the wrong assumption. Send them DIRECT
(no proxy at all, not even the ambient environment) and let operators
opt them into control-layer routing explicitly.

- ForwardProxyRule gains include_non_github (JSON-stored, no migration),
  valid only on control rules. When true, control calls targeting
  non-GitHub hosts follow the control ruleset like GitHub-destined
  control traffic; when false or absent they are sent direct.
- New NewForwardProxyNonGitHubControlTransport installed on the release
  HEAD-probe client; new "direct" layer label on
  ghp_forward_proxy_select_total for observability.
- API validation rejects include_non_github on non-control rules; store
  contract, router, API, and metrics tests extended; docs updated.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MWmuf2JwYiQ5VFeXHPWHxG
…ders

A team may know something the operator's rules can't express — their own
egress path with IP allow-listing on the far side, needed only for
particular requests. Let clients select the upstream forward proxy per
request while still flowing through ghp, so scoping, audit logging, and
metrics all apply.

- Headers: X-GitHub-Proxy-Forward-HTTP / -HTTPS (http/https proxy URLs,
  aliases) and X-GitHub-Proxy-Forward-SOCKS (socks5/socks5h). At most one
  proxy per request; conflicting or invalid values return 400. The
  headers are always stripped before forwarding upstream.
- Gated system-wide by forward_proxy.allow_request_header (default
  false / GHP_FORWARD_PROXY_ALLOW_REQUEST_HEADER): honouring the headers
  lets a client direct ghp to connect to an arbitrary proxy endpoint, so
  operators must opt in. When disabled the headers are stripped silently.
- A client-specified proxy beats every ruleset layer; recorded as
  layer="header" in ghp_forward_proxy_select_total plus a dedicated
  ghp_forward_proxy_client_specified_total{scheme,token_type} counter
  (the proxy URL itself is never a label — client-controlled).
- Docs: feature page section, configuration reference, CLAUDE.md; tests
  for extraction/validation/stripping, precedence, and metrics.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MWmuf2JwYiQ5VFeXHPWHxG
Findings from the five-persona precommit-review skill (added here as
.claude/skills/precommit-review/SKILL.md, adapted to ghp):

- [blocker] GHP_FORWARD_PROXY_ALLOW_REQUEST_HEADER was documented but
  inert: the env TransformFunc splits sections at the first underscore
  and had no "forward" case, so the key never mapped to
  forward_proxy.allow_request_header. Add the mapping + regression test.
- [major] Client-specified proxy headers are now honoured only after a
  ghx_/gha_ token has resolved. Without the gate, an unauthenticated
  caller on the passthrough path could use the header to make ghp dial
  arbitrary internal host:port targets (SSRF/port-scan).
- [major] usernameResolver.SetTransport ran after WarmCache had spawned
  background GraphQL lookups — an unsynchronized transport write racing
  in-flight requests, and warm-cache traffic bypassed control routing.
  Transports are now installed immediately after construction.
- [minor] Reload no longer logs rejected proxy target URLs verbatim
  (targets may embed userinfo credentials); log the redacted form.
- [minor] Stale comments/docs from the direct-by-default change fixed
  (server wiring comment, NewReleasesHandler godoc, how-it-works
  summary); CLAUDE.md stage row now covers control-plane selections.
- [minor] Route-info middleware extracted to a named function with
  tests (400 on invalid header, strip-when-disabled, IP seeding); new
  tests for PATCH proxies:[] rejection, StartRefresh, IPv6 net rules,
  and the header auth gate.
- [minor] Vault name-uniqueness create/rename race documented as a
  known limitation (check-then-write, no CAS) per the Vault backend
  conventions; token/app rule values documented as opaque references
  that dangle after the referenced record is deleted.

Deferred deliberately: replacing the substring-based duplicate-name
409 mapping with a store-level sentinel (architecture/portability
minor) — it matches the existing cached-repositories pattern; aligning
both belongs in a dedicated refactor per the CLAUDE.md convention of
fixing patterns as they are touched repo-wide.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MWmuf2JwYiQ5VFeXHPWHxG

@goodtune goodtune left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Found five issues that should be addressed before merge. Four are annotated inline. One additional control-plane issue cannot be anchored because internal/proxy/enterprise.go is not part of GitHub's current PR diff:

[P2] Route team membership checks through control egress. newTeamChecker still constructs an http.Client with the default transport at internal/proxy/enterprise.go:326. In deployments where direct GitHub egress is unavailable or disallowed, installation-token minting follows control routing but the membership GET bypasses it, fails closed, and caches a false verdict for five minutes. Inject the control transport so membership checks select control → system as required by CLAUDE.md:88-102.

Comment thread internal/server/server.go Resolved
Comment thread internal/server/server.go Resolved
Comment thread internal/database/vault.go Resolved
Comment thread internal/database/models.go Resolved
Five findings from the owner's review of #248:

- [P1] Cached-repo git traffic now follows ruleset egress selection:
  gitcache.Handler gains SetTransport and the server installs the shared
  forward proxy transport. Upstream ls-refs/fetch requests already carry
  the inbound request context, so seeded route info (client IP + resolved
  token/app identity) selects layers exactly like the raw passthrough.
- [P1] GHE-style API paths on the management host (/api/v3/*,
  /api/graphql via mux) now pass through forwardProxyRouteInfoMiddleware;
  previously they bypassed host-dispatch wrapping and silently fell back
  to ambient egress.
- [P2] Enterprise team membership checks route via the control layer:
  EnterprisePolicy gains SetTransport (installed with the control
  transport) so membership GETs follow control -> system instead of
  dialing GitHub directly and caching a false negative for five minutes
  in proxy-only deployments.
- [P2] Vault ruleset create/rename now claims the by-name index first
  with an atomic KV v2 CAS create and rolls the claim back if the record
  write fails — no sequence leaves a listed record without an index, and
  a transient failure no longer manufactures a phantom duplicate on
  retry. The known-limitations doc entry is updated accordingly.
- [P2] GetForwardProxyRulesetByID returns wrapped database.ErrNotFound
  on all three backends per the sentinel-error convention; the API maps
  it to 404 via errors.Is, Vault's read-style ByName/List lookups
  tolerate stale index entries, and contract tests assert the sentinel.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MWmuf2JwYiQ5VFeXHPWHxG

Copy link
Copy Markdown
Owner Author

All five review findings addressed in 06f9345:

  • [P1] Cached git traffic — gitcache.Handler gains SetTransport; the server installs the shared ruleset transport. Upstream ls-refs/fetch requests are built with the inbound request context, so seeded route info (client IP + resolved token/app identity) drives layer selection exactly like the raw passthrough.
  • [P1] Management-host proxy paths — the /api/v3/* and /api/graphql mux registrations are now wrapped with forwardProxyRouteInfoMiddleware, so GHE-style requests on the management host get full ruleset selection instead of falling back to ambient.
  • [P2] Team membership checks — EnterprisePolicy.SetTransport installs the control transport on the team checker's client, so membership GETs follow control → system routing.
  • [P2] Vault partial creation — create/rename now claims the by-name index first via an atomic KV v2 CAS create (kvCreate, cas=0) and rolls the claim back if the record write fails. No sequence leaves a listed record without an index, and a transient failure can no longer manufacture a phantom duplicate on retry; this also closes the previously documented concurrent-create race, and the known-limitations doc is updated.
  • [P2] ErrNotFound sentinel — GetForwardProxyRulesetByID returns wrapped database.ErrNotFound on all three backends; the API maps it to 404 via errors.Is, Vault's read-style ByName/List lookups tolerate stale index entries, and the contract tests assert the sentinel. GetForwardProxyRulesetByName intentionally stays (nil, nil)-for-missing as an existence probe used by duplicate checks.

Build, vet, and go test -race green locally across the affected packages (Docker-based Postgres/Vault container tests excepted, as before).


Generated by Claude Code

claude and others added 5 commits August 16, 2026 20:03
NewEnterprisePolicy returns nil when github.enterprise_slug is empty
(the feature-disabled default, including the E2E environment), and the
server now calls SetTransport unconditionally — crashing the server at
startup with a nil pointer dereference. Guard the nil receiver and the
nil team checker, with a regression test covering both plus the
enabled-without-identity case.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MWmuf2JwYiQ5VFeXHPWHxG
…ault name index

Three review findings on the forward proxy ruleset work.

HTTP/2 connection reuse defeated per-request routing. http.Transport
consults Proxy only when it dials; once a destination negotiates HTTP/2,
Go's bundled h2 transport pools connections by authority alone, so every
later request to that host rode the first request's proxy — ignoring token
rules, client-specified proxies and ruleset reloads. Reproduced: four
HTTP/2 requests, one Proxy call. The transport constructors now return a
routingTransport that resolves the proxy per request and dispatches to an
http.Transport dedicated to that proxy, so HTTP/2 and connection pooling
survive while each egress path keeps its own pool. The cache is bounded
(client-specified proxies are caller-controlled) and evicts with idle
connections closed. Applied to all three constructors, including control.

Vault delete released the name reservation before deleting the record, so
a failed record delete left a live ruleset whose name was free to claim —
two rulesets under one supposedly unique name. Record is deleted first
now, and index-cleanup failures are reported rather than swallowed.

Vault rename overwrote the record unconditionally, so concurrent renames
A->B and A->C could both claim their destination and both write; the loser
left its name reserved forever. Updates now write with a compare-and-set on
the record version read at the start, releasing the claim on conflict. Adds
kvReadVersioned/kvWriteCAS alongside kvCreate, both withRelogin-wrapped and
context-propagating. Lookups now reject index entries whose record no
longer bears the name, and create reclaims a demonstrably stale
reservation via CAS, so a failed cleanup is recoverable rather than
permanent.

Tests: HTTP/2 per-request selection regression, transport-per-proxy and
cache bound, kvVersionOf shapes, name reuse after delete in the store
contract. Docs updated.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MWmuf2JwYiQ5VFeXHPWHxG
@goodtune
goodtune marked this pull request as ready for review September 17, 2026 00:08
Copilot AI lite review requested due to automatic review settings September 17, 2026 00:08

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@goodtune
goodtune merged commit 88d6ddc into main Sep 24, 2026
3 checks passed
@goodtune
goodtune deleted the claude/forward-proxy-rulesets-akpkt9 branch September 24, 2026 01:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants