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, trustStorePassword and trustStoreType come from these sources, later ones overriding earlier ones as on the java command line:
    • Maven: JAVA_TOOL_OPTIONS, JDK_JAVA_OPTIONS, .mvn/jvm.config, then MAVEN_OPTS. jvm.config is found as Maven 3's bin/mvn finds it (MAVEN_BASEDIR, else the nearest .mvn from the -f directory 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, then MAVEN_ARGS, then the mvn command 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, then GRADLE_OPTS.
  • 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 java literally.
  • With no trustStore, glab reads jssecacerts or cacerts from $JAVA_HOME, as JSSE does, trying changeit and then no password. A named store that is missing or not a regular file also falls back to cacerts. NONE, Windows-* and KeychainStore* 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_OPTIONS after the command line, mvn passes MAVEN_DEBUG_OPTS after MAVEN_OPTS, and Maven 4 appends .mvn/jvm.config after MAVEN_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 mvn arguments, MAVEN_ARGS or .mvn/maven.config on Maven 3, and with -D or --system-prop on the gradle command line, which gradle applies over GRADLE_OPTS one property at a time, with or without the daemon.
  • glab now warns when _JAVA_OPTIONS, for mvn MAVEN_DEBUG_OPTS or its own arguments, or for gradle its command line, sets trustStore, trustStorePassword, or a trustStoreType other than PKCS12 or JKS, and names MAVEN_OPTS/GRADLE_OPTS as 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's jvm.config order needs the Maven version: detecting it would mean probing the install.
  • The help text and the regenerated docs/source/dependency-firewall/_index.md describe 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 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: Run end to end through the inspection proxy to an httptest TLS 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 with tls: bad certificate.
  • TestJVMUpstreamTrustAnchors: quoting, source precedence, jvm.config lookup and comments, default cacerts/jssecacerts, fallback for a missing store, system store types, the warnings, the override warnings for _JAVA_OPTIONS and MAVEN_DEBUG_OPTS, and truststore options in the mvn arguments, MAVEN_ARGS, .mvn/maven.config and on the gradle command line.
  • TestJVMTrustStoreOverride, TestRunWarnsOncePerJVMTrustStoreProblem, TestSplitJVMArgs, TestRunWarnsAboutAConfiguredJVMTrustStoreItCannotUse, TestJVMTrustStoreDiagnosticsKeepThePasswordOut.
  • go test -race ./internal/dependencyfirewall/... ./internal/commands/df/..., golangci-lint (0 issues) and scripts/comment-overlap (0 findings) pass. Each new branch was mutated and a test failed.
  • Real tools in CI, glab from this MR and from main as 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; main and 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 23141edc7 as a control: on Maven 4.0.0-rc-7, a truststore in the mvn arguments, MAVEN_ARGS or .mvn/maven.config failed with x509: certificate signed by unknown authority and now builds through the proxy. On Maven 3.9.16 and Gradle 9.8.2, a truststore on the command line still fails with PKIX path building failed, now with the warning. MAVEN_OPTS and GRADLE_OPTS work on all three, without a warning.
Edited by Arpit Gogia

Merge request reports

Loading
Loading