File tree Expand file tree Collapse file tree 10 files changed +72
-7
lines changed Expand file tree Collapse file tree 10 files changed +72
-7
lines changed Original file line number Diff line number Diff line change 115
115
imports = [ "${ modulesPath } /profiles/hardened.nix" ] ;
116
116
} ) ] ;
117
117
} ]
118
+
119
+ [ {
120
+ # no
121
+ id = null ;
122
+ } {
123
+ id = "credentials" ;
124
+ modules = [ ( { config , pkgs , ... } : {
125
+ # This is the guest vm config
126
+ microvm = {
127
+ credentialFiles . SECRET_BOOTSTRAP_KEY = "/etc/microvm-bootstrap.secret" ;
128
+ testing . enableTest = builtins . elem config . microvm . hypervisor [
129
+ # Hypervisors that support systemd credentials
130
+ "qemu"
131
+ ] ;
132
+ } ;
133
+ # TODO: need to somehow have the test harness check for the success or failure of this service.
134
+ systemd . services . test-secret-availability = {
135
+ serviceConfig = {
136
+ ImportCredential = "SECRET_BOOTSTRAP_KEY" ;
137
+ Restart = "no" ;
138
+ } ;
139
+ path = [ pkgs . gnugrep pkgs . coreutils ] ;
140
+ script = ''
141
+ cat $CREDENTIALS_DIRECTORY/SECRET_BOOTSTRAP_KEY | grep -q "i am super secret"
142
+ if [ $? -ne 0 ]; then
143
+ echo "Secret not found at $CREDENTIALS_DIRECTORY/SECRET_BOOTSTRAP_KEY"
144
+ exit 1
145
+ fi
146
+ '' ;
147
+ } ;
148
+ } ) ] ;
149
+ } ]
150
+
118
151
] ;
119
152
120
153
allVariants =
Original file line number Diff line number Diff line change 17
17
# Must be big enough for the store overlay volume
18
18
virtualisation . diskSize = 4096 ;
19
19
20
+ environment . etc . "microvm-bootstrap.secret" . text = "i am super secret" ;
21
+
20
22
microvm . vms . "${ system } -${ hypervisor } -example" . flake = self ;
21
23
} ;
22
24
testScript = ''
Original file line number Diff line number Diff line change 9
9
user
10
10
vcpu mem balloon initialBalloonMem hotplugMem hotpluggedMem interfaces volumes shares devices vsock
11
11
kernel initrdPath
12
- storeDisk storeOnDisk ;
12
+ storeDisk storeOnDisk credentialFiles ;
13
13
in {
14
14
command =
15
15
if user != null
22
22
then throw "alioth does not support hotplugMem"
23
23
else if hotpluggedMem != 0
24
24
then throw "alioth does not support hotpluggedMem"
25
+ else if credentialFiles != { }
26
+ then throw "alioth does not support credentialFiles"
25
27
else builtins . concatStringsSep " " (
26
28
[
27
29
"${ pkgs . alioth } /bin/alioth" "run"
Original file line number Diff line number Diff line change 7
7
8
8
let
9
9
inherit ( pkgs ) lib ;
10
- inherit ( microvmConfig ) vcpu mem balloon initialBalloonMem deflateOnOOM hotplugMem hotpluggedMem user interfaces volumes shares socket devices hugepageMem graphics storeDisk storeOnDisk kernel initrdPath ;
10
+ inherit ( microvmConfig ) vcpu mem balloon initialBalloonMem deflateOnOOM hotplugMem hotpluggedMem user interfaces volumes shares socket devices hugepageMem graphics storeDisk storeOnDisk kernel initrdPath credentialFiles ;
11
11
inherit ( microvmConfig . cloud-hypervisor ) platformOEMStrings extraArgs ;
12
12
13
13
hasUserConsole = ( extractOptValues "--console" extraArgs ) . values != [ ] ;
147
147
command =
148
148
if user != null
149
149
then throw "cloud-hypervisor will not change user"
150
+ else if credentialFiles != { }
151
+ then throw "cloud-hypervisor does not support credentialFiles"
150
152
else lib . escapeShellArgs (
151
153
[
152
154
( if graphics . enable
Original file line number Diff line number Diff line change 9
9
inherit ( pkgs . stdenv ) system ;
10
10
inherit ( microvmConfig )
11
11
vcpu mem balloon initialBalloonMem hotplugMem hotpluggedMem user volumes shares
12
- socket devices vsock graphics
12
+ socket devices vsock graphics credentialFiles
13
13
kernel initrdPath storeDisk storeOnDisk ;
14
14
inherit ( microvmConfig . crosvm ) pivotRoot extraArgs ;
15
15
53
53
then throw "crosvm does not support hotplugMem"
54
54
else if hotpluggedMem != 0
55
55
then throw "crosvm does not support hotpluggedMem"
56
+ else if credentialFiles != { }
57
+ then throw "crosvm does not support credentialFiles"
56
58
else lib . escapeShellArgs (
57
59
[
58
60
"${ pkgs . crosvm } /bin/crosvm" "run"
Original file line number Diff line number Diff line change 10
10
vcpu mem balloon initialBalloonMem hotplugMem hotpluggedMem
11
11
interfaces volumes shares devices
12
12
kernel initrdPath
13
- storeDisk ;
13
+ storeDisk credentialFiles ;
14
14
inherit ( microvmConfig . firecracker ) cpu ;
15
15
16
16
kernelPath = {
83
83
then throw "hotplugMem not implemented for Firecracker"
84
84
else if hotpluggedMem != 0
85
85
then throw "hotpluggedMem not implemented for Firecracker"
86
+ else if credentialFiles != { }
87
+ then throw "credentialFiles are not implemented for Firecracker"
86
88
else lib . escapeShellArgs [
87
89
"${ pkgs . firecracker } /bin/firecracker"
88
90
"--config-file" configFile
Original file line number Diff line number Diff line change 8
8
inherit ( microvmConfig )
9
9
hostName preStart user
10
10
vcpu mem balloon initialBalloonMem hotplugMem hotpluggedMem interfaces volumes shares devices vsock
11
- kernel initrdPath
11
+ kernel initrdPath credentialFiles
12
12
storeDisk storeOnDisk ;
13
13
in {
14
14
preStart = ''
25
25
then throw "kvmtool does not support hotplugMem"
26
26
else if hotpluggedMem != 0
27
27
then throw "kvmtool does not support hotpluggedMem"
28
+ else if credentialFiles != { }
29
+ then throw "kvmtool does not support credentialFiles"
28
30
else builtins . concatStringsSep " " (
29
31
[
30
32
"${ pkgs . kvmtool } /bin/lkvm" "run"
Original file line number Diff line number Diff line change 49
49
50
50
qemu = overrideQemu qemuPkg ;
51
51
52
- inherit ( microvmConfig ) hostName vcpu mem balloon initialBalloonMem deflateOnOOM hotplugMem hotpluggedMem user interfaces shares socket forwardPorts devices vsock graphics storeOnDisk kernel initrdPath storeDisk ;
52
+ inherit ( microvmConfig ) hostName vcpu mem balloon initialBalloonMem deflateOnOOM hotplugMem hotpluggedMem user interfaces shares socket forwardPorts devices vsock graphics storeOnDisk kernel initrdPath storeDisk credentialFiles ;
53
53
inherit ( microvmConfig . qemu ) machine extraArgs serialConsole ;
54
54
55
55
155
155
then "console=ttyAMA0"
156
156
else "" ;
157
157
158
+ systemdCredentialStrings = lib . mapAttrsToList ( name : path : "name=opt/io.systemd.credentials/${ name } ,file=${ path } " ) credentialFiles ;
159
+ fwCfgOptions = systemdCredentialStrings ;
158
160
159
161
in
160
162
lib . warnIf ( mem == 2048 ) ''
@@ -188,6 +190,9 @@ lib.warnIf (mem == 2048) ''
188
190
"-chardev" "stdio,id=stdio,signal=off"
189
191
"-device" "virtio-rng-${ devType } "
190
192
] ++
193
+ lib . optionals ( fwCfgOptions != [ ] ) [
194
+ "-fw_cfg" ( lib . concatStringsSep "," fwCfgOptions )
195
+ ] ++
191
196
lib . optionals serialConsole [
192
197
"-serial" "chardev:stdio"
193
198
] ++
Original file line number Diff line number Diff line change 11
11
inherit ( microvmConfig )
12
12
hostName
13
13
vcpu mem balloon initialBalloonMem hotplugMem hotpluggedMem interfaces shares socket forwardPorts devices
14
- kernel initrdPath
14
+ kernel initrdPath credentialFiles
15
15
storeOnDisk storeDisk ;
16
16
17
17
tapMultiQueue = vcpu > 1 ;
79
79
then throw "stratovirt does not support hotplugMem"
80
80
else if hotpluggedMem != 0
81
81
then throw "stratovirt does not support hotpluggedMem"
82
+ else if credentialFiles != { }
83
+ then throw "stratovirt does not support credentialFiles"
82
84
else lib . escapeShellArgs (
83
85
[
84
86
"${ pkgs . expect } /bin/unbuffer"
Original file line number Diff line number Diff line change 675
675
This is required for commands like `microvm -l` to function but removes reference to the uncompressed store content when using a disk image for the nix store.
676
676
'' ;
677
677
} ;
678
+
679
+ credentialFiles = mkOption {
680
+ type = with types ; attrsOf path ;
681
+ default = { } ;
682
+ description = ''
683
+ Key-value pairs of credential files that will be loaded into the vm using systemd's io.systemd.credential feature.
684
+ '' ;
685
+ example = literalExpression /* nix */ ''
686
+ {
687
+ SOPS_AGE_KEY = "/run/secrets/guest_microvm_age_key";
688
+ }
689
+ '' ;
690
+ } ;
678
691
} ;
679
692
680
693
imports = [
You can’t perform that action at this time.
0 commit comments