mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-12-29 00:53:57 +00:00
4f0dadbf38
After final improvements to the official formatter implementation, this commit now performs the first treewide reformat of Nix files using it. This is part of the implementation of RFC 166. Only "inactive" files are reformatted, meaning only files that aren't being touched by any PR with activity in the past 2 months. This is to avoid conflicts for PRs that might soon be merged. Later we can do a full treewide reformat to get the rest, which should not cause as many conflicts. A CI check has already been running for some time to ensure that new and already-formatted files are formatted, so the files being reformatted here should also stay formatted. This commit was automatically created and can be verified using nix-builda08b3a4d19
.tar.gz \ --argstr baseRevb32a094368
result/bin/apply-formatting $NIXPKGS_PATH
94 lines
3.4 KiB
Nix
94 lines
3.4 KiB
Nix
import ./make-test-python.nix (
|
|
{ pkgs, ... }:
|
|
{
|
|
name = "tang";
|
|
meta = with pkgs.lib.maintainers; {
|
|
maintainers = [ jfroche ];
|
|
};
|
|
|
|
nodes.server =
|
|
{
|
|
config,
|
|
pkgs,
|
|
modulesPath,
|
|
...
|
|
}:
|
|
{
|
|
imports = [
|
|
"${modulesPath}/../tests/common/auto-format-root-device.nix"
|
|
];
|
|
virtualisation = {
|
|
emptyDiskImages = [ 512 ];
|
|
useBootLoader = true;
|
|
useEFIBoot = true;
|
|
# This requires to have access
|
|
# to a host Nix store as
|
|
# the new root device is /dev/vdb
|
|
# an empty 512MiB drive, containing no Nix store.
|
|
mountHostNixStore = true;
|
|
};
|
|
|
|
boot.loader.systemd-boot.enable = true;
|
|
|
|
networking.interfaces.eth1.ipv4.addresses = [
|
|
{
|
|
address = "192.168.0.1";
|
|
prefixLength = 24;
|
|
}
|
|
];
|
|
|
|
environment.systemPackages = with pkgs; [
|
|
clevis
|
|
tang
|
|
cryptsetup
|
|
];
|
|
services.tang = {
|
|
enable = true;
|
|
ipAddressAllow = [ "127.0.0.1/32" ];
|
|
};
|
|
};
|
|
testScript = ''
|
|
start_all()
|
|
machine.wait_for_unit("sockets.target")
|
|
|
|
with subtest("Check keys are generated"):
|
|
machine.wait_until_succeeds("curl -v http://127.0.0.1:7654/adv")
|
|
key = machine.wait_until_succeeds("tang-show-keys 7654")
|
|
|
|
with subtest("Check systemd access list"):
|
|
machine.succeed("ping -c 3 192.168.0.1")
|
|
machine.fail("curl -v --connect-timeout 3 http://192.168.0.1:7654/adv")
|
|
|
|
with subtest("Check basic encrypt and decrypt message"):
|
|
machine.wait_until_succeeds(f"""echo 'Hello World' | clevis encrypt tang '{{ "url": "http://127.0.0.1:7654", "thp":"{key}"}}' > /tmp/encrypted""")
|
|
decrypted = machine.wait_until_succeeds("clevis decrypt < /tmp/encrypted")
|
|
assert decrypted.strip() == "Hello World"
|
|
machine.wait_until_succeeds("tang-show-keys 7654")
|
|
|
|
with subtest("Check encrypt and decrypt disk"):
|
|
machine.succeed("cryptsetup luksFormat --force-password --batch-mode /dev/vdb <<<'password'")
|
|
machine.succeed(f"""clevis luks bind -s1 -y -f -d /dev/vdb tang '{{ "url": "http://127.0.0.1:7654", "thp":"{key}" }}' <<< 'password' """)
|
|
clevis_luks = machine.succeed("clevis luks list -d /dev/vdb")
|
|
assert clevis_luks.strip() == """1: tang '{"url":"http://127.0.0.1:7654"}'"""
|
|
machine.succeed("clevis luks unlock -d /dev/vdb")
|
|
machine.succeed("find /dev/mapper -name 'luks*' -exec cryptsetup close {} +")
|
|
machine.succeed("clevis luks unlock -d /dev/vdb")
|
|
machine.succeed("find /dev/mapper -name 'luks*' -exec cryptsetup close {} +")
|
|
# without tang available, unlock should fail
|
|
machine.succeed("systemctl stop tangd.socket")
|
|
machine.fail("clevis luks unlock -d /dev/vdb")
|
|
machine.succeed("systemctl start tangd.socket")
|
|
|
|
with subtest("Rotate server keys"):
|
|
machine.succeed("${pkgs.tang}/libexec/tangd-rotate-keys -d /var/lib/tang")
|
|
machine.succeed("clevis luks unlock -d /dev/vdb")
|
|
machine.succeed("find /dev/mapper -name 'luks*' -exec cryptsetup close {} +")
|
|
|
|
with subtest("Test systemd service security"):
|
|
output = machine.succeed("systemd-analyze security tangd@.service")
|
|
machine.log(output)
|
|
assert output[-9:-1] == "SAFE :-}"
|
|
'';
|
|
}
|
|
)
|