feat(df): reach registries through proxies set in package-manager config
Description
glab df points each package manager at its local inspection proxy. The inspection proxy then needs the outbound proxy the package manager would have used for its own connection to the registry. !4156 (merged) reads that proxy from the package manager's environment variables. This MR also reads it from the package manager's user and global config files, using the same precedence and no-proxy rules the manager applies. A corporate proxy that is set only in ~/.npmrc, ~/.yarnrc, ~/.yarnrc.yml, pip.conf or $CARGO_HOME/config.toml now receives the registry CONNECT.
glab skips any config file inside the project: the git work tree that holds the working directory, else the working directory. Rane asked for this in !4156 (comment 4199169261), because a file in the repository must not choose where registry traffic goes. The check also covers a user or global path that an environment variable such as CARGO_HOME, PREFIX or HOME puts inside the project, and it skips the file when it can't tell. Yarn Berry detection still reads the project's package.json and .yarnrc.yml, but only to choose between the Berry and Classic rules.
resolveUpstreamProxy now takes the working directory (RunOptions.BaseDir, which is the cwd the manager runs in) and the forwarded arguments, and resolvePlainHTTPProxy takes the working directory. Both return an error when a config file cannot be read or parsed, naming only the file and line, and Run stops before the manager starts. upstreamProxy.URL == "" now means a direct connection, for settings that disable the proxy: that scheme gets a proxy func that returns nil instead of falling back to HTTPS_PROXY. Three environment values from !4156 (merged) now connect directly too, as the tools do: YARN_HTTPS_PROXY=false or npm_config_https_proxy=false for Yarn Classic, an empty CARGO_HTTP_PROXY, and an empty YARN_HTTPS_PROXY in a Berry project.
What each manager reads, highest precedence first:
| Manager | Lookup | Verified against |
|---|---|---|
| npm | Each key is resolved on its own: npm_config_* env, then the user config (userconfig, else ~/.npmrc), then the global npmrc (globalconfig, else <prefix>/etc/npmrc, where prefix is prefix, $PREFIX, or the install prefix of the node on PATH). For https: https-proxy from any layer, then proxy from any layer, then HTTPS_PROXY. Plain HTTP uses the same proxy. A higher layer that sets a key to an empty value hides lower layers for that key, and false, null and undefined leave it unset. ${VAR} is expanded. noproxy and NO_PROXY both apply. The project .npmrc is not read. |
npm 11.17 runs against a logging fake proxy; @npmcli/config 10 source (lib/index.js load, loadGlobalPrefix), ini 6.0 decode, @npmcli/agent getProxy |
| Yarn Classic | https-proxy, then proxy. Plain HTTP reads only proxy. Each key is looked up in Yarn's config first (YARN_HTTPS_PROXY, then $YARN_USERCONFIG or ~/.yarnrc, then <prefix>/etc/yarnrc). If Yarn's config doesn't have the key, npm's config is used (npm_config_*, then the user .npmrc, then <prefix>/etc/npmrc). https-proxy false means direct, and other false, null and undefined values leave the key unset. .yarnrc is parsed as yarn parses it, in its lockfile syntax with a YAML fallback. A configured proxy ignores NO_PROXY. An unset ${VAR} in .npmrc fails the run, as it fails yarn. The .yarnrc and .npmrc files in the project and its ancestors are not read. |
yarn 1.22.22 runs (corepack yarn@1.22.22 info) against fake proxies; source at v1.22.22: src/config.js#L332-L340, src/util/request-manager.js#L153-L163,L476-L489, src/registries/yarn-registry.js#L65-L121, src/registries/npm-registry.js#L41-L60,L257-L338 |
| Yarn Berry | YARN_HTTPS_PROXY, then ~/.yarnrc.yml. ${VAR}, ${VAR-x} and ${VAR:-x} are expanded in the file. An empty value, in the file or in YARN_HTTPS_PROXY, means direct. NO_PROXY, npm_config_* and .npmrc are ignored. The .yarnrc.yml files from cwd up are not read. |
yarn 4.9.2 runs (yarn npm info) against fake proxies; Configuration.ts at @yarnpkg/cli/4.9.2 (findRcFiles, find, use), configUtils.ts#L103-L193, httpUtils.ts#L103-L141,L281-L296 |
| pip | PIP_PROXY, then the command's section ([install], [download], and so on) in any config file, then [global]. Within a section, the last file in pip's load order wins: global files, user files (~/.pip/pip.conf, then $XDG_CONFIG_HOME/pip/pip.conf or ~/.config/pip/pip.conf; on macOS, ~/Library/Application Support/pip/pip.conf when that directory exists), the site file of the virtualenv that holds the pip on PATH (skipped when it is inside the project), then PIP_CONFIG_FILE. An existing PIP_CONFIG_FILE replaces the user files, and /dev/null disables all files. --isolated skips the user files and PIP_PROXY. A configured proxy ignores HTTPS_PROXY and NO_PROXY. |
pip 26.1.2 runs (pip download) against fake proxies; configuration.py at 26.2.2, utils/appdirs.py#L18-L48, cli/parser.py#L226-L251, cli/index_command.py#L123-L134 |
| pipenv | Same files, [global] only. Pipenv's resolver builds pip's options under a command name that no section matches. |
pipenv v2026.10.4 source reading |
| cargo | CARGO_HTTP_PROXY (an empty value means direct), then config or config.toml in $CARGO_HOME (default ~/.cargo; config wins over config.toml), then git's http.proxy from ~/.gitconfig, then the XDG git config, then /etc/gitconfig. An empty http.proxy means direct. NO_PROXY still applies. The .cargo/config and .cargo/config.toml files in cwd and its ancestors are not read. |
cargo 1.99 runs (cargo generate-lockfile) against fake proxies; cargo 0.100.0 walk_tree/get_file_path, network/proxy.rs#L18-L25, config reference |
How Yarn Berry is detected: Corepack's packageManager field pins yarn@2 or later in the nearest package.json that has the field, or a .yarnrc.yml from cwd up sets yarnPath, which Classic hands the run to. Otherwise the run is treated as Classic, which is what Corepack and the yarn npm package run by default. If Berry finds no httpsProxy, it connects directly. In that case this MR still lets the inspection proxy use HTTPS_PROXY, as !4156 (merged) does, in case the detection is wrong.
pnpm is out of scope here. Its config lookup differs by major version and is handled separately. pnpm keeps the behaviour from !4156 (merged): only npm_config_* variables and HTTPS_PROXY are read.
Not read, and documented in the code:
- npm: the builtin npmrc, workspace roots, and command-line flags.
- Yarn: Berry per-host
networkSettings(out of scope per the plan). - pip: the site file of a Python that is not in a virtualenv.
- cargo: config
include(stable since 1.94) and--config. - git:
include/includeIf. - uv, poetry, twine, gem and bundle are unchanged.
github.com/pelletier/go-toml/v2 (already in go.mod as indirect) becomes a direct dependency to parse cargo config. go.yaml.in/yaml/v3 (already direct) parses .yarnrc.yml. The npmrc, .yarnrc, pip.conf and git config parsers are small and written to match each tool's own parser.
The glab dependency-firewall help text now describes this. docs/source was regenerated.
Related Issues
Related to #8635 (closed) Related to gitlab-org/gitlab#629431 Related to gitlab-org&24327 Builds on !4156 (merged), which is merged.
How has this been tested?
- Precedence tables for each manager, with a test for each case listed in the table above, using temp directories and files:
TestNpmUpstreamProxyFromConfigFiles,TestPnpmReadsOnlyNpmConfigEnvironment,TestYarnClassicUpstreamProxyFromConfigFiles,TestYarnBerryUpstreamProxyFromConfigFiles,TestPipUpstreamProxyFromConfigFiles,TestPipUserConfigOnMacOS,TestCargoUpstreamProxyFromConfigFiles. TheTestUpstreamProxyResolverstest from !4156 (merged) still passes with the new signature. TestRunSendsRegistryTrafficThroughUserConfigNotProjectConfig:Runend to end with recording proxies. The proxy from the user's config gets theCONNECT, and the proxy from a file inside the project gets nothing.TestRunRejectsMalformedManagerConfig: a malformed~/.cargo/config.tomlstops the run before cargo starts.- Each precedence rule encoded here was first observed with the real tools against logging fake proxies: npm 11.17, yarn 1.22.22, yarn 4.9.2, pip 26.1.2 and cargo 1.99, on macOS.
go test -racefor./internal/dependencyfirewall/...and./internal/commands/df/...,golangci-lint(0 issues),scripts/comment-overlap(0 findings),make gen-docs(no drift) andlefthook run pre-pushpass. The Docker harness has not been run on this branch, and nothing was run on Windows.
Tests, method and real-tool results
Unit tables: TestNpmUpstreamProxyFromConfigFiles, TestPnpmReadsOnlyNpmConfigEnvironment, TestYarnClassicUpstreamProxyFromConfigFiles, TestYarnBerryUpstreamProxyFromConfigFiles, TestPipUpstreamProxyFromConfigFiles, TestPipUserConfigOnMacOS, TestCargoUpstreamProxyFromConfigFiles. The project check has its own tests: TestConfigFilesSkipFilesInsideTheProject, TestConfigFilesFailClosed, TestConfigFilesMatchTheProjectInAnyCase, and TestConfigPathsThatResolveInsideTheProjectAreNotRead, which runs from a subdirectory and from a symlink to it, so that relative paths in PREFIX, HOME, NPM_CONFIG_USERCONFIG, YARN_USERCONFIG, CARGO_HOME and XDG_CONFIG_HOME, and a .. after a symlink, land inside the project. TestConfigErrorsNameTheFileWithoutQuotingIt checks the whole error text for each kind of file. TestUpstreamProxyResolvers, TestPlainHTTPProxyResolvers and TestOwnProxyVariablesAreRead from !4156 (merged) pass with the new signatures, and TestOwnProxyConfigFilesAreRead writes each file the help lists and checks that it is read.
Run tests: TestRunSendsRegistryTrafficThroughUserConfigNotProjectConfig (npm, Yarn Classic, Yarn Berry, pip and cargo, plus CARGO_HOME, NPM_CONFIG_USERCONFIG, PREFIX, PIP_CONFIG_FILE or HOME inside the project, a user file that links into it, and pip run from a subdirectory), TestRunConnectsDirectlyWhenTheManagerDisablesItsProxy, and TestRunRejectsMalformedManagerConfig.
Real-tool method (npm 10.9.8, Yarn 1.22.19, Yarn 4.9.2, pnpm 10.12.4, pip 26.0 and cargo 1.98 on macOS): a fresh HOME per case, each setting pointing at a different closed port on 127.0.0.1, and the registry at registry.invalid. The refused port names the proxy, and a failed lookup of registry.invalid means a direct connection. pip's errors name no proxy, so its proxies were recording listeners instead.
| Tool | Setting | Bare tool | glab |
|---|---|---|---|
| npm | ~/.npmrc https-proxy 9001 |
9001 | 9001 |
| npm | $PREFIX/etc/npmrc https-proxy 9001 |
9001 | 9001 |
| npm | ~/.npmrc https-proxy 9001, plain-HTTP registry, HTTP_PROXY 9007 |
9001 | 9001 |
| npm | ~/.npmrc 9001, project .npmrc 9002 |
9002 | 9001 |
| npm | NPM_CONFIG_USERCONFIG inside the project 9002, HTTPS_PROXY 9005 |
9002 | 9005 |
| npm | PREFIX inside the project 9002, ~/.npmrc proxy 9003 |
9002 | 9003 |
| npm | ~/.npmrc linked to a project file 9002, HTTPS_PROXY 9005 |
9002 | 9005 |
| npm | working directory spelled in another case, NPM_CONFIG_USERCONFIG inside the project 9002 |
9002 | 9005 |
| pnpm | ~/.npmrc https-proxy 9027 |
9027 | direct, as pnpm's files are not read yet |
| Yarn 1 | ~/.yarnrc https-proxy 9001 |
9001 | 9001 |
| Yarn 1 | ~/.yarnrc 9001 over npm_config_https_proxy 9004 |
9001 | 9001 |
| Yarn 1 | ~/.yarnrc https-proxy false, HTTPS_PROXY 9005 |
direct | direct |
| Yarn 1 | npm_config_https_proxy=false, npm_config_proxy 9003, HTTPS_PROXY 9005 |
direct | direct |
| Yarn 1 | plain HTTP, ~/.npmrc https-proxy 9001 and proxy 9003 |
9003 | 9003 |
| Yarn 1 | lowercase npm_config_userconfig file 9025, ~/.npmrc 9026 |
9025 | 9025 |
| Yarn 1 | ~/.yarnrc with an unquoted URL, HTTPS_PROXY 9005 |
9005 | 9005 |
| Yarn 1 | ~/.yarnrc written as YAML, 9017 |
9017 | 9017 |
| Yarn 1 | ~/.yarnrc 9001, project .yarnrc 9002 |
9002 | 9001 |
| Yarn 1 | YARN_USERCONFIG inside the project 9002, user .npmrc proxy 9003 |
9002 | 9003 |
| Yarn 1 | ancestor .yarnrc 9003 only |
9003 | direct |
| Yarn 1 | packageManager: yarn@4.9.2 without Corepack, ~/.npmrc 9028 |
9028 | direct, as glab applies the Berry rules |
| Yarn 4 | ~/.yarnrc.yml httpsProxy 9001 |
9001 | 9001 |
| Yarn 4 | empty YARN_HTTPS_PROXY, ~/.yarnrc.yml 9001 |
direct | direct |
| Yarn 4 | ~/.yarnrc.yml 9001, project .yarnrc.yml 9002 |
9002 | 9001 |
| Yarn 4 | ancestor .yarnrc.yml 9003 only |
9003 | direct |
| pip | ~/.config/pip/pip.conf 9001 |
9001 | 9001 |
| pip | PIP_CONFIG_FILE 9003 over the user file |
9003 | 9003 |
| pip | PIP_CONFIG_FILE inside the project 9002, HTTPS_PROXY 9005 |
9002 | 9005 |
| pip | virtualenv outside the project 9005, user file 9001 | 9005 | 9005 |
| pip | virtualenv inside the project 9002, user file 9001 | 9002 | 9001 |
| pip | run from a subdirectory, virtualenv in the project 9032, user file 9001 | 9032 | 9001 |
| cargo | ~/.cargo/config.toml 9001 |
9001 | 9001 |
| cargo | ~/.gitconfig http.proxy 9003 |
9003 | 9003 |
| cargo | empty CARGO_HTTP_PROXY, HTTPS_PROXY 9005 |
direct | direct |
| cargo | ~/.cargo/config.toml 9001, project .cargo/config.toml 9002 |
9002 | 9001 |
| cargo | CARGO_HOME inside the project, absolute or .cargo, 9042, ~/.gitconfig 9044 |
9042 | 9044 |
| cargo | ancestor .cargo/config.toml 9002 only |
9002 | direct |
Environment-only checks from !4156 (merged) give the same route as before: npm_config_https_proxy, npm_config_proxy=false with HTTPS_PROXY, HTTPS_PROXY over HTTP_PROXY for npm plain HTTP, YARN_HTTPS_PROXY, PIP_PROXY and CARGO_HTTP_PROXY. No glab output in these runs contains the credential from a .yarnrc with one.