fix(df): trust ca_cert and package-manager CAs for glab df go module downloads
Description
glab dependency-firewall go does not route module downloads through the MITM proxy. A loopback Go module proxy (goproxy, in internal/dependencyfirewall/gomodproxy/backend.go) serves them, and since !4170 (merged) it fetches each module by running go with the user's GOPROXY. That go subprocess, and goproxy's own checksum database requests, trusted only the system roots. A user behind a TLS-inspecting corporate proxy, who set ca_cert or one of the CA variables for the other managers, still got x509: certificate signed by unknown authority from glab df go.
This MR gives the Go backend the extra registry CAs that pm.Run already loads with upstreamRootCAs (added in !4150 (merged)):
upstreamRootCAsnow also returns those extra certificates as PEM.setupInputgets anupstreamCAsfield, andgolangManager.Setuppasses it togomodproxy.NewBackend, which now takesupstreamCAs []byte.- The backend writes the PEM to
upstream-ca.pemin its temp directory, whichClosealready removes, and sets the fetcher'sSSL_CERT_FILEto it. That replacesgo's default CA file, butgostill reads the default CA directories, or the user'sSSL_CERT_DIR, so the roots it trusted before stay trusted. - The same PEM builds a pool for
goproxy.Goproxy.Transport, a clone ofhttp.DefaultTransportthat keepshttp.ProxyFromEnvironment, which covers checksum database proxying. - The fetcher keeps its own trust where
SSL_CERT_FILEwould drop the system roots: on macOS and Windows, where since Go 1.27 it replaces the platform store instead of adding to it, and when onlySSL_CERT_DIRis set. glab logs this underGLAB_DEBUG. - With no extra CAs, nothing changes.
What this does not cover: modules that go fetches directly from version control use the certificate and proxy settings of go and git. The dependency-firewall help text and docs/source/dependency-firewall/_index.md now state this and the macOS, Windows and SSL_CERT_DIR cases.
Related Issues
Related to #8635 (closed) Related to gitlab-org/gitlab#629431 Related to gitlab-org&24327
Builds on !4150 (merged) and !4170 (merged), both merged.
How has this been tested?
- New
TestRunComposedGolangTrustsConfiguredCAsUpstreamininternal/dependencyfirewall/pm/golang_composed_test.go. It runspm.Runwith the realgobinary and the real gomodproxy backend, with the fetcher'sGOPROXYpointed at anhttptestTLS server that serves a module fixture. With the server's certificate inca_cert(RunOptions.CACertPath) or inREQUESTS_CA_BUNDLE,go mod downloadsucceeds and one zip is checked. With neither, the run fails and the upstream gets no request. The trusted cases skip on macOS and Windows. - Without the
SSL_CERT_FILEchange, theca_certandREQUESTS_CA_BUNDLEcases fail on Linux. - New
TestNewBackendUpstreamCAsininternal/dependencyfirewall/gomodproxy/backend_test.gocovers when the fetcher getsSSL_CERT_FILE(Linux, with and without the user'sSSL_CERT_FILEandSSL_CERT_DIR, macOS, Windows) and thatGoproxy.Transportis set only when there are extra CAs. go test ./internal/dependencyfirewall/gomodproxy/ ./internal/dependencyfirewall/pm/ ./internal/commands/df/...pass.