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 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 = {
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+
118151 ] ;
119152
120153 allVariants =
Original file line number Diff line number Diff line change 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 = ''
Original file line number Diff line number Diff line change 99 user
1010 vcpu mem balloon initialBalloonMem hotplugMem hotpluggedMem interfaces volumes shares devices vsock
1111 kernel initrdPath
12- storeDisk storeOnDisk ;
12+ storeDisk storeOnDisk credentialFiles ;
1313in {
1414 command =
1515 if user != null
2222 then throw "alioth does not support hotplugMem"
2323 else if hotpluggedMem != 0
2424 then throw "alioth does not support hotpluggedMem"
25+ else if credentialFiles != { }
26+ then throw "alioth does not support credentialFiles"
2527 else builtins . concatStringsSep " " (
2628 [
2729 "${ pkgs . alioth } /bin/alioth" "run"
Original file line number Diff line number Diff line change 77
88let
99 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 ;
1111 inherit ( microvmConfig . cloud-hypervisor ) platformOEMStrings extraArgs ;
1212
1313 hasUserConsole = ( extractOptValues "--console" extraArgs ) . values != [ ] ;
147147 command =
148148 if user != null
149149 then throw "cloud-hypervisor will not change user"
150+ else if credentialFiles != { }
151+ then throw "cloud-hypervisor does not support credentialFiles"
150152 else lib . escapeShellArgs (
151153 [
152154 ( if graphics . enable
Original file line number Diff line number Diff line change 99 inherit ( pkgs . stdenv ) system ;
1010 inherit ( microvmConfig )
1111 vcpu mem balloon initialBalloonMem hotplugMem hotpluggedMem user volumes shares
12- socket devices vsock graphics
12+ socket devices vsock graphics credentialFiles
1313 kernel initrdPath storeDisk storeOnDisk ;
1414 inherit ( microvmConfig . crosvm ) pivotRoot extraArgs ;
1515
5353 then throw "crosvm does not support hotplugMem"
5454 else if hotpluggedMem != 0
5555 then throw "crosvm does not support hotpluggedMem"
56+ else if credentialFiles != { }
57+ then throw "crosvm does not support credentialFiles"
5658 else lib . escapeShellArgs (
5759 [
5860 "${ pkgs . crosvm } /bin/crosvm" "run"
Original file line number Diff line number Diff line change 1010 vcpu mem balloon initialBalloonMem hotplugMem hotpluggedMem
1111 interfaces volumes shares devices
1212 kernel initrdPath
13- storeDisk ;
13+ storeDisk credentialFiles ;
1414 inherit ( microvmConfig . firecracker ) cpu ;
1515
1616 kernelPath = {
8383 then throw "hotplugMem not implemented for Firecracker"
8484 else if hotpluggedMem != 0
8585 then throw "hotpluggedMem not implemented for Firecracker"
86+ else if credentialFiles != { }
87+ then throw "credentialFiles are not implemented for Firecracker"
8688 else lib . escapeShellArgs [
8789 "${ pkgs . firecracker } /bin/firecracker"
8890 "--config-file" configFile
Original file line number Diff line number Diff line change 88 inherit ( microvmConfig )
99 hostName preStart user
1010 vcpu mem balloon initialBalloonMem hotplugMem hotpluggedMem interfaces volumes shares devices vsock
11- kernel initrdPath
11+ kernel initrdPath credentialFiles
1212 storeDisk storeOnDisk ;
1313in {
1414 preStart = ''
2525 then throw "kvmtool does not support hotplugMem"
2626 else if hotpluggedMem != 0
2727 then throw "kvmtool does not support hotpluggedMem"
28+ else if credentialFiles != { }
29+ then throw "kvmtool does not support credentialFiles"
2830 else builtins . concatStringsSep " " (
2931 [
3032 "${ pkgs . kvmtool } /bin/lkvm" "run"
Original file line number Diff line number Diff line change 4949
5050 qemu = overrideQemu qemuPkg ;
5151
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 ;
5353 inherit ( microvmConfig . qemu ) machine extraArgs serialConsole ;
5454
5555
155155 then "console=ttyAMA0"
156156 else "" ;
157157
158+ systemdCredentialStrings = lib . mapAttrsToList ( name : path : "name=opt/io.systemd.credentials/${ name } ,file=${ path } " ) credentialFiles ;
159+ fwCfgOptions = systemdCredentialStrings ;
158160
159161in
160162lib . warnIf ( mem == 2048 ) ''
@@ -188,6 +190,9 @@ lib.warnIf (mem == 2048) ''
188190 "-chardev" "stdio,id=stdio,signal=off"
189191 "-device" "virtio-rng-${ devType } "
190192 ] ++
193+ lib . optionals ( fwCfgOptions != [ ] ) [
194+ "-fw_cfg" ( lib . concatStringsSep "," fwCfgOptions )
195+ ] ++
191196 lib . optionals serialConsole [
192197 "-serial" "chardev:stdio"
193198 ] ++
Original file line number Diff line number Diff line change 1111 inherit ( microvmConfig )
1212 hostName
1313 vcpu mem balloon initialBalloonMem hotplugMem hotpluggedMem interfaces shares socket forwardPorts devices
14- kernel initrdPath
14+ kernel initrdPath credentialFiles
1515 storeOnDisk storeDisk ;
1616
1717 tapMultiQueue = vcpu > 1 ;
7979 then throw "stratovirt does not support hotplugMem"
8080 else if hotpluggedMem != 0
8181 then throw "stratovirt does not support hotpluggedMem"
82+ else if credentialFiles != { }
83+ then throw "stratovirt does not support credentialFiles"
8284 else lib . escapeShellArgs (
8385 [
8486 "${ pkgs . expect } /bin/unbuffer"
Original file line number Diff line number Diff line change 675675 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.
676676 '' ;
677677 } ;
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+ } ;
678691 } ;
679692
680693 imports = [
You can’t perform that action at this time.
0 commit comments