fix(df): keep the system CAs in the proxy CA bundle
Description
Most of the variables glab points at its CA bundle replace a tool's default trust instead of extending it: PIP_CERT, REQUESTS_CA_BUNDLE, SSL_CERT_FILE, TWINE_CERT, BUNDLE_SSL_CA_CERT and CARGO_HTTP_CAINFO. !4505 (merged) adds npm's cafile. When the user has no CA of their own, the bundle holds only glab's CA.
glab intercepts every connection that goes through its proxy, so those need only glab's CA. But a connection that skips the proxy and reads one of these variables can no longer verify any public host. Since !4503 (merged), a script run with glab dependency-firewall poetry run that connects with PIP_CERT fails this way. Once !4505 (merged) points npm's cafile at the bundle, so does an install script that downloads with npm's settings, because Node's https and fetch ignore proxy variables by default.
The bundle now also holds the system roots:
| Code | Change |
|---|---|
writeCABundle in pm.go |
Appends the system roots after the user's CAs and glab's CA |
Run in pm.go |
Passes systemRoots(), which the JVM truststore already uses. It reads PEM bundle files on Linux, the keychains on macOS and the certificate stores on Windows |
systemRoots in jvmtrust.go |
Reads the roots once per process, so Windows starts PowerShell at most once, and logs when it finds none. On macOS it keeps only CA certificates, so the device and MDM certificates in the System keychain don't become trust anchors |
SystemCABundlePaths in jvmtrust.go |
One list of Linux CA bundle paths, Go's six locations. The CI job proxy's merged bundle (session.WriteMergedBundle), which already includes the system roots for the same reason, now reads the same list |
encodeJVMTrustStore in jvmtrust.go |
Skips system roots the bundle already holds, so Maven and Gradle don't get each root twice |
| Help text and docs | Say that the CA bundle also holds the system's trusted certificates |
On macOS, reading the roots takes about 0.03 s and adds 163 certificates to the temporary bundle, which comes to 246 KB. If no roots can be read, the bundle is the same as before. Windows reads them with PowerShell, which hasn't been timed.
A user who narrowed a tool's trust to their own CA, for example with PIP_CERT, now also trusts the system CAs for connections that skip glab's proxy. The JVM truststore already works this way.
This MR should land before !4505 (merged), which would otherwise break those install scripts for every npm user without a cafile.
Related Issues
Related to gitlab-org&24327
How has this been tested?
Unit tests and direct connections before and after
Unit tests in internal/dependencyfirewall/pm:
TestWriteCABundleAppendsSystemRoots: the bundle holds glab's CA, then the roots passed in.TestEncodeJVMTrustStoreListsEachRootOnce: a system root that is already in the bundle isn't added to the JVM truststore again.TestSystemRootsHoldOnlyCAsOnMacOS: on macOS, every system root is a CA certificate.- The existing
writeCABundletests pass no roots and keep their exact counts.TestRunMergesUserCAIntoOverriddenVargoes throughRun, so its count now includes the system roots.
go test over internal/dependencyfirewall/... and internal/commands/df/... and golangci-lint pass.
Direct connections on macOS with no CA settings of the user's own, comparing main (b923f6be9) with this branch (c6267c35a). The probes ran with Python 3.14.6 and Poetry 2.5.1, and with Node 24.19.0 and npm 11.17.0.
| Case | main |
This branch |
|---|---|---|
glab df poetry run python probe.py, where probe.py connects to pypi.org with Python's http.client and PIP_CERT as its CA file |
PIP_CERT holds 1 certificate; CERTIFICATE_VERIFY_FAILED |
164 certificates; status 200 |
With !4505 (merged) (0674248f7), glab df npm install in a project whose postinstall script connects to registry.npmjs.org with Node's https and npm's cafile:
| Binary | npm_config_cafile |
Direct connection |
|---|---|---|
main |
Unset | 200 |
| !4505 (merged) | 1 certificate | UNABLE_TO_GET_ISSUER_CERT_LOCALLY |
| !4505 (merged) with this branch | 164 certificates | 200 |
The install itself succeeds in all three cases, because npm's own requests go through glab's proxy.
probe.py:
import http.client, os, ssl
f = os.environ["PIP_CERT"]
print("PROBE PIP_CERT has", open(f).read().count("BEGIN CERTIFICATE"), "certificate(s)")
try:
c = http.client.HTTPSConnection("pypi.org", context=ssl.create_default_context(cafile=f), timeout=10)
c.request("HEAD", "/simple/six/")
print("PROBE direct connection status", c.getresponse().status)
except Exception as e:
print("PROBE direct connection error", type(e).__name__, str(e)[:90])The npm postinstall script, probe.js:
const fs = require('fs');
const https = require('https');
const f = process.env.npm_config_cafile;
let ca;
if (f) {
ca = fs.readFileSync(f);
console.log('PROBE npm_config_cafile has ' + (ca.toString().match(/BEGIN CERTIFICATE/g) || []).length + ' certificate(s)');
} else {
console.log('PROBE npm_config_cafile unset');
}
https.get({ host: 'registry.npmjs.org', path: '/left-pad', ca, agent: false }, (r) => {
console.log('PROBE direct connection status ' + r.statusCode);
r.resume();
}).on('error', (e) => console.log('PROBE direct connection error ' + (e.code || e.message)));