Skip to content

Commit 1f22606

Browse files
committed
feat: Add testing for microvm.credentialFiles
1 parent 2bb7e39 commit 1f22606

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

checks/default.nix

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,37 @@ let
115115
imports = [ "${modulesPath}/profiles/hardened.nix" ];
116116
}) ];
117117
} ]
118+
119+
[ {
120+
# no
121+
id = null;
122+
} {
123+
id = "credentials";
124+
modules = [ ({ config, pkgs, ... }: {
125+
# This is the guest vm config
126+
microvm.credentialFiles.SECRET_BOOTSRAP_KEY = "/etc/microvm-bootstrap.secret";
127+
microvm.testing.enableTest = builtins.elem config.microvm.hypervisor [
128+
# Hypervisors that support systemd credentials
129+
"qemu"
130+
];
131+
# TODO: need to somehow have the test harness check for the success or failure of this service.
132+
systemd.services.test-secret-availability = {
133+
serviceConfig = {
134+
ImportCredential = "SECRET_BOOTSRAP_KEY";
135+
Restart = "no";
136+
};
137+
path = [ pkgs.gnugrep pkgs.coreutils ];
138+
script = ''
139+
cat $CREDENTIALS_DIRECTORY/SECRET_BOOTSRAP_KEY | grep -q "i am super secret"
140+
if [ $? -ne 0 ]; then
141+
echo "Secret not found at $CREDENTIALS_DIRECTORY/SECRET_BOOTSRAP_KEY"
142+
exit 1
143+
fi
144+
'';
145+
};
146+
}) ];
147+
} ]
148+
118149
];
119150

120151
allVariants =

checks/vm.nix

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
# Must be big enough for the store overlay volume
1818
virtualisation.diskSize = 4096;
1919

20+
environment.etc."microvm-bootstrap.secret".text = "i am super secret";
21+
2022
microvm.vms."${system}-${hypervisor}-example".flake = self;
2123
};
2224
testScript = ''

nixos-modules/microvm/options.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,7 @@ in
678678

679679
credentialFiles = mkOption {
680680
type = with types; attrsOf path;
681+
default = {};
681682
description = ''
682683
Key-value pairs of credential files that will be loaded into the vm using systemd's io.systemd.credential feature.
683684
'';

0 commit comments

Comments
 (0)