Draft: feat(df): enforce the Dependency Firewall for Go via a local GOPROXY server
Description
On macOS, go and git consult only the system trust store, so the CA the Dependency Firewall's MITM proxy mints is rejected and glab df go cannot work at all — installing that CA needs sudo security add-trusted-cert, which is unacceptable locally and impossible in CI.
This replaces the enforcement mechanism for Go only. glab df now starts a small HTTP server that speaks the Go module proxy protocol on loopback and points the child at it with GOPROXY. Plain HTTP means no certificate is involved, so the trust-store problem disappears entirely. The other 12 package managers are untouched and keep using the MITM proxy.
Point of interception
GOPROXY. The child go asks our server for each module instead of proxy.golang.org:
go --GOPROXY--> gomodproxy.Server --.zip?--> firewall policy --allowed--> goproxy --> proxy.golang.org
\--blocked--> 403Coordinates come straight out of the request path — /<module>/@v/<version>.zip — so no body parsing or sniffing is needed:
| Where | What |
|---|---|
internal/dependencyfirewall/gomodproxy/request.go |
parseRequest splits the path on /@ (@ is illegal in a module path) and unescapes with x/mod/module, giving module + version. |
internal/dependencyfirewall/gomodproxy/gomodproxy.go |
Server.handle routes; Server.check builds policy.Request{Coordinate{Ecosystem: "golang", Name, Version}, ProjectID, Download} — the same request the MITM path already sends, so nothing changes firewall-side. |
internal/dependencyfirewall/pm/pm.go |
A new optional sidecar seam starts the server after the proxy and stops it before verdicts are snapshotted. Managers that don't implement it are unaffected. |
Only .zip is checked. A single go get issues ~13 .mod requests against one .zip: .mod drives version resolution across the whole graph, including modules that are never built, and go also probes path prefixes (/github.com/@v/list) with no version to check at all. Gating metadata would multiply policy calls and could fail a build over a module whose code never ships. The zip is where source actually crosses the boundary, and it matches what proxy.GoMatcher already matches on the MITM path.
Verifying it
The proxy variable is set on the child, and nothing else:
$ glab df go env GOPROXY
http://127.0.0.1:50654
$ go env GOPROXY # outside glab df, unchanged
https://proxy.golang.org,directAn allowed install goes through normally:
$ glab df go install github.com/rakyll/hey@v0.1.4
go: downloading github.com/rakyll/hey v0.1.4
$ ls $(go env GOBIN)
heyA blocked one fails before any code lands, with the firewall's reason surfaced by go itself:
glab df go install golang.org/x/net@v0.0.0-20181017193950-04a2e542c03f
go: downloading golang.org/x/net v0.0.0-20181017193950-04a2e542c03f
go: golang.org/x/net@v0.0.0-20181017193950-04a2e542c03f: golang.org/x/net@v0.0.0-20181017193950-04a2e542c03f: reading http://127.0.0.1:50791/golang.org/x/net/@v/v0.0.0-20181017193950-04a2e542c03f.zip: 403 Forbidden
server response:
blocked by the GitLab Dependency Firewall: golang.org/x/net@v0.0.0-20181017193950-04a2e542c03f
reason: Package 'golang.org/x/net' violates 'DepFw - Block high-severity vulnerabilities' policy
╭───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ ✖ GitLab Dependency Firewall │
│ 1 package blocked │
├───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤
│ PACKAGE VERSION REASON │
│ ✖ golang.org/x/net v0.0.0-20181017193950-04a2e542c03f Package 'golang.org/x/net' violates 'DepFw - Block high-severity vulnerabilities' policy │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯No binary is installed and the exit code is non-zero.
Why 403, and why GOPROXY names only our server
cmd/go treats only 404 and 410 as "not here, try the next source"; every other non-200 is terminal. A 404 on a blocked module would silently fall through and fetch it anyway. The refusal is also text/plain within cmd/go's 8-line/648-byte error-detail window, because go discards a body with any other content type — which is why the reason above is visible at all.
GOPROXY is our server alone: no ,direct (falls through on 404/410) and no | (falls through on any error).
Fail-open routes closed
GONOPROXY and GONOSUMDB are pinned to none, not the empty string — cmd/go falls back to the go env file when a variable is empty, so anyone who had run go env -w GOPRIVATE=… would otherwise keep a live direct-from-VCS bypass with no check and no verdict. NO_PROXY exempts loopback, since pm.Run points HTTP(S)_PROXY at the CONNECT-only MITM proxy, which would 405 our plain-HTTP request.
New dependency
github.com/goproxy/goproxy (MIT), plus golang.org/x/mod promoted to a direct build dependency. The stdlib has no GOPROXY protocol implementation and no existing dependency provides one. proxy.golang.org handles version resolution, pseudo-versions and zip construction, but not /sumdb/… — a hand-rolled reverse proxy would need a second upstream for it and would still miss modules the mirror won't serve. Build footprint is goproxy, x/mod and aofei/backoff; minio-go and cobra belong to its cmd/ tree and are not vendored.
Known limits (documented in glab df go --help)
Private modules fetched direct from VCS, modules already in GOMODCACHE, vendored builds, and local replace directives are not checked. Toolchain switching is disabled for the run (GOTOOLCHAIN=local). docs/residual-review-findings/go-mod-proxy.md records the deferred items.