Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proposal: crypto/x509: allow user override of the system roots on all platforms #71924

Open
Snaipe opened this issue Feb 24, 2025 · 2 comments
Open
Labels
LibraryProposal Issues describing a requested change to the Go standard library or x/ libraries, but not to a tool Proposal Proposal-Crypto Proposal related to crypto packages or other security issues
Milestone

Comments

@Snaipe
Copy link

Snaipe commented Feb 24, 2025

Proposal Details

Today, Go supports on Unices (not darwin) the ability to override the system roots through the use of the environment variables SSL_CERT_FILE and SSL_CERT_DIR.

Having this ability to change the system roots without modifying the target Go binary is great for testing and integration into larger programs that invoke other Go programs. In particular, while it is trivial to modify a Go program to specify an alternate source for the system roots, not all Go programs that open TLS connections provide an option to do so.

Unfortunately, SSL_CERT_FILE and SSL_CERT_DIR are not honored on every system. This can be understandable since both are, originally, OpenSSL-specific, and Windows and macOS have their own ways to manage their system certificate store.

For these reasons, I'd like to propose a mechanism to override the system roots on platforms that do not support SSL_CERT_FILE/DIR. Today, these platforms are Windows, macOS, and Plan9 (and wasm, but that's probably not applicable?). I can mostly see two options here:

Option 1: extend SSL_CERT_FILE and SSL_CERT_DIR to other platforms.

This one is straightforward: move the logic that loads the roots from these variables out of roots_unix.go and in the SystemCertPool function.

The benefit is that quite a lot of tooling that set SSL_CERT_FILE would now work with no modification on more platforms. There is precedent in some languages/libraries doing this (Rust TLS for instance), too.

The drawback however is that this sudden support might not be desired, or lead to surprising behavior (for instance, tools that set the variable by mistake on Windows and relied on the actual system roots being loaded would suddenly honor the variable).

Option 2: introduce Go-specific environment variables GO_SSL_CERT_FILE and GO_SSL_CERT_DIR

This is less disruptive; it would mostly entail copying the code handling SSL_CERT_FILE/DIR and duplicate it into SystemCertPool, but using the environment variables GO_SSL_CERT_FILE/DIR instead. There is precedent in other languages and/or libraries doing this (NODE_EXTRA_CA_CERTS, REQUESTS_CA_BUNDLE, ...), so it wouldn't be too surprising to users.


Overall, option 1 would probably be the most seamless w.r.t. integration, but realistically I think the only real option is option 2 to avoid any potential breakage.

@gopherbot gopherbot added this to the Proposal milestone Feb 24, 2025
@gabyhelp gabyhelp added the LibraryProposal Issues describing a requested change to the Go standard library or x/ libraries, but not to a tool label Feb 24, 2025
@ianlancetaylor
Copy link
Member

CC @golang/security

@ianlancetaylor ianlancetaylor added the Proposal-Crypto Proposal related to crypto packages or other security issues label Feb 24, 2025
@ianlancetaylor ianlancetaylor moved this to Incoming in Proposals Feb 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LibraryProposal Issues describing a requested change to the Go standard library or x/ libraries, but not to a tool Proposal Proposal-Crypto Proposal related to crypto packages or other security issues
Projects
Status: Incoming
Development

No branches or pull requests

4 participants