Skip to content

Commit fdbff90

Browse files
committed
feat: Add microvm.credentialFiles for passing credentials to guests
This commit implements `microvm.credentialFiles` a mechanism for passing credentials into guest vms from the host. Currently only support for qemu is implemented as I want to test the waters to see if you're interested in this feature, Astro. In addition to qmeu cloud-hypervisor can be supported via smbios. But it depends on [this feature being added](cloud-hypervisor/cloud-hypervisor#6951 (comment)), and also microvm-nix#336 being merged to microvm.nix cloud-hypervisor could be supported immediately, but then the secrets would be visible in the ps output. A cursory code search shows that the following additional hypervisors could be supported: - crosvm: via fw_cfg, or smbios - alioth: via fw_cfg - stratovirt: via fw_cfg (maybe smbios) kvmtool and firecracker both seem like they cannot be supported. Related: - microvm-nix#259 - microvm-nix#52
1 parent a887694 commit fdbff90

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/runners/qemu.nix

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ let
4747

4848
qemu = overrideQemu qemuPkg;
4949

50-
inherit (microvmConfig) hostName vcpu mem balloon initialBalloonMem deflateOnOOM hotplugMem hotpluggedMem user interfaces shares socket forwardPorts devices vsock graphics storeOnDisk kernel initrdPath storeDisk;
50+
inherit (microvmConfig) hostName vcpu mem balloon initialBalloonMem deflateOnOOM hotplugMem hotpluggedMem user interfaces shares socket forwardPorts devices vsock graphics storeOnDisk kernel initrdPath storeDisk credentialFiles;
5151
inherit (microvmConfig.qemu) machine extraArgs serialConsole;
5252

5353
inherit (import ../. { inherit (pkgs) lib; }) withDriveLetters;
@@ -154,6 +154,8 @@ let
154154
then "console=ttyAMA0"
155155
else "";
156156

157+
systemdCredentialStrings = lib.mapAttrsToList (name: path: "name=opt/io.systemd.credentials/${name},file=${path}" ) credentialFiles;
158+
fwCfgOptions = systemdCredentialStrings;
157159

158160
in
159161
lib.warnIf (mem == 2048) ''
@@ -187,6 +189,9 @@ lib.warnIf (mem == 2048) ''
187189
"-chardev" "stdio,id=stdio,signal=off"
188190
"-device" "virtio-rng-${devType}"
189191
] ++
192+
lib.optionals (fwCfgOptions != []) [
193+
"-fw_cfg" (lib.concatStringsSep "," fwCfgOptions)
194+
] ++
190195
lib.optionals serialConsole [
191196
"-serial" "chardev:stdio"
192197
] ++

nixos-modules/microvm/options.nix

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -660,6 +660,18 @@ in
660660
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.
661661
'';
662662
};
663+
664+
credentialFiles = mkOption {
665+
type = with types; attrsOf path;
666+
description = ''
667+
Key-value pairs of credential files that will be loaded into the vm using systemd's io.systemd.credential feature.
668+
'';
669+
example = literalExpression /* nix */ ''
670+
{
671+
SOPS_AGE_KEY = "/run/secrets/guest_microvm_age_key";
672+
}
673+
'';
674+
};
663675
};
664676

665677
imports = [

0 commit comments

Comments
 (0)