Skip to content

cacert: ensure that NIX_SSL_CERT_FILE is readable before using it - #345322

Closed
lukegb wants to merge 1 commit into
NixOS:stagingfrom
lukegb:nix-ssl-cert-file-345226
Closed

lukegb wants to merge 1 commit into
NixOS:stagingfrom
lukegb:nix-ssl-cert-file-345226

Conversation

@lukegb

@lukegb lukegb commented Sep 29, 2024

Copy link
Copy Markdown
Contributor

Description of changes

Following on from #303307, we check that NIX_SSL_CERT_FILE is readable from the current environment before using it; otherwise we set it from the cacert package as before.

We log a message if we're inheriting it, as well as if we're ignoring it, to leave a breadcrumb for people wondering why their custom SSL cert file isn't being used.

Fixes #345226.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Tested basic functionality of all binary files (usually in ./result/bin/)
  • 24.11 Release Notes (or backporting 23.11 and 24.05 Release notes)
    • (Package updates) Added a release notes entry if the change is major or breaking
    • (Module updates) Added a release notes entry if the change is significant
    • (Module addition) Added a release notes entry if adding a new NixOS module
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

Following on from NixOS#303307, we check that `NIX_SSL_CERT_FILE` is readable
from the current environment before using it; otherwise we set it from
the cacert package as before.

We log a message if we're inheriting it, as well as if we're ignoring
it, to leave a breadcrumb for people wondering why their custom SSL cert
file isn't being used.

Fixes NixOS#345226.
@ofborg ofborg Bot added 10.rebuild-darwin-stdenv This PR causes stdenv to rebuild on Darwin and must target a staging branch. 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. labels Sep 29, 2024
echo "cacert/setup-hook: NIX_SSL_CERT_FILE in environment $NIX_SSL_CERT_FILE cannot be read; overriding" >&2
fi
export NIX_SSL_CERT_FILE="@out@/etc/ssl/certs/ca-bundle.crt"
fi

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 was thinking of this:

export NIX_SSL_CERT_FILE="${NIX_SSL_CERT_FILE:-@out@/etc/ssl/certs/ca-bundle.crt}"
if test ! -r "$NIX_SSL_CERT_FILE"; then
  echo "cacert/setup-hook: NIX_SSL_CERT_FILE in environment $NIX_SSL_CERT_FILE cannot be read; overriding" >&2
  export NIX_SSL_CERT_FILE="@out@/etc/ssl/certs/ca-bundle.crt"
fi

It's still a bit of duplication, but at least there's no edge cases around e.g. testing an empty file when NIX_SSL_CERT_FILE isn't set.

@timbertson timbertson 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.

I think the logging might be a bit verbose, but I believe this should fix the issue.

@wegank wegank added the 12.approvals: 1 This PR was reviewed and approved by one person. label Oct 11, 2024
@EmileGregoire-Eaton

Copy link
Copy Markdown

Is there something blocking this PR from getting merged? We are facing an issue that is fixed by this PR in our current setup.

@timbertson

timbertson commented Jan 8, 2025 via email

Copy link
Copy Markdown
Contributor

@timbertson

Copy link
Copy Markdown
Contributor

@lukegb I don't support you have permission to merge this do you?

@FliegendeWurst

FliegendeWurst commented Apr 13, 2025 •

Copy link
Copy Markdown
Member

There is a merge conflict that must be resolved

(lukegb does have the commit bit so could merge this, but most try to avoid self-merges)

@FliegendeWurst

Copy link
Copy Markdown
Member

IMO it would also be nicer to convert this to a postHook now, and not set stuff right away. The only reason the hook worked before is that stdenv's SSL_CERT_FILE setup comes after sourcing all setup hooks:

# Prevent SSL libraries from using certificates in /etc/ssl, unless set explicitly.
# Leave it in impure shells for convenience.
if [[ -z "${NIX_SSL_CERT_FILE:-}" && "${IN_NIX_SHELL:-}" != "impure" ]]; then
export NIX_SSL_CERT_FILE=/no-cert-file.crt
fi
# Another variant left for compatibility.
if [[ -z "${SSL_CERT_FILE:-}" && "${IN_NIX_SHELL:-}" != "impure" ]]; then
export SSL_CERT_FILE=/no-cert-file.crt
fi

With this fix, it would overwrite that value.

(unlike the merge conflict, this suggestion doesn't block merging)

@nixpkgs-ci nixpkgs-ci Bot added the 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md label Oct 11, 2025
@lukegb lukegb closed this Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

2.status: merge conflict This PR has merge conflicts with the target branch 2.status: stale https://github.com/NixOS/nixpkgs/blob/master/.github/STALE-BOT.md 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-darwin-stdenv This PR causes stdenv to rebuild on Darwin and must target a staging branch. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. 12.approvals: 1 This PR was reviewed and approved by one person.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants