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)):

  • upstreamRootCAs now also returns those extra certificates as PEM. setupInput gets an upstreamCAs field, and golangManager.Setup passes it to gomodproxy.NewBackend, which now takes upstreamCAs []byte.
  • The backend writes the PEM to upstream-ca.pem in its temp directory, which Close already removes, and sets the fetcher's SSL_CERT_FILE to it. That replaces go's default CA file, but go still reads the default CA directories, or the user's SSL_CERT_DIR, so the roots it trusted before stay trusted.
  • The same PEM builds a pool for goproxy.Goproxy.Transport, a clone of http.DefaultTransport that keeps http.ProxyFromEnvironment, which covers checksum database proxying.
  • The fetcher keeps its own trust where SSL_CERT_FILE would 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 only SSL_CERT_DIR is set. glab logs this under GLAB_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 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 TestRunComposedGolangTrustsConfiguredCAsUpstream in internal/dependencyfirewall/pm/golang_composed_test.go. It runs pm.Run with the real go binary and the real gomodproxy backend, with the fetcher's GOPROXY pointed at an httptest TLS server that serves a module fixture. With the server's certificate in ca_cert (RunOptions.CACertPath) or in REQUESTS_CA_BUNDLE, go mod download succeeds 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_FILE change, the ca_cert and REQUESTS_CA_BUNDLE cases fail on Linux.
  • New TestNewBackendUpstreamCAs in internal/dependencyfirewall/gomodproxy/backend_test.go covers when the fetcher gets SSL_CERT_FILE (Linux, with and without the user's SSL_CERT_FILE and SSL_CERT_DIR, macOS, Windows) and that Goproxy.Transport is set only when there are extra CAs.
  • go test ./internal/dependencyfirewall/gomodproxy/ ./internal/dependencyfirewall/pm/ ./internal/commands/df/... pass.
Edited by Bala Kumar

Merge request reports

Loading
Loading