Linux machine with a real vTPM#
For the break-test rows that need an actual TPM character device rather than swtpm over
TCP. The host needs libvirt/KVM, QEMU's TPM emulator, qemu-img, virsh, and either
cloud-localds or genisoimage, plus an SSH public key for the nac guest account.
swtpm covers the TPM behaviour, but two things live in the kernel driver and cannot be
reached through it: that /dev/tpmrm0 is the right device to open, and what happens when
something else holds the raw /dev/tpm0. Both decide whether the agent coexists with the
other software on a workstation, and neither fails in testing — they fail on the one
machine that also runs a disk-encryption tool.
Bring it up#
Run from the repository root:
nac_image_dir=$(mktemp -d)
curl -fL -o "$nac_image_dir/noble-cloud.img" \
https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img
qemu-img convert -O qcow2 "$nac_image_dir/noble-cloud.img" \
"$nac_image_dir/nac-vtpm.qcow2"
sudo install -d /var/lib/libvirt/images
sudo install -m 0600 -o libvirt-qemu -g kvm "$nac_image_dir/nac-vtpm.qcow2" \
/var/lib/libvirt/images/nac-vtpm.qcow2
rm -rf "$nac_image_dir"
if ! sudo virsh net-info nac-test >/dev/null 2>&1; then
sudo virsh net-define testbed/windows/network.xml
fi
if ! sudo virsh net-info nac-test | grep -q 'Active:.*yes'; then
sudo virsh net-start nac-test
fi
sudo virsh net-autostart nac-test
testbed/linux-vtpm/seed.sh # renders user-data.template, writes the seed ISO
sudo virsh define testbed/linux-vtpm/domain.xml
sudo virsh start nac-vtpm
The commands above use Ubuntu's libvirt-qemu:kvm ownership for the disk; use the
QEMU account and group configured by your host if they differ. After boot, find the
guest address with sudo virsh net-dhcp-leases nac-test, then connect as nac using
the SSH key whose public half was used by seed.sh.
seed.sh takes the authorised key from $SSH_AUTHORIZED_KEY or from your own
~/.ssh/*.pub, because the repository is the wrong place for one: a key committed
here is one person's login on every machine anybody builds from this tree. Run it as
yourself — it asks for sudo only to put the ISO where libvirt reads it.
Run the suite against the real device#
go test -c -o /tmp/keystore.test ./internal/keystore
scp /tmp/keystore.test nac@<ip>:/tmp/
ssh nac@<ip> 'sudo NAC_TEST_TPM_DEVICE=/dev/tpmrm0 /tmp/keystore.test -test.v'
NAC_TEST_TPM_DEVICE makes the whole TPM suite use the real device instead of starting
swtpm. Two tests still start their own software TPM regardless — the substituted-machine
case and the EK stability check need a second, different TPM, and a machine only has
one.