feat(df): reach registries through proxies in Maven and Gradle settings
Description
glab df maven and glab df gradle now send the inspection proxy's registry traffic through the corporate proxy configured in Maven's settings.xml or Gradle's gradle.properties. Before this, those proxies were never used: glab passes Maven its own -s settings file, so the user's <proxy> never reaches Maven, and the inspection proxy only knew about HTTPS_PROXY. Neither Maven nor the JVM reads HTTPS_PROXY, so behind a proxy that only lives in these files, registry downloads failed.
This builds on the resolver from !4282 (merged) (upstreamProxyResolver, upstreamProxy). As with the npm, Yarn, pip and cargo settings, glab reads only user and global files: it skips a settings file, Gradle user home or Gradle installation that resolves inside the project.
Maven (upstreammaven.go), checked against Maven 3.9.16 and maven-resolver 1.9.27:
- Settings files: the user and global settings files come from
-s/--settingsand-gs/--global-settingsinMAVEN_ARGSor the command line, then the defaults. The default user file is${user.home}/.m2/settings.xml. The default global file issettings.xmlin the-Dmaven.confdirectory, elseconf/settings.xmlof the installation that holds themvnonPATH. The launcher ignoresMAVEN_HOME. user.homecomes from-Duser.home(command line, thenMAVEN_OPTS), else the account's home directory. The JVM ignoresHOME.- Proxies are merged by id, user entries first, and global entries with the same id are dropped. Then inactive entries are skipped: an entry is active when
<active>is missing or saystruein any case, soyescounts as inactive.<protocol>defaults tohttp, and<port>defaults to 8080. - For an https registry, Maven picks the first
httpsproxy whosenonProxyHostsdon't match the host, else the first suchhttpproxy. Other protocols are ignored. To support this,upstreamProxygetsNonProxyHosts(JVM-style*patterns, case-insensitive, whole host) andFallbacks(tried in order for a host the previous proxy skips).nonProxyHostssplits on|only, not on commas, and tokens are not trimmed. ${env.NAME},${user.home}and-Dproperties are interpolated in host, protocol, username, password andnonProxyHosts. Unknown expressions stay literal. The port is read before interpolation, as in Maven.- Username and password go into the proxy URL. A password Maven would decrypt (plexus-cipher's
{...}pattern) fails the run with a message that doesn't include the value. A missing-s/-gsfile, malformed XML, a duplicate<proxies>and a non-numeric port also fail the run. - With no active http/https proxy, the resolver reports none, so glab keeps using
HTTPS_PROXYfrom its own environment.
Gradle (upstreamgradle.go), checked against Gradle 9.8.2:
- Reads
https.proxyHost,https.proxyPort(default 443),https.proxyUser,https.proxyPasswordandhttp.nonProxyHosts. The JVM applieshttp.nonProxyHoststo https too, andhttps.nonProxyHostshas no effect. Each key comes from the first of:-D/--system-propon the command line (last one wins), thensystemProp.*ingradle.propertiesin the Gradle user home (-g/--gradle-user-home,-Dgradle.user.home,GRADLE_USER_HOME,~/.gradle) and the Gradle installation. - An empty
https.proxyHostmeans a direct connection.http.proxyHostalone does not cover https. gradle.propertiesis parsed asjava.util.Properties(=,:or whitespace separators,#/!comments, line continuation,\uXXXXescapes; trailing whitespace kept).http.nonProxyHostsuses JVM semantics:*only at the start or end of a pattern, so a pattern likerepo.*.orgnever matches and is dropped.
The glab dependency-firewall help text and generated docs now list Maven and Gradle and mention that encrypted Maven proxy passwords aren't supported.
Not covered: Maven 4 (project .mvn/settings.xml, new encryption format), -Dorg.apache.maven.user-settings (Maven 3.9 ignores it), commons-cli long-option prefixes like --set, and init scripts.
Related Issues
Related to #8635 (closed) Related to gitlab-org/gitlab#629431 Related to gitlab-org&24327
How has this been tested?
- Manual run in maven-testing-ground with glab built from main and from this MR, egress locked behind a Squid proxy: https://gitlab.com/gl-demo-premium-hbaker/maven-testing-ground/-/pipelines/3066301503. With this MR, Maven reaches the registry through a proxy that exists only in the
-ssettings.xml, an encrypted proxy password stops the run beforemvnstarts, and a-sfile that resolves inside the project is ignored. On main the first two fail as expected. TheHTTPS_PROXYcontrols for Maven, Gradle and npm pass on both builds.
Unit tests and tool checks
TestMavenUpstreamProxyFromSettingsandTestGradleUpstreamProxyFromProperties: precedence tables on temp dirs covering every rule above, including the errors.TestMatchesHostPattern,TestUpstreamProxyFuncFallsBackForNonProxyHostsandTestUpstreamProxyFuncRejectsBadFallback.TestRunSendsMavenTrafficThroughProxyFromSettings:Runend to end with a fakemvnthat reads glab's generated settings file and fetches a jar through it. The proxy from the user's-ssettings file receivesCONNECT repo.maven.apache.org:443.TestRunRejectsEncryptedMavenProxyPassword:Runfails before startingmvn, names the file and proxy id, and doesn't print the password.TestOwnProxyConfigFilesAreRead,TestJVMConfigPathsThatResolveInsideTheProjectAreNotReadandTestEmptyJVMUserHomeIsNotTheAccountHome: glab reads the Maven and Gradle files only from outside the project, and resolves an emptyuser.home,maven.confor Gradle user home as Maven 3.9.12 and Gradle 9.4 do.- Before the resolvers were wired in, the new tests failed: the type assertions failed, no CONNECT reached the corporate proxy, and no error was returned for the encrypted password.
- Every rule was first observed with the real tools in
docker run --rm maven:3.9-amazoncorretto-25andgradle:jdk21(Gradle 9.8.2). A local recording proxy on several ports showed which proxy each configuration actually used forrepo.maven.apache.org: 50+ Maven cases and 30+ Gradle cases. - After the rebase onto main,
go test -race ./internal/dependencyfirewall/... ./internal/commands/df/...passed.golangci-lintreported 0 issues andcomment-overlapreported 0 findings.