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/--settings and -gs/--global-settings in MAVEN_ARGS or the command line, then the defaults. The default user file is ${user.home}/.m2/settings.xml. The default global file is settings.xml in the -Dmaven.conf directory, else conf/settings.xml of the installation that holds the mvn on PATH. The launcher ignores MAVEN_HOME.
  • user.home comes from -Duser.home (command line, then MAVEN_OPTS), else the account's home directory. The JVM ignores HOME.
  • 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 says true in any case, so yes counts as inactive. <protocol> defaults to http, and <port> defaults to 8080.
  • For an https registry, Maven picks the first https proxy whose nonProxyHosts don't match the host, else the first such http proxy. Other protocols are ignored. To support this, upstreamProxy gets NonProxyHosts (JVM-style * patterns, case-insensitive, whole host) and Fallbacks (tried in order for a host the previous proxy skips). nonProxyHosts splits on | only, not on commas, and tokens are not trimmed.
  • ${env.NAME}, ${user.home} and -D properties are interpolated in host, protocol, username, password and nonProxyHosts. 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/-gs file, 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_PROXY from its own environment.

Gradle (upstreamgradle.go), checked against Gradle 9.8.2:

  • Reads https.proxyHost, https.proxyPort (default 443), https.proxyUser, https.proxyPassword and http.nonProxyHosts. The JVM applies http.nonProxyHosts to https too, and https.nonProxyHosts has no effect. Each key comes from the first of: -D/--system-prop on the command line (last one wins), then systemProp.* in gradle.properties in the Gradle user home (-g/--gradle-user-home, -Dgradle.user.home, GRADLE_USER_HOME, ~/.gradle) and the Gradle installation.
  • An empty https.proxyHost means a direct connection. http.proxyHost alone does not cover https.
  • gradle.properties is parsed as java.util.Properties (=, : or whitespace separators, #/! comments, line continuation, \uXXXX escapes; trailing whitespace kept). http.nonProxyHosts uses JVM semantics: * only at the start or end of a pattern, so a pattern like repo.*.org never 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 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 -s settings.xml, an encrypted proxy password stops the run before mvn starts, and a -s file that resolves inside the project is ignored. On main the first two fail as expected. The HTTPS_PROXY controls for Maven, Gradle and npm pass on both builds.
Unit tests and tool checks
  • TestMavenUpstreamProxyFromSettings and TestGradleUpstreamProxyFromProperties: precedence tables on temp dirs covering every rule above, including the errors.
  • TestMatchesHostPattern, TestUpstreamProxyFuncFallsBackForNonProxyHosts and TestUpstreamProxyFuncRejectsBadFallback.
  • TestRunSendsMavenTrafficThroughProxyFromSettings: Run end to end with a fake mvn that reads glab's generated settings file and fetches a jar through it. The proxy from the user's -s settings file receives CONNECT repo.maven.apache.org:443.
  • TestRunRejectsEncryptedMavenProxyPassword: Run fails before starting mvn, names the file and proxy id, and doesn't print the password.
  • TestOwnProxyConfigFilesAreRead, TestJVMConfigPathsThatResolveInsideTheProjectAreNotRead and TestEmptyJVMUserHomeIsNotTheAccountHome: glab reads the Maven and Gradle files only from outside the project, and resolves an empty user.home, maven.conf or 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-25 and gradle:jdk21 (Gradle 9.8.2). A local recording proxy on several ports showed which proxy each configuration actually used for repo.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-lint reported 0 issues and comment-overlap reported 0 findings.
Edited by Hannah Baker

Merge request reports

Loading
Loading