Skip to content

libressl: use the host CA bundle like openssl - #576513

Merged
zimbatm merged 2 commits into
NixOS:stagingfrom
zimbatm:cacert-libressl
Nov 5, 2026
Merged

zimbatm merged 2 commits into
NixOS:stagingfrom
zimbatm:cacert-libressl

Conversation

@zimbatm

@zimbatm zimbatm commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

OPENSSLDIR was the relative path "etc/ssl". Thus libcrypto (openssl CLI, SSL_CTX_set_default_verify_paths) looked for "etc/ssl/cert.pem" relative to the current directory, and the vendored $out/etc/ssl/cert.pem was not used.

Set OPENSSLDIR to $out/etc/ssl and replace the vendored cert.pem with a symlink to the cacert bundle, like TLS_DEFAULT_CA_FILE for libtls.

Related to: #576485
Related to: #576541

Assisted-by: Claude Code (claude-opus-5)

Things done

@nixpkgs-ci nixpkgs-ci Bot added the 2.status: merge-bot eligible This PR can be merged by commenting "@NixOS/nixpkgs-merge-bot merge". label Oct 20, 2026
@nixpkgs-ci nixpkgs-ci Bot added 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-linux: 501-1000 This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-darwin: 501-1000 This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-nixos-tests This PR causes rebuilds for all NixOS tests and should normally target the staging branches. llm-assisted Contributions that include code generation with LLMs labels Oct 20, 2026
@hesiod hesiod added the 1.severity: security Issues which raise a security issue, or PRs that fix one label Oct 20, 2026
@zimbatm zimbatm added the backport staging-26.05 Backport PR automatically label Oct 20, 2026
@vcunat

vcunat commented Oct 21, 2026

Copy link
Copy Markdown
Member

Targeting nixpkgs master sounds OK to me at this moment. (very many binaries are still missing in there)

Comment thread pkgs/by-name/li/libressl/default.nix Outdated
Comment on lines +44 to +46
# The default OPENSSLDIR is the relative path "etc/ssl", so libcrypto
# would look for its default CA file relative to the current directory.
"-DOPENSSLDIR=${placeholder "out"}/etc/ssl"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this follow the same semantics as the OpenSSL build? It is, after all, supposed to be the compatibility layer with OpenSSL.

See the various use-etc-ssl-certs.patch under pkgs/development/libraries/openssl.

Additionally, using that patch implies that, for any follow-up, the host system's mitigations for the cert bundle will naturally apply. And additionally-additionally, in the far future, using older (but newer than today) builds of libressl will also benefit from the system's up-to-date bundle.

cc @ruuda (maintainer).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not familiar enough with the OpenSSL build; in my projects where I use the LibreSSL package, I use Nix only to build an image and then I take the certificate bundle from the host.

How do you propose to change it? I would prefer to avoid patches as much as possible.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. I fixed the PR to match OpenSSL's approach.

@samueldr-at-cyberus

samueldr-at-cyberus commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

It may also be questionable how TLS_DEFAULT_CA_FILE is being set to the package set's cacert, depending on what the actual semantics within Nixpkgs should be. (But out of scope for this PR, really.)

It should, at least, be consistent. It's kinda bad if sometimes it's under the ambient /etc, sometimes the whichever cacert it was built against.

@ruuda ruuda left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks okay to me. @samueldr-at-cyberus, if you have a suggestion to improve it further, could it be done as a follow-up, or do you think anything is wrong with the current version?

@nixpkgs-ci nixpkgs-ci Bot added 12.approvals: 1 This PR was reviewed and approved by one person. 12.approved-by: package-maintainer This PR was reviewed and approved by a maintainer listed in any of the changed packages. labels Oct 27, 2026
@zimbatm zimbatm changed the title libressl: use cacert as the default libcrypto CA file libressl: use the host CA bundle like openssl Oct 27, 2026
# so that libressl follows CA updates of the host like openssl does.
hostCaFile =
if stdenv.hostPlatform.isDarwin then
"/nix/var/nix/profiles/default/etc/ssl/certs/ca-bundle.crt"

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hopefully we can unify both at some point...

OPENSSLDIR was the relative path "etc/ssl". Thus libcrypto (openssl CLI,
SSL_CTX_set_default_verify_paths) looked for "etc/ssl/cert.pem" relative to
the current directory, and libtls used the cacert of the package set.

Set OPENSSLDIR to $out/etc/ssl. Point the default CA file of libcrypto
(X509_CERT_FILE) and libtls (TLS_DEFAULT_CA_FILE) to the path of openssl's
use-etc-ssl-certs patches: /etc/ssl/certs/ca-certificates.crt, or the
bundle of the default profile on Darwin. A CA update of the host now
applies without a rebuild. Remove the vendored $out/etc/ssl/cert.pem.

Assisted-by: Claude Code (claude-opus-5)
@ruuda

ruuda commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Removing the cacert dependency would undo the behavior introduced by @cvengler in #540702. (The dependency was already there, but not used correctly, so effectively #540702 introduced the usage.)

I think it does make sense to default to a path in /etc rather than /nix/store, in order to respond to CA changes quickly without having to rebuild the world, so I think the new behavior makes sense, but I am curious about @cvengler’s use case. If the path needs to be configurable, we could make hostCaFile a package argument with default value, so it can be overridden to "${cacert}/etc/ssl/certs/ca-bundle.crt" when you do want a hard-coded CA bundle.

(I will be away for a few days until Monday, I am fine with either solution so feel free to merge either way, because there is some time pressure on this one.)

@cvengler

Copy link
Copy Markdown
Member

I'm generally in favor of having a global system-wide CA store.

My only concern with this is on how it will interfere with potential sandboxes. For the Nix build sandbox it is probably not a big deal because it runs without internet access and TLS certificates signed by canonical CAs in unit tests are rare.
It should also not be a big deal for applications either, as I quite often find myself allowing read access to /etc/ssl/certs.

@zimbatm

zimbatm commented Oct 29, 2026

Copy link
Copy Markdown
Member Author

I noticed libressl isn't patched to support NIX_SSL_CERT_FILE / SSL_CERT_FILE yet, which is the fallback that we need for the sandbox scenario. This is what Nix relies on if for example we want to use openssl to fetch from the FODs.

LibreSSL reads neither variable: libcrypto uses X509_get_default_cert_file()
and libtls the compiled-in TLS_DEFAULT_CA_FILE. Check NIX_SSL_CERT_FILE,
then SSL_CERT_FILE, before the default in both, like openssl's
nix-ssl-cert-file.patch. Setuid programs ignore the variables.

In the build sandbox /etc/ssl does not exist and the cacert setup hook
sets NIX_SSL_CERT_FILE, so this keeps libressl usable there.

Assisted-by: Claude Code (claude-opus-5)

@ruuda ruuda left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The if ((file = nix_cert_file_env()) == NULL) assignment inside a condition is a bit cryptic for my taste, I would have put it on a separate line, but it works and we should merge this sooner rather than later, so LGTM.

@zimbatm
zimbatm added this pull request to the merge queue Nov 5, 2026
Merged via the queue into NixOS:staging with commit 7703e44 Nov 5, 2026
28 checks passed
@zimbatm
zimbatm deleted the cacert-libressl branch November 5, 2026 12:21
@nixpkgs-ci

nixpkgs-ci Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Backport failed for staging-26.05, because it was unable to cherry-pick the commit(s).

Please cherry-pick the changes locally and resolve any conflicts.

git fetch origin staging-26.05
git worktree add -d .worktree/backport-576513-to-staging-26.05 origin/staging-26.05
cd .worktree/backport-576513-to-staging-26.05
git switch --create backport-576513-to-staging-26.05
git cherry-pick -x f28e4b68bf174604ceda72d63bfdf2453e31396b 9dfc9b9542c6160fa43bbd7717ebd7fc21ab797c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1.severity: security Issues which raise a security issue, or PRs that fix one 2.status: merge-bot eligible This PR can be merged by commenting "@NixOS/nixpkgs-merge-bot merge". 8.has: failed backport 10.rebuild-darwin: 501-1000 This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-linux: 501-1000 This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-nixos-tests This PR causes rebuilds for all NixOS tests and should normally target the staging branches. 12.approvals: 1 This PR was reviewed and approved by one person. 12.approved-by: package-maintainer This PR was reviewed and approved by a maintainer listed in any of the changed packages. backport staging-26.05 Backport PR automatically llm-assisted Contributions that include code generation with LLMs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants