Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .agents/skills/verify-lane-schedule/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
4 changes: 2 additions & 2 deletions .agents/skills/verify-lane-schedule/model/fingerprints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions internal/sync/egress.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
121 changes: 121 additions & 0 deletions internal/sync/egress_scheme_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
2 changes: 1 addition & 1 deletion internal/sync/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion internal/sync/worker_push.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Loading