贺培轩
2022-Oct-14 03:11 UTC
Qeustion about how to use domsetlaunchsecstate command correctly.
Hello, I'm new to libvirt. I have tried to launch a sev vm with secret injection recently, and I found the command domsetlaunchsecstate is what I need. But I had some problem to make it work. Here is what I did to use this command. 1. run command: virsh create sev-guest.xml 2. create secret header file and secret file. 3. run command: virsh domsetlaunchsecstate sev-guest-1 --secrethdr <hdr-filename> --secret <secret-filename> . But it will report this error: SEV: not in correct state. I think it is because the vm is not in a paused state. So how can I launch a sev vm which is in a paused state? How should I revise my xml file? The sev-guest.xml I use is as follows: <domain type="kvm"> <name>sev-guest-1</name> <uuid>d50a4205-40e0-4482-b0dc-f26bb4a1a9ff</uuid> <metadata> <libosinfo:libosinfo xmlns:libosinfo=" http://libosinfo.org/xmlns/libvirt/domain/1.0"> <libosinfo:os id="http://ubuntu.com/ubuntu/16.04"/> </libosinfo:libosinfo> </metadata> <memory>4194304</memory> <currentMemory>4194304</currentMemory> <memtune> <hard_limit>4563402</hard_limit> </memtune> <vcpu>32</vcpu> <cpu mode='custom' match='exact' check='partial'> <model fallback='forbid'>EPYC</model> </cpu> <os> <type arch="x86_64" machine="q35">hvm</type> <loader readonly="yes" type="pflash">/data01/OVMF.fd</loader> <nvram template="/data01/OVMF.fd">/var/lib/libvirt/qemu/nvram/sev-guest-1_VARS.fd</nvram> <boot dev="hd"/> </os> <features> <acpi/> <apic/> </features> <clock offset="utc"> <timer name="rtc" tickpolicy="catchup"/> <timer name="pit" tickpolicy="delay"/> <timer name="hpet" present="no"/> </clock> <pm> <suspend-to-mem enabled="no"/> <suspend-to-disk enabled="no"/> </pm> <devices> <emulator>/usr/local/bin/qemu-system-x86_64</emulator> <disk type="file" device="disk"> <driver name="qemu" type="qcow2"/> <source file="/data01/AMDSEV/sev-guest-1.qcow2"/> <target dev="sda" bus="scsi"/> </disk> <controller type="scsi" index="0" model="virtio-scsi"> <driver iommu="on"/> </controller> <controller type="virtio-serial" index="0"> <driver iommu="on"/> </controller> <controller type="usb" index="0" model="ich9-ehci1"/> <controller type="usb" index="0" model="ich9-uhci1"> <master startport="0"/> </controller> <controller type="usb" index="0" model="ich9-uhci2"> <master startport="2"/> </controller> <controller type="usb" index="0" model="ich9-uhci3"> <master startport="4"/> </controller> <controller type='pci' index='1' model='pcie-root-port'> <model name='pcie-root-port'/> <target chassis='1' port='0x8'/> <alias name='pci.1'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x0' multifunction='on'/> </controller> <controller type='pci' index='2' model='pcie-root-port'> <model name='pcie-root-port'/> <target chassis='2' port='0x9'/> <alias name='pci.2'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x1'/> </controller> <controller type='pci' index='3' model='pcie-root-port'> <model name='pcie-root-port'/> <target chassis='3' port='0xa'/> <alias name='pci.3'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x2'/> </controller> <controller type='pci' index='4' model='pcie-root-port'> <model name='pcie-root-port'/> <target chassis='4' port='0xb'/> <alias name='pci.4'/> <address type='pci' domain='0x0000' bus='0x00' slot='0x02' function='0x3'/> </controller> <console type="pty"/> <input type="tablet" bus="usb"/> <graphics type="vnc" port="-1" listen="127.0.0.1"/> <video> <model type="vga"/> <address type='pci' slot='0x07'/> </video> <memballoon model="virtio"> <driver iommu="on"/> </memballoon> </devices> <launchSecurity type="sev"> <cbitpos>51</cbitpos> <reducedPhysBits>1</reducedPhysBits> <policy>0x05</policy> <dhCert>XXXXXXXXX</dhCert> <session>XXXXXXXXXXXXXXXXx</session> </launchSecurity> </domain> Thank you in advance, Peixuan -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://listman.redhat.com/archives/libvirt-users/attachments/20221014/476e946a/attachment.htm>
Daniel P. Berrangé
2022-Oct-14 07:53 UTC
Qeustion about how to use domsetlaunchsecstate command correctly.
On Fri, Oct 14, 2022 at 11:11:08AM +0800, ??? wrote:> Hello, > I'm new to libvirt. I have tried to launch a sev vm with secret > injection recently, and I found the command domsetlaunchsecstate is what I > need. But I had some problem to make it work. Here is what I did to use > this command. > 1. run command: virsh create sev-guest.xml > 2. create secret header file and secret file. > 3. run command: virsh domsetlaunchsecstate sev-guest-1 > --secrethdr <hdr-filename> --secret <secret-filename> . > But it will report this error: SEV: not in correct state. > I think it is because the vm is not in a paused state. So how can I launch > a sev vm which is in a paused state? How should I revise my xml file?Just pass the --paused flag, eg $ virsh create --paused sev-guest.xml Note, that before injecting sectrets to the guest, you would want to perform an attestation to validate the boot measurement is what is expected. https://listman.redhat.com/archives/libvir-list/2022-October/234729.html The next release of libvirt is likley to include a script which handles the attestation and can inject a secret when it succeeds: https://gitlab.com/berrange/libvirt/-/blob/lgtm-vm/tools/virt-qemu-sev-validate See docs showing usage here: https://gitlab.com/berrange/libvirt/-/blob/lgtm-vm/docs/manpages/virt-qemu-sev-validate.rst#examples This script is hardcoded to inject a LUKS disk secret, as defined by the OVMF amdsev build flavour. I'm curious what kind of secret you are wanting to inject, and whether our tool needs extending to cope with other secrets besides the disk.> The sev-guest.xml I use is as follows: > <domain type="kvm"> > <name>sev-guest-1</name> > <uuid>d50a4205-40e0-4482-b0dc-f26bb4a1a9ff</uuid> > <metadata> > <libosinfo:libosinfo xmlns:libosinfo=" > http://libosinfo.org/xmlns/libvirt/domain/1.0"> > <libosinfo:os id="http://ubuntu.com/ubuntu/16.04"/> > </libosinfo:libosinfo> > </metadata> > <memory>4194304</memory> > <currentMemory>4194304</currentMemory> > <memtune> > <hard_limit>4563402</hard_limit> > </memtune> > <vcpu>32</vcpu> > <cpu mode='custom' match='exact' check='partial'> > <model fallback='forbid'>EPYC</model> > </cpu> > <os> > <type arch="x86_64" machine="q35">hvm</type> > <loader readonly="yes" type="pflash">/data01/OVMF.fd</loader> > <nvram > template="/data01/OVMF.fd">/var/lib/libvirt/qemu/nvram/sev-guest-1_VARS.fd</nvram>For use with SEV, if you want to perform attestation prior to injecting a disk secret, then use of a stateless firmware (ie no NVRAM) is strongly recommended, otherwise the NVRAM can be used to undermine the integrity of the guest from a malicious host. With regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|