fix(df): check Maven packages fetched through a mirror
Description
glab df maven doesn't check packages that a build fetches through a mirror. It replaces the caller's settings.xml, and when a mirror does serve a request, the mirror's path ends up in the package name, so no rule matches.
This keeps the caller's settings and works out the real package name from the mirrored path.
flowchart LR
S["caller's settings.xml"] --> M["mvn fetches through<br/>the caller's mirror"]
M --> P["glab proxy sees<br/>/repository/public/org/slf4j/…"]
P -->|"every mirror known"| K["mirror URL stripped:<br/>org.slf4j:slf4j-api"]
P -->|otherwise| R["every reading checked,<br/>a block on any wins"]- glab finds the settings file the way Maven does and adds its proxy to a copy, expanding
${env.X}in repository URLs so Maven fetches from the URL glab checks. A file with a plain-HTTP mirror falls back to glab's own file with awarning:, until !4326 (merged) lets the proxy handle plain HTTP. - With a catch-all mirror (
mirrorOf=*) and every mirror URL known, glab strips the mirror URL and checks one name. That stops log4j 2's parent POM being blocked aslog4j:log4j, whose CVE-2021-4104 covers every version. - glab then passes Maven a copy of the global settings it checked as
-gs, so Maven can't use a mirror glab didn't see. - When glab can't be sure of every mirror (no catch-all, an rc file that changes arguments,
-funtil !4327 (closed), Maven 4), it checks every reading as before, up to 21 policy calls per artifact. A wrong block is still possible there, a missed one isn't. - The generated settings files can hold the caller's
<servers>credentials. They're0600and deleted on exit, but survive aSIGKILL. - glab's
-snow goes before any-salready inMAVEN_ARGS. Released glab put it after, so the caller's file won andmvnran without the proxy.
Supersedes !4289 (closed) and !4291 (closed). !4326 (merged) and then !4327 (closed) stack on this one, so merge this first.
Related Issues
Relates to gitlab-org/gitlab#637331. Does the exact matching proposed in gitlab-org/gitlab#638414.
How has this been tested?
Real mvn 3.9.12 through glab df maven, with the fake policy checker:
| Setup | Released glab 1.123.0 | This MR |
|---|---|---|
-s settings with a mirrorOf=* mirror |
settings ignored, Central used | mirror used, log4j-core blocked |
-gs Nexus-style or virtual-registry mirror |
nothing checked | log4j-core blocked |
rule on log4j:log4j, project uses log4j 2 behind a mirror |
n/a | builds |
mirrorOf=central only |
n/a | every reading checked |
catch-all URL from ${env.X}, rule on log4j:log4j |
settings ignored, Central used | mirror used, builds |
The issue's four CI job shapes, on Alpine's Maven package, all build with the log4j:log4j rule and still block log4j-core.
New tests
pm/maven_user_settings_test.go: where the settings file is found, and that the merge keeps the caller's content.TestMavenMirrorCandidates,TestMavenMirrorPolicyMatching,TestMavenMirrorThroughTunnel: the readings, which verdict wins, the deadline, fail-closed checks.TestMavenMirrorKnownURLs,TestMavenMirrorKnownURLsThroughTunnel: exact matching under a known mirror, and its fallbacks.TestMavenKnownMirrors: when every mirror counts as known.TestMavenGlobalSettingsFile,TestMavenManagerKnownMirrors: which global settings glab reads, and that Maven gets-sthen-gswith an exact0600copy.TestMavenPlainHTTPRepositories,TestRunWarnsAboutPlainHTTPRepositories: the plain-HTTP fallback, and a warning that never prints a URL.TestMavenExpandEnvURLs: which${env.X}URLs are expanded.TestCacheCheckFailedOnlyMarksFailures: a failed check is never recorded as a block.
Edited by Hannah Baker
Merge request reports
Loading

