From 9c7da84c0e2373bdcfed8399338081a0e6494990 Mon Sep 17 00:00:00 2001 From: Thomas Kosiewski Date: Tue, 17 Nov 2026 01:35:16 +0000 Subject: [PATCH 1/2] fix(sync): send an upper-case http(s) scheme through the egress proxy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The pull and push lanes started the egress proxy only for a URL that began with a lower-case `http://` or `https://`. A link stored with an upper-case scheme (`HTTPS://`, `Https://`) skipped the proxy. Today git refuses such a link before any dial, because GIT_ALLOW_PROTOCOL compares transport names case-sensitively ("transport 'HTTPS' not allowed"), but the egress guard should not depend on that. viaEgressProxy matches the scheme case-insensitively, as RFC 3986 and curl read it, and both lanes use it. The new tests emulate a git that takes the transport (HTTP in GIT_ALLOW_PROTOCOL, git-remote-HTTP on PATH): on main both lanes dial the loopback upstream directly; now the strict policy refuses it in the proxy. Signed-off-by: Thomas Kosiewski --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_ Change-Id: I8b9f6c8ebc7db122c3b4a82e18a3024b11049cd3 Signed-off-by: Thomas Kosiewski --- internal/sync/egress.go | 11 +++ internal/sync/egress_scheme_test.go | 121 ++++++++++++++++++++++++++++ internal/sync/worker.go | 2 +- internal/sync/worker_push.go | 2 +- 4 files changed, 134 insertions(+), 2 deletions(-) create mode 100644 internal/sync/egress_scheme_test.go diff --git a/internal/sync/egress.go b/internal/sync/egress.go index f5b4dd14..61156e33 100644 --- a/internal/sync/egress.go +++ b/internal/sync/egress.go @@ -47,6 +47,17 @@ type egressProxy struct { dialErr string } +// viaEgressProxy reports whether url names an http or https upstream, +// whose transfer must dial through the egress proxy. A URL scheme is case +// insensitive (RFC 3986), and curl dials `HTTPS://` as https, so a stored +// `HTTPS://` link matches too. Today GIT_ALLOW_PROTOCOL refuses such a +// link before any dial (git compares transport names case-sensitively: +// "transport 'HTTPS' not allowed"), but the guard must not depend on it. +func viaEgressProxy(url string) bool { + scheme, _, ok := strings.Cut(url, "://") + return ok && (strings.EqualFold(scheme, "http") || strings.EqualFold(scheme, "https")) +} + func startEgressProxy(allowPrivate bool) (*egressProxy, error) { ln, err := net.Listen("tcp", "127.0.0.1:0") if err != nil { diff --git a/internal/sync/egress_scheme_test.go b/internal/sync/egress_scheme_test.go new file mode 100644 index 00000000..75ca18f3 --- /dev/null +++ b/internal/sync/egress_scheme_test.go @@ -0,0 +1,121 @@ +package sync + +import ( + "context" + "net/http" + "net/http/httptest" + "os" + "os/exec" + "path/filepath" + "strings" + "sync/atomic" + "testing" +) + +// TestViaEgressProxy: an http or https upstream URL needs the egress proxy +// whatever the letter case of its scheme; no other scheme does. +func TestViaEgressProxy(t *testing.T) { + for url, want := range map[string]bool{ + "http://forge.example/o/n.git": true, + "https://forge.example/o/n.git": true, + "HTTP://forge.example/o/n.git": true, + "HTTPS://forge.example/o/n.git": true, + "Https://forge.example/o/n.git": true, + "hTtP://forge.example/o/n.git": true, + "file:///srv/o/n.git": false, + "ssh://forge.example/o/n.git": false, + "httpx://forge.example/o/n.git": false, + "xhttps://forge.example/o.git": false, + "ext::sh -c true": false, + } { + if got := viaEgressProxy(url); got != want { + t.Errorf("viaEgressProxy(%q) = %v, want %v", url, got, want) + } + } +} + +// takeUpperCaseHTTP makes the worker's git take an `HTTP://` upstream: its +// GIT_ALLOW_PROTOCOL lists HTTP, and git finds a git-remote-HTTP helper, +// the real git-remote-http, as it would on a case-insensitive file system. +// The production default ("http:https") refuses the transport before any +// dial ("transport 'HTTP' not allowed"), so this is the only way a test +// sees where git would dial such a link. +func takeUpperCaseHTTP(t *testing.T, w *Worker) { + t.Helper() + out, err := exec.Command("git", "--exec-path").Output() + if err != nil { + t.Fatalf("git --exec-path: %v", err) + } + helper := filepath.Join(strings.TrimSpace(string(out)), "git-remote-http") + if _, err := os.Stat(helper); err != nil { + t.Fatalf("git http helper: %v", err) + } + bin := t.TempDir() + if err := os.Symlink(helper, filepath.Join(bin, "git-remote-HTTP")); err != nil { + t.Fatal(err) + } + t.Setenv("PATH", bin+string(os.PathListSeparator)+os.Getenv("PATH")) + w.AllowProtocol = "HTTP:" + w.AllowProtocol +} + +// unreachedServer is a loopback upstream that records whether anything +// reached it. +func unreachedServer(t *testing.T) (url string, reached *atomic.Bool) { + t.Helper() + reached = new(atomic.Bool) + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + reached.Store(true) + http.Error(w, "unreachable", http.StatusTeapot) + })) + t.Cleanup(srv.Close) + return srv.URL, reached +} + +// TestWorkerUpperCaseSchemeUpstreamDialsThroughProxy: a stored upstream +// whose scheme is upper case (`HTTP://`) fetches through the egress proxy +// like a lower-case one, so the strict policy refuses its loopback host +// and the upstream is never contacted. Before, only a lower-case scheme +// started the proxy, and a git that took the transport dialed the link +// directly. +func TestWorkerUpperCaseSchemeUpstreamDialsThroughProxy(t *testing.T) { + f := newWorkerFixture(t) + takeUpperCaseHTTP(t, f.worker) + f.worker.PullEgressAllowPrivate = false // strict policy + url, reached := unreachedServer(t) + f.putUpstream(t, "repo_uc", "own", "proj", "HTTP://"+strings.TrimPrefix(url, "http://")) + + if err := f.worker.Run(context.Background(), Job{Org: "acme", RepoID: "repo_uc"}); err == nil { + t.Fatal("Run succeeded against a policy-denied private upstream") + } + if reached.Load() { + t.Fatal("the HTTP:// upstream was dialed around the egress proxy") + } + events := f.rec.list() + assertEventTypes(t, events, EventSyncStarted, EventSyncFailed) + if events[1].Error != FailConfig { // a refused transport would be FailClone + t.Fatalf("error = %q, want %q", events[1].Error, FailConfig) + } +} + +// TestPushRunUpperCaseSchemeUpstreamDialsThroughProxy is the push lane's +// twin of TestWorkerUpperCaseSchemeUpstreamDialsThroughProxy. +func TestPushRunUpperCaseSchemeUpstreamDialsThroughProxy(t *testing.T) { + f := newWorkerFixture(t) + takeUpperCaseHTTP(t, f.worker) + f.worker.PushEgressAllowPrivate = false // production default + seedLocalRepo(t, f, "repo_ucp") + url, reached := unreachedServer(t) + f.putUpstream(t, "repo_ucp", "own", "proj", "HTTP://"+strings.TrimPrefix(url, "http://")) + + if err := f.worker.RunPush(context.Background(), Job{Org: "acme", RepoID: "repo_ucp"}); err == nil { + t.Fatal("RunPush succeeded against a policy-denied private upstream") + } + if reached.Load() { + t.Fatal("the HTTP:// upstream was dialed around the egress proxy") + } + events := f.rec.list() + assertEventTypes(t, events, EventPushUpstreamStarted, EventPushUpstreamFailed) + if events[1].Error != FailConfig { // a refused transport would be FailForward + t.Fatalf("error = %q, want %q", events[1].Error, FailConfig) + } +} diff --git a/internal/sync/worker.go b/internal/sync/worker.go index 8297ac21..ec38ff5a 100644 --- a/internal/sync/worker.go +++ b/internal/sync/worker.go @@ -785,7 +785,7 @@ func (w *Worker) transfer(ctx context.Context, job Job, repo RepoInfo, up Upstre // longer reach the upstream fetch: the guard dials destinations // directly, exactly like webhook delivery and push forwarding. var egress *egressProxy - if u := up.CloneURL(); strings.HasPrefix(u, "http://") || strings.HasPrefix(u, "https://") { + if viaEgressProxy(up.CloneURL()) { egress, err = startEgressProxy(w.PullEgressAllowPrivate) if err != nil { return &syncFailure{code: FailInternal, cause: err} diff --git a/internal/sync/worker_push.go b/internal/sync/worker_push.go index 038eed99..aabe9249 100644 --- a/internal/sync/worker_push.go +++ b/internal/sync/worker_push.go @@ -629,7 +629,7 @@ func (w *Worker) transferPush(ctx context.Context, job Job, repo RepoInfo, up Up // file:// upstreams (tests; GIT_ALLOW_PROTOCOL-blocked in production) // have no network egress to guard. var egress *egressProxy - if u := up.CloneURL(); strings.HasPrefix(u, "http://") || strings.HasPrefix(u, "https://") { + if viaEgressProxy(up.CloneURL()) { egress, err = startEgressProxy(w.PushEgressAllowPrivate) if err != nil { return nil, &syncFailure{code: FailInternal, cause: err} From 7dbf6db20996bd646f3d9a8a893420dd2f793c4b Mon Sep 17 00:00:00 2001 From: Thomas Kosiewski Date: Tue, 17 Nov 2026 01:44:39 +0000 Subject: [PATCH 2/2] chore: re-record the lane-schedule fingerprints MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit worker.go and worker_push.go are covered code: both lanes now decide on the egress proxy with viaEgressProxy. Signed-off-by: Thomas Kosiewski --- _Generated with [`xum`](https://github.com/coder/xum) • Model: `anthropic:claude-opus-5-5` • Thinking: `xhigh`_ Change-Id: I73f2e3e60cd0db8ed443b9ddb01710e8aedc6300 Signed-off-by: Thomas Kosiewski --- .agents/skills/verify-lane-schedule/SKILL.md | 2 +- .agents/skills/verify-lane-schedule/model/fingerprints.txt | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.agents/skills/verify-lane-schedule/SKILL.md b/.agents/skills/verify-lane-schedule/SKILL.md index ae63fe6d..cc7fb7d9 100644 --- a/.agents/skills/verify-lane-schedule/SKILL.md +++ b/.agents/skills/verify-lane-schedule/SKILL.md @@ -226,7 +226,7 @@ With every fact TRUE in the code, setting each fact FALSE in the model alone fai ## Coverage record -Sync commit: `2e98dad6dd886941543d266b99fed69d8b34b17d` (the last commit at which someone confirmed that the model describes this code; only `check.sh --record` moves it). +Sync commit: `9c7da84c0e2373bdcfed8399338081a0e6494990` (the last commit at which someone confirmed that the model describes this code; only `check.sh --record` moves it). Every declaration in these files is covered: diff --git a/.agents/skills/verify-lane-schedule/model/fingerprints.txt b/.agents/skills/verify-lane-schedule/model/fingerprints.txt index d11ce3d7..58a9cf42 100644 --- a/.agents/skills/verify-lane-schedule/model/fingerprints.txt +++ b/.agents/skills/verify-lane-schedule/model/fingerprints.txt @@ -776,7 +776,7 @@ internal/sync/worker.go:Worker.restoreForShutdown 9a0a6bce1769bf3b920ed6bb32fbad internal/sync/worker.go:Worker.restoreLocal 26a4d6afcb497aad19bf44a05a934271739a9f5589932177cf95572fd56304ff internal/sync/worker.go:Worker.retryFinish ffaeb07c443ff810394a4163e9bbba358e94167e2a862610fc85ea7cd04bb3ac internal/sync/worker.go:Worker.retryFinishWithin e5d50e3769f6ee0472f6f27eea02cb1f50b666bc32e18f95bc357ee6a270617c -internal/sync/worker.go:Worker.transfer 9a7214ab5245a9dff3f77236343915bd12d363e65d0a931d562ddb5aabe7046e +internal/sync/worker.go:Worker.transfer e2b636cde9e3f5280ce41a42be946fb00f8a363ed5b3cf174b6dd839fd5582ea internal/sync/worker.go:Worker.upstreamAuth f7c972b140b7e1c99a838e12a0874a06c59d8a1e56b1ad20ca51ad93acfdbac9 internal/sync/worker.go:Worker.waitPublication 5523b2acf8503a7d67b1c7a16ac8193b665e56cf2359c4b2c665712c2387079f internal/sync/worker.go:allLocalWins 2e1ed7ba97088a77c021e2f4b6814a936cd110f583795fddf5b52e55a198452a @@ -846,7 +846,7 @@ internal/sync/worker_push.go:Worker.RunPush 77bbe1edd8d5a5935bbca6f30c0017450137 internal/sync/worker_push.go:Worker.deferPendingPushRetry 7bf248bb135e0fbdbffd91fec3e0f56b87903684fc58ee1cdffbe058af433a65 internal/sync/worker_push.go:Worker.finishPush 6b4e06cf7bffdbcac72ced432007e68dcf586366783c4a52b50d085715cb58e4 internal/sync/worker_push.go:Worker.schedulePushRetry 7d6624eeb71fae525f515582bca5ecb8eca4d5c723a5db950b6e20f519bd9b42 -internal/sync/worker_push.go:Worker.transferPush 14bae9f7ac2107bde7a518e9004b5838733868fd52c84ec7127ed11936b9a618 +internal/sync/worker_push.go:Worker.transferPush bfae66f00a38a2e79765bf2cd3325bb0647b567b50f0689e91fc6b6db16fd6ce internal/sync/worker_push.go:const_MaxPushTransientRetries 42c201bde330462628aa7335deb7e991d94bd2bd7694de9ebad264a6933464b1 internal/sync/worker_push.go:const_defaultDetachPoll 652efd282a5ede53fe7f4bf7bb2aca47d000b78f442e2191d23121276b6b0534 internal/sync/worker_push.go:heldRefStale a105a5dae5878c6108dae79010890eede3abf564d7bcd4d24281e34abf63a3da