-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
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
Initrd verify stage 2 #273593
base: master
Are you sure you want to change the base?
Initrd verify stage 2 #273593
Conversation
Are there some background discussions on this? |
This work is part of the supply chain security project funded by the STF, so indeed there is some background real-time discussion because we're trying to make the deadline. Feel free to get in touch if you have any questions and let's take it to another channel (public if you wish) and keep the PRs for technical discussion. |
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/boot-time-integrity-checks-for-the-nix-store/36793/1 |
after = [ "initrd-fs.target" ]; | ||
serviceConfig = { | ||
Type = "oneshot"; | ||
ExecStart = "${nix}/bin/nix --experimental-features nix-command verify -r --store /sysroot --trusted-public-keys \"${lib.concatStringsSep " " cfg.trustedPublicKeys}\" ${if cfg.sigsNeeded == 0 then "--no-trust" else "--sigs-needed " + toString cfg.sigsNeeded} \${NIXOS_SYSTEM_CLOSURE}"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ExecStart = "${nix}/bin/nix --experimental-features nix-command verify -r --store /sysroot --trusted-public-keys \"${lib.concatStringsSep " " cfg.trustedPublicKeys}\" ${if cfg.sigsNeeded == 0 then "--no-trust" else "--sigs-needed " + toString cfg.sigsNeeded} \${NIXOS_SYSTEM_CLOSURE}"; | |
ExecStart = "${nix}/bin/nix --extra-experimental-features nix-command verify -r --store /sysroot --trusted-public-keys \"${lib.concatStringsSep " " cfg.trustedPublicKeys}\" ${if cfg.sigsNeeded == 0 then "--no-trust" else "--sigs-needed " + toString cfg.sigsNeeded} \${NIXOS_SYSTEM_CLOSURE}"; |
I am not sure if it would be relevant if ca-derivations or similar are used in the closures.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean? Content-address derivations have the hash in their path measure their contents, but it's not checked at boot- or access-time.
AFAIK, nix store verify
still checks that the contents of CA derivations match their NAR hash, per the description:
For each path, it checks that
- its contents match the NAR hash recorded in the Nix database; and
- it is trusted, that is, it is signed by at least one trusted signing key, is content-addressed, or is built locally ("ultimately trusted").
That does lead to an interesting question, though: could an adversary manipulate the Nix db to change a CA derivation's expected hash ?
@@ -398,6 +419,9 @@ in { | |||
ManagerEnvironment=${lib.concatStringsSep " " (lib.mapAttrsToList (n: v: "${n}=${lib.escapeShellArg v}") cfg.managerEnvironment)} | |||
''; | |||
|
|||
# Make the system closure available as an environment variable. | |||
"/etc/systemd/system-environment-generators/nixos-environment-generator".source = "${envGenerator}/bin/nixos-environment-generator"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"/etc/systemd/system-environment-generators/nixos-environment-generator".source = "${envGenerator}/bin/nixos-environment-generator"; | |
"/etc/systemd/system-environment-generators/nixos-environment-generator".source = lib.getExe envGenerator; |
TIL that meta.mainProgram is prefilled for writeShellScriptBin
@@ -0,0 +1 @@ | |||
not-secret:0f9ZmCOeRdEa5HitWkOOfQDJQcrif06V+apZpSSHJ/WZL9ZDI2Guw7qEw3/cjBtKgh1r8MJoqQPWUmkL4gjZ5g== |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To fix the editorconfig check we probably need to add a line sort of like
Line 82 in 28089f8
insert_final_newline = unset |
Appologies if this is the wrong place to mention this, @ElvishJerricco An alternative I experimented with (and discussed a bit with some people at CCCamp's NixOS tent this year) is using
I'd be happy to share my experiences with that, and help upstream such a solution; the main issues I ran into were:
|
@nbraud It would probably be best to share that here: https://discourse.nixos.org/t/boot-time-integrity-checks-for-the-nix-store/36793 But the short version of my findings is that you can't actually verify that files are in the right locations with fs-verity, so e.g. it doesn't protect against the |
OK, let's take it to Discourse. |
Description of changes
Adds options for verifying the system closure during boot, and signing during switch-to-configuration.
Things done
nix.conf
? (See Nix manual)sandbox = relaxed
sandbox = true
nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)Add a 👍 reaction to pull requests you find important.