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

feat: add CPIO packing for companion files #168

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
8890bf7
feat: add cpio packing for companion files
RaitoBezarius Apr 30, 2023
2a4f584
linux-bootloader: rework the cpio code
RaitoBezarius Nov 9, 2023
a366f73
stub/common: add credential/sysext discovery
RaitoBezarius Nov 9, 2023
4a52120
stub(*): support dynamic initrds
RaitoBezarius Nov 9, 2023
634f012
stub: discover credentials and system extensions and load them
RaitoBezarius Nov 9, 2023
9d16eea
stub(cargo): use personal fork of uefi-rs for development
RaitoBezarius Nov 9, 2023
4b38f19
feat(cpio): move cpio archive assembling in its own library called `pio`
RaitoBezarius Nov 15, 2023
6668ee1
stub: measure companion initrds
RaitoBezarius Nov 15, 2023
31c3422
stub: merge dynamically initrds
RaitoBezarius Nov 15, 2023
3bbcd7d
linux-bootloader: shuffle things around
RaitoBezarius Nov 15, 2023
06f9a35
tool(systemd): support global credentials installation
RaitoBezarius Nov 15, 2023
ebf70fe
linux-bootloader: take note of the `image_device_path` in `PeInMemory`
RaitoBezarius Nov 15, 2023
afd2002
modules/lanzaboote: support global credentials and local credentials
RaitoBezarius Nov 15, 2023
423ed75
nix/tests/lanzaboote: add `credentials-basic` test
RaitoBezarius Nov 15, 2023
113bd24
linux-bootloader: communicate that we theoretically support credentia…
RaitoBezarius Nov 15, 2023
63d41c9
stub(thin): align initrds!
RaitoBezarius Nov 15, 2023
3289b60
stub: pin to uefi 0.25.0 fork
RaitoBezarius Jan 2, 2024
58722f4
flake: bump to 24.05+
RaitoBezarius Jan 2, 2024
cf5887c
stub: `cargo fmt` it
RaitoBezarius Jan 2, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions nix/modules/lanzaboote.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,25 @@ let
lib.generators.mkKeyValueDefault { } " " k v;
};

assembleCredentialDirectoryFromDrv = drv: ''
for credential in ${drv}/*; do
echo "Processing $credential"
if [[ "''${credential##*.}" != "cred" ]]; then
echo "Found a non-credential: $credential, please remove it or move it."
exit 1
fi
cp $credential $out/
done
'';

assembleCredentialDirectory = drvs: pkgs.runCommand "assemble-credentials" { } ''
mkdir -p $out/
${concatStringsSep "\n" (map assembleCredentialDirectoryFromDrv drvs)}
'';

globalCredentialsDirectory = assembleCredentialDirectory cfg.globalCredentials;
localCredentialsDirectory = assembleCredentialDirectory cfg.localCredentials;

loaderConfigFile = loaderSettingsFormat.generate "loader.conf" cfg.settings;

configurationLimit = if cfg.configurationLimit == null then 0 else cfg.configurationLimit;
Expand All @@ -36,6 +55,30 @@ in
'';
};

globalCredentials = mkOption {
type = types.listOf types.package;
description = lib.mdDoc ''
A list of derivations containing multiple .cred files inside of it.
If anything else than a .cred is found, in the top-level, this will fail
at assembly time.

This will be installed in $ESP/loader/credentials.
In case of data conflict, the installer will fail and ask for manual removal.
'';
};

localCredentials = mkOption {
type = types.listOf types.package;
description = lib.mdDoc ''
A list of derivations containing multiple .cred files inside of it.
If anything else than a .cred is found, in the top-level, this will fail
at assembly time.

This will be installed in this generation's drop-in directory specifically.
In case of data conflict, the installer will fail and ask for manual removal.
'';
};

pkiBundle = mkOption {
type = types.nullOr types.path;
description = "PKI bundle containing db, PK, KEK";
Expand Down Expand Up @@ -125,6 +168,8 @@ in
--public-key ${cfg.publicKeyFile} \
--private-key ${cfg.privateKeyFile} \
--configuration-limit ${toString configurationLimit} \
--global-credentials-directory ${globalCredentialsDirectory} \
--local-credentials-directory ${localCredentialsDirectory} \
${config.boot.loader.efi.efiSysMountPoint} \
/nix/var/nix/profiles/system-*-link
'';
Expand Down
20 changes: 19 additions & 1 deletion nix/tests/lanzaboote.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ let
inherit (pkgs) lib system;
defaultTimeout = 5 * 60; # = 5 minutes

mkSecureBootTest = { name, machine ? { }, useSecureBoot ? true, useTPM2 ? false, readEfiVariables ? false, testScript }:
# `handInstrumentationOverInInitrd`: stop the test script at initrd time in stage 1 so you can assert stage 1 behavior via https://github.com/NixOS/nixpkgs/pull/256226 backdoor.
mkSecureBootTest = { name, machine ? { }, useSecureBoot ? true, useTPM2 ? false, readEfiVariables ? false, handInstrumentationInInitrd ? false, globalCredentials ? [ ], localCredentials ? [ ], testScript }:
let
tpmSocketPath = "/tmp/swtpm-sock";
tpmDeviceModels = {
Expand Down Expand Up @@ -94,6 +95,9 @@ let
machine
];

testing.initrdBackdoor = lib.mkIf handInstrumentationInInitrd true;
boot.initrd.systemd.enable = lib.mkIf handInstrumentationInInitrd true;

virtualisation = {
useBootLoader = true;
useEFIBoot = true;
Expand Down Expand Up @@ -146,6 +150,7 @@ let
enable = true;
enrollKeys = lib.mkDefault true;
pkiBundle = ./fixtures/uefi-keys;
inherit globalCredentials localCredentials;
};
};
};
Expand Down Expand Up @@ -450,4 +455,17 @@ in
'';
};

credentials-basic = mkSecureBootTest {
name = "lanzaboote-credentials-basic";
readEfiVariables = true;
handInstrumentationInInitrd = true;
globalCredentials = [
(pkgs.writeTextDir "super-secret.cred" "MASTER_KEY=lanzarote")
];
testScript = ''
machine.start()
contents = machine.succeed("cat /.extra/global_credentials/super-secret.cred")
assert "MASTER_KEY=lanzarote" == contents, f"Unexpected credential contents, got: {contents}"
'';
};
}
28 changes: 28 additions & 0 deletions rust/stub/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
[package]
name = "lanzaboote_stub"
version = "0.1.0"
edition = "2021"
publish = false
# For UEFI target
rust-version = "1.68"

[dependencies]
uefi = { version = "0.20.0", default-features = false, features = [ "alloc", "global_allocator" ] }
uefi-services = { version = "0.17.0", default-features = false, features = [ "panic_handler", "logger" ] }
goblin = { version = "0.6.1", default-features = false, features = [ "pe64", "alloc" ]}
bitflags = "2.2.1"

# Even in debug builds, we don't enable the debug logs, because they generate a lot of spam from goblin.
log = { version = "0.4.17", default-features = false, features = [ "max_level_info", "release_max_level_warn" ]}

# Use software implementation because the UEFI target seems to need it.
sha2 = { version = "0.10.6", default-features = false, features = ["force-soft"] }
# SHA1 for TPM TCG interface version 1.
sha1_smol = "1.0.0"
# std::io for alloc/no_std
# FIXME: I don't want this extra dependency actually.
acid_io = { git = "https://github.com/dataphract/acid_io", default-features = false, features = [ "alloc" ] }

[profile.release]
opt-level = "s"
lto = true
Loading