feat(df): support registries behind an upstream proxy
Description
glab df could not reach package registries in a network where the only route out is an outbound (corporate) proxy. The inspection proxy's upstream http.Transport had no Proxy func, so it dialed registries directly. Because glab df also points the package manager's HTTP_PROXY and HTTPS_PROXY at the inspection proxy, the caller's corporate proxy was never used for registry traffic, and every install failed, allowed packages included.
This MR sets the upstream transport's Proxy to http.ProxyFromEnvironment. glab's own environment is untouched (only the package manager's environment is rewritten), so the caller's HTTPS_PROXY reaches the corporate proxy and can't loop back to the inspection proxy. Credentials in the proxy URL are sent on CONNECT, and NO_PROXY is honored, so an internal registry can still be reached directly. glab's GitLab API client already uses http.ProxyFromEnvironment, so registry and API traffic now take the same route.
WithUpstreamProxy is added for tests, alongside the existing WithUpstreamRootCAs: http.ProxyFromEnvironment reads the environment once per process, so a test can't change it with t.Setenv.
Out of scope, noted in the issue as follow-ups:
- When the upstream round trip fails, the tunnel is closed without a response, so the package manager reports a bare connection reset rather than the cause (for example a
407from the proxy, or an untrusted certificate from a TLS-inspecting proxy). - A proxy configured only in a package manager's own config (
pip.confproxy =,.npmrchttps-proxy=) is still not used for glab's upstream connection. SettingHTTPS_PROXYworks.
Related Issues
Resolves #8635 (closed) Related to gitlab-org&24327
How has this been tested?
Unit tests in internal/dependencyfirewall/proxy/outbound_test.go, against a CONNECT-only forward proxy that requires basic auth:
TestProxyReachesUpstreamThroughOutboundProxy: a tarball fetch succeeds through the outbound proxy, and the outbound proxy saw the tunnel to the upstream registry.TestProxyDoesNotFallBackToDirectWhenOutboundProxyRefuses: with wrong credentials the request fails, and the upstream is never contacted directly.TestProxyUsesEnvironmentOutboundProxyByDefault:Newuseshttp.ProxyFromEnvironment. It fails without the fix.
go test ./internal/dependencyfirewall/... passes, the new tests pass with -race -count=3, and golangci-lint and scripts/comment-overlap report nothing for the changed files.
End to end, with the same one-line change built on v1.123.0, against a project with an enforced and a warn-mode dependency firewall policy:
| Setup | glab 1.123.0 | With this change |
|---|---|---|
| Docker network with no direct internet, authenticated Squid as the only egress (npm, pip) | ECONNRESET / RemoteDisconnected; Squid sees no registry CONNECT |
Registry CONNECTs go through Squid, and requests reach the policy check |
Host with direct internet, HTTPS_PROXY set to Squid (npm, real verdicts) |
Correct verdicts, but registry traffic bypasses Squid | Correct verdicts (lodash@4.17.11 blocked, 4.18.1 allowed), with registry traffic through Squid |
Artifactory npm remote through Squid, and with NO_PROXY=<artifactory host> |
n/a | Both work: through Squid, and direct when exempted |
TLS-inspecting proxy (mitmproxy), corporate CA in the OS trust store or SSL_CERT_FILE on Linux |
n/a | Works |
Manual testing
These steps use mitmproxy in Docker as the corporate proxy and npm as the package manager. They use the fake policy checker (GLAB_DF_FAKE_*) by default, so you don't need a project with the dependency firewall enabled. GLAB_DF_FAKE_BLOCK=npm:left-pad proves a request went through glab's inspection proxy: the install is blocked only if glab saw it.
Setup. Build glab from the root of this branch, then create an empty npm project to install into. Run every step in that new directory, not in an existing project: the steps delete node_modules and package-lock.json, add left-pad to package.json, and step 3 points origin at another project. In an existing checkout, glab also looks up that project's remote through the proxy, so 1a fails at the lookup rather than at the registry.
make build
export GLAB=$PWD/bin/glab
mkdir -p ~/df-proxy-test/mitm && cd ~/df-proxy-test
npm init -y >/dev/null
# glab df takes the project from the git remote. The fake checker never contacts it, so a placeholder works.
git init -q && git remote add origin https://gitlab.com/example/df-proxy-test.git
# Otherwise, in a terminal, glab looks the project up on gitlab.com through the proxy before npm starts.
git config remote.origin.glab-resolved-base base
# glab's telemetry would also go through the proxy and log certificate warnings.
export GLAB_SEND_TELEMETRY=false
# npm serves cached tarballs without asking the proxy, so use a fresh cache for every install.
fresh() { rm -rf node_modules package-lock.json; export npm_config_cache=$(mktemp -d); }1. TLS-intercepting proxy, the usual corporate setup:
docker run -d --name corp-proxy -p 8080:8080 -v ~/df-proxy-test/mitm:/home/mitmproxy/.mitmproxy \
mitmproxy/mitmproxy mitmdump --set block_global=false
export HTTPS_PROXY=http://127.0.0.1:8080 GLAB_DF_FAKE_DEFAULT=allow
CA=~/df-proxy-test/mitm/mitmproxy-ca-cert.pem| Step | Command | Expected |
|---|---|---|
| 1a | fresh; GLAB_DEBUG=true $GLAB df npm install left-pad |
The install fails after about a minute, because npm retries. npm itself reports ECONNRESET (socket hang up). The cause is only in glab's debug output: dependency firewall proxy: upstream request to registry.npmjs.org:443 failed: tls: failed to verify certificate: x509: .... On main, the install succeeds and docker logs corp-proxy has no registry.npmjs.org line, because registry traffic skips the proxy. |
| 1b | fresh; GLAB_CA_CERT=$CA $GLAB df npm install left-pad |
Installs. docker logs corp-proxy shows the registry.npmjs.org requests. |
| 1c | fresh; GLAB_CA_CERT=$CA GLAB_DF_FAKE_BLOCK=npm:left-pad $GLAB df npm install left-pad |
1 package blocked: traffic through the corporate proxy is still inspected. |
| 1d | fresh; NODE_EXTRA_CA_CERTS=$CA $GLAB df npm install left-pad |
Installs. Registry connections also trust the package manager's CA variables. |
| 1e | fresh; NO_PROXY=registry.npmjs.org $GLAB df npm install left-pad |
Installs with no CA set, and no new registry.npmjs.org lines appear in docker logs corp-proxy: hosts in NO_PROXY are reached directly. |
2. Authenticated proxy:
docker rm -f corp-proxy
docker run -d --name corp-proxy -p 8080:8080 mitmproxy/mitmproxy \
mitmdump --set block_global=false --ignore-hosts '.*' --proxyauth corp:secret| Step | Command | Expected |
|---|---|---|
| 2a | fresh; HTTPS_PROXY=http://corp:secret@127.0.0.1:8080 $GLAB df npm install left-pad |
Installs. |
| 2b | fresh; HTTPS_PROXY=http://corp:wrong@127.0.0.1:8080 GLAB_DEBUG=true $GLAB df npm install left-pad |
The install fails after about a minute. npm itself reports ECONNRESET (socket hang up), and glab's debug output has the cause: upstream request to registry.npmjs.org:443 failed: Proxy Authentication Required. The password is not printed, and glab doesn't fall back to a direct connection. On main, it installs. |
3. Optional, with real policies. This needs glab auth login for gitlab.com, and a project with the dependency firewall enabled that you can access. The example is the demo project the corporate-proxy harness uses.
docker rm -f corp-proxy
docker run -d --name corp-proxy -p 8080:8080 -v ~/df-proxy-test/mitm:/home/mitmproxy/.mitmproxy \
mitmproxy/mitmproxy mitmdump --set block_global=false
export HTTPS_PROXY=http://127.0.0.1:8080
unset GLAB_DF_FAKE_DEFAULT
git remote set-url origin https://gitlab.com/gitlab-da/tutorials/security-and-governance/forrester-wave-agentic-development-security-tools-2026/depfw-group/dependency-firewall-python-demo.git| Step | Command | Expected |
|---|---|---|
| 3a | fresh; GLAB_CA_CERT=$CA $GLAB df npm install left-pad |
Installs. The policy check and the registry download both work through the proxy, and docker logs corp-proxy shows the gitlab.com and registry.npmjs.org requests: one CA setting covers both connections. |
| 3b | fresh; NODE_EXTRA_CA_CERTS=$CA $GLAB df npm install left-pad |
The install fails. The summary reports 1 package blocked, because the policy check couldn't run (policy check failed for npm:left-pad@1.3.0, with x509: "gitlab.com" certificate is not trusted). glab's API client trusts ca_cert but not the package-manager variables. |
Clean up with docker rm -f corp-proxy; unset HTTPS_PROXY GLAB_DF_FAKE_DEFAULT.