fix(df): trust the user's JVM truststore on Maven and Gradle registry connections
Description
glab df maven and glab df gradle point the JVM at a truststore that glab generates, so that mvn and gradle trust the inspection proxy. That flag replaces the user's own -Djavax.net.ssl.trustStore, so the user's truststore reaches no connection. If a registry, or the outbound proxy in front of it, is signed by a CA that lives only in that truststore, the inspection proxy's TLS check to the registry fails.
This MR adds the certificates from the truststore the JVM would have loaded to the registry trust pool from !4150 (merged), for Maven and Gradle runs only.
How the store is found:
trustStore,trustStorePasswordandtrustStoreTypecome from these sources, later ones overriding earlier ones as on thejavacommand line:- Maven:
JAVA_TOOL_OPTIONS,JDK_JAVA_OPTIONS,.mvn/jvm.config, thenMAVEN_OPTS.jvm.configis found as Maven 3'sbin/mvnfinds it (MAVEN_BASEDIR, else the nearest.mvnfrom the-fdirectory or the working directory). A line is cut at a#that starts a word, then${MAVEN_PROJECTBASEDIR}is substituted, as in Maven 4. - Maven also:
.mvn/maven.config, thenMAVEN_ARGS, then themvncommand line (-D,--define). Maven 4 sets each of these properties only where the JVM options leave it unset, so they come before the JVM options. Maven 3 applies them over the JVM options; see below. - Gradle:
JAVA_TOOL_OPTIONS,JDK_JAVA_OPTIONS,JAVA_OPTS, thenGRADLE_OPTS.
- Maven:
- Values split on whitespace outside quotes, one line at a time; backslashes stay literal. Quotes follow the JVM, Gradle and Maven 4; Maven 3's Unix launcher passes them to
javaliterally. - With no
trustStore, glab readsjssecacertsorcacertsfrom$JAVA_HOME, as JSSE does, tryingchangeitand then no password. A named store that is missing or not a regular file also falls back tocacerts.NONE,Windows-*andKeychainStore*add nothing. - PKCS#12 is decoded with
go-pkcs12. A store glab cannot use (JKS or JCEKS, wrong or missing password, key entries,PKCS11) gets a one-line warning and the run goes on.
Options that replace glab's truststore:
- The JVM applies
_JAVA_OPTIONSafter the command line, mvn passesMAVEN_DEBUG_OPTSafterMAVEN_OPTS, and Maven 4 appends.mvn/jvm.configafterMAVEN_OPTS. A truststore set there replaces the one glab gives the child, so mvn or gradle cannot trust the proxy and the run fails. This was already true before this MR. - The same happens with a truststore option in the
mvnarguments,MAVEN_ARGSor.mvn/maven.configon Maven 3, and with-Dor--system-propon thegradlecommand line, which gradle applies overGRADLE_OPTSone property at a time, with or without the daemon. - glab now warns when
_JAVA_OPTIONS, for mvnMAVEN_DEBUG_OPTSor its own arguments, or for gradle its command line, setstrustStore,trustStorePassword, or atrustStoreTypeother thanPKCS12orJKS, and namesMAVEN_OPTS/GRADLE_OPTSas the place to set it. The mvn-argument warning says "on Maven 3", because on Maven 4 the run succeeds. Neither it nor Maven 4'sjvm.configorder needs the Maven version: detecting it would mean probing the install. - The help text and the regenerated
docs/source/dependency-firewall/_index.mddescribe both.
Not built: gradle.properties trust settings, finding a JDK on PATH when JAVA_HOME is unset, and JKS parsing.
Rebased onto main after !4156 (merged), !4279 (merged), !4282 (merged), !4323 (merged), !4277 (merged) and !4407 (merged) merged. main now makes upstreamRootCAs also return the extra registry CAs as PEM for the Go backend, so the rebased function takes this MR's anchors and returns main's PEM, which includes the anchors. The job-level proxy's UpstreamRootCAs passes no anchors. It merges textually with !4281 (closed), but whichever lands second must pass nil for anchors in !4281 (closed)'s three new upstreamRootCAs calls.
Related Issues
Related to #8635 (closed) Related to gitlab-org/gitlab#629431 Related to gitlab-org&24327
Part of the corporate-proxy stack. It is based on main.
How has this been tested?
Unit tests and real-tool runs
TestRunTrustsUserJVMTrustStoreUpstream:Runend to end through the inspection proxy to anhttptestTLS registry whose certificate is only in a PKCS#12 store. Passes for Maven (MAVEN_OPTS,JAVA_TOOL_OPTIONS) and Gradle (GRADLE_OPTS,JAVA_OPTS); fails for npm. Before the change, all four JVM cases failed withtls: bad certificate.TestJVMUpstreamTrustAnchors: quoting, source precedence,jvm.configlookup and comments, defaultcacerts/jssecacerts, fallback for a missing store, system store types, the warnings, the override warnings for_JAVA_OPTIONSandMAVEN_DEBUG_OPTS, and truststore options in themvnarguments,MAVEN_ARGS,.mvn/maven.configand on thegradlecommand line.TestJVMTrustStoreOverride,TestRunWarnsOncePerJVMTrustStoreProblem,TestSplitJVMArgs,TestRunWarnsAboutAConfiguredJVMTrustStoreItCannotUse,TestJVMTrustStoreDiagnosticsKeepThePasswordOut.go test -race ./internal/dependencyfirewall/... ./internal/commands/df/...,golangci-lint(0 issues) andscripts/comment-overlap(0 findings) pass. Each new branch was mutated and a test failed.- Real tools in CI, glab from this MR and from
mainas a control: Maven 3.9.12 on JDK 21, Maven 4.0.0-rc-7, Gradle 9.8.2, npm, pip, a TLS-intercepting proxy and a JFrog remote with a block policy. With a truststore in_JAVA_OPTIONS, mvn and gradle fail and glab names the option;mainand the previous head fail without the warning. All on b5b576c7; the later commit changes only comments (pipeline 3060782786). - Command-line truststores, behind mitmproxy with its CA only in the user's truststore, glab from this MR and from
23141edc7as a control: on Maven 4.0.0-rc-7, a truststore in themvnarguments,MAVEN_ARGSor.mvn/maven.configfailed withx509: certificate signed by unknown authorityand now builds through the proxy. On Maven 3.9.16 and Gradle 9.8.2, a truststore on the command line still fails withPKIX path building failed, now with the warning.MAVEN_OPTSandGRADLE_OPTSwork on all three, without a warning.