fix(df): keep the user's Maven settings when running the firewall
Description
glab df maven always wrote its own settings.xml holding nothing but the firewall's proxy entry, then pointed -s at it — so the caller's own mirrors, server credentials, and active profiles were silently dropped. Depending on how the caller passed their settings, this either broke builds that needed an internal mirror's credentials, or (when a settings file was already set via MAVEN_ARGS) stopped the firewall inspecting anything at all, because Maven read the caller's unproxied file first.
This merges the firewall's <proxy> entries into a byte-for-byte copy of whichever settings file Maven would actually read, instead of replacing it.
flowchart LR
subgraph before [Before]
U1["caller's settings.xml<br/>mirrors, credentials, profiles"] -. discarded .-> X1(["✗"])
G1["glab's standalone settings.xml<br/>proxy only"] --> M1["mvn"]
end
subgraph after [After]
U2["caller's settings.xml"] --> MG["byte-for-byte copy<br/>+ proxy spliced in"]
P2["firewall's proxy entry"] --> MG
MG --> M2["mvn"]
end- The settings file is located the way Maven locates it:
-s/--settingsinMAVEN_ARGS, then the command line, then.mvn/maven.config, then<user.home>/.m2/settings.xml—user.homecomes from the password database, not$HOME. - The document is copied byte for byte and the proxy entries spliced in by offset;
encoding/xmlonly locates the insertion point, never re-encodes, so a file that works today keeps working. - The entries are inserted first and glab's
-snow precedes any inheritedMAVEN_ARGS, since Maven uses the first active proxy per protocol and the first occurrence of a repeated flag. - When there's no settings file, or it can't be read or parsed, behavior is unchanged: glab writes its own standalone file so routing still works.
- The generated file can now contain the caller's real
<servers>credentials in plaintext (previously it held only the proxy block) — still0600inos.TempDir(), removed on normal exit and interrupt, but persists onSIGKILL/panic where it previously held nothing sensitive. - Known gaps, not fixed here:
.mvn/maven.configis resolved from glab's working directory, not a-f/--fileproject directory; a non-UTF-8 settings file is dropped rather than merged (the decoder has noCharsetReader).
Pairs with !4291 (closed), and should merge after it — see that MR's merge-order note.
Related Issues
Relates to gitlab-org/gitlab#637331 (Gap 2)
How has this been tested?
-
maven_user_settings_test.go: settings arriving via-s,--settings=, attached-sPATH,MAVEN_ARGS,.mvn/maven.config,~/.m2/settings.xml, a disagreeing command-line-svsMAVEN_ARGS, no settings at all, a caller's own active proxy, a self-closed<proxies/>, an unreadable path, and a complex realistic settings file (servers + mirrors + profiles + repositories + pluginRepositories together) — each proves the merge survives that shape without losing the caller's content or the firewall's own proxy. -
Mutation testing: 10 individual reverts (e.g. appending instead of prepending
-s, dropping.mvn/maven.config, reversing precedence) applied one at a time; every one fails the suite. -
End to end with a real
mvn3.9.12 against a settings file mirroring central to another host:main → Downloading from central: https://repo.maven.apache.org (mirror dropped) this branch → Downloading from customer-mirror: https://maven.aliyun.com (mirror used)— and the firewall still recorded a verdict for that traffic either way.
Commands: go test ./internal/dependencyfirewall/..., new tests under -race -count=2, golangci-lint run ./internal/dependencyfirewall/pm/..., go run ./scripts/comment-overlap.
