---
title: "Run a Guest Notary"
description: "Boot a QEMU VM on a hardware-rooted vTPM, install the Linux notary inside it, and verify that a manifest from the guest chains back to the host's hardware."
source: "EQTY Notary"
---
This tutorial gives a Linux VM a TPM rooted in the host's TPM or Secure Enclave, runs the notary
inside the VM on that TPM, and checks that a credential from the guest chains to the host. It
works the same on a Linux workstation with KVM and a hardware TPM, and on an Apple silicon Mac
with HVF and the Secure Enclave. You need:

- A host notary with the [swtpm-notary](/notary-backed-vtpm/install/) fork installed, so new vTPMs are
  hardware-rooted. Check with `eqty-notaryctl vtpm show`: `backing=identity`, `hardwareEps=true`.
- QEMU. On a Mac: `brew install qemu xorriso`.
- The notary's Linux `.deb` for the guest's architecture, from the
  [vcomp-notary-desktop release](https://github.com/eqtylab-RND/vcomp-notary-desktop/releases):
  `_amd64` for a Linux x86_64 host, `_arm64` for a Mac.

import { Tabs, TabItem } from "@eqtylab/docs/components";

## What a guest notary adds

A guest notary on a vTPM treats it as its hardware TPM. At startup it reads the EK certificate
and chain from NV, has the IAK certify its own AK and issue the AK's certificate, and carries
all of it in its `VCompTpmV1` identity; see [Credentials](../desktop-notary/advanced/credentials.mdx#a-notary-on-a-vtpm).
Containers in the VM then sign through the guest notary and their manifests chain, through the
vTPM, to the host's hardware.

## 1. Create the vTPM

For your own user, so that QEMU runs without root:

```sh
sudo eqty-notaryctl vtpm create --id guest1 --client-uid "$(id -u)" --client-gid "$(id -g)"
eqty-notaryctl vtpm show guest1
```

QEMU needs the control socket: `/var/run/eqty-notary/vtpm/guest1.sock.ctrl`.

## 2. Prepare the VM

An Ubuntu cloud image, with cloud-init installing Docker and `tpm2-tools` and authorizing your
SSH key on first boot. The VM boots with `ima_policy=tcb` later, in step 4.

<Tabs syncKey="host">
  <TabItem label="Linux (KVM)">

```sh
mkdir -p ~/vtpm-vm && cd ~/vtpm-vm
curl -LO https://cloud-images.ubuntu.com/releases/26.04/release/ubuntu-26.04-server-cloudimg-amd64.img
qemu-img create -f qcow2 -F qcow2 -b ubuntu-26.04-server-cloudimg-amd64.img disk.qcow2 20G
cp /usr/share/OVMF/OVMF_VARS_4M.fd vars.fd
```

  </TabItem>
  <TabItem label="macOS (HVF)">

```sh
mkdir -p ~/vtpm-vm && cd ~/vtpm-vm
curl -LO https://cloud-images.ubuntu.com/releases/26.04/release/ubuntu-26.04-server-cloudimg-arm64.img
qemu-img create -f qcow2 -F qcow2 -b ubuntu-26.04-server-cloudimg-arm64.img disk.qcow2 20G
cp "$(brew --prefix qemu)/share/qemu/edk2-arm-vars.fd" vars.fd
```

  </TabItem>
</Tabs>

```sh
[ -f ~/.ssh/id_ed25519 ] || ssh-keygen -t ed25519 -N '' -f ~/.ssh/id_ed25519
mkdir -p seed
cat > seed/meta-data <<EOF2
instance-id: vtpm-vm
local-hostname: vtpm-vm
EOF2
cat > seed/user-data <<EOF2
#cloud-config
users:
  - name: ubuntu
    sudo: ALL=(ALL) NOPASSWD:ALL
    groups: [docker, tss]
    shell: /bin/bash
    ssh_authorized_keys: ["$(cat ~/.ssh/id_ed25519.pub)"]
packages: [docker.io, tpm2-tools]
EOF2
xorriso -as mkisofs -quiet -o seed.iso -V cidata -J -r seed
```

## 3. Boot with the vTPM

<Tabs syncKey="host">
  <TabItem label="Linux (KVM)">

```sh
CTRL=/var/run/eqty-notary/vtpm/guest1.sock.ctrl
qemu-system-x86_64 -machine q35,accel=kvm -cpu host -m 4096 -smp 4 \
  -drive if=pflash,format=raw,readonly=on,file=/usr/share/OVMF/OVMF_CODE_4M.fd \
  -drive if=pflash,format=raw,file=vars.fd \
  -drive if=virtio,file=disk.qcow2 \
  -drive if=virtio,format=raw,readonly=on,file=seed.iso \
  -chardev socket,id=chrtpm,path="$CTRL" \
  -tpmdev emulator,id=tpm0,chardev=chrtpm \
  -device tpm-tis,tpmdev=tpm0 \
  -netdev user,id=n0,hostfwd=tcp:127.0.0.1:2222-:22 -device virtio-net-pci,netdev=n0 \
  -display none -serial file:console.log -daemonize -pidfile qemu.pid
```

  </TabItem>
  <TabItem label="macOS (HVF)">

```sh
CTRL=/var/run/eqty-notary/vtpm/guest1.sock.ctrl
qemu-system-aarch64 -machine virt,accel=hvf -cpu host -m 4096 -smp 4 \
  -drive if=pflash,format=raw,readonly=on,file="$(brew --prefix qemu)/share/qemu/edk2-aarch64-code.fd" \
  -drive if=pflash,format=raw,file=vars.fd \
  -drive if=virtio,file=disk.qcow2 \
  -drive if=virtio,format=raw,readonly=on,file=seed.iso \
  -chardev socket,id=chrtpm,path="$CTRL" \
  -tpmdev emulator,id=tpm0,chardev=chrtpm \
  -device tpm-tis-device,tpmdev=tpm0,ppi=off \
  -netdev user,id=n0,hostfwd=tcp:127.0.0.1:2222-:22 -device virtio-net-pci,netdev=n0 \
  -display none -serial file:console.log -daemonize -pidfile qemu.pid
```

Keep `ppi=off`. QEMU 11.1 and later abort under HVF without it, with `HV_BAD_ARGUMENT`. It turns
off only the Physical Presence Interface, the guest's way to ask the firmware to clear the TPM.

  </TabItem>
</Tabs>

The three TPM lines are what matters: `-chardev` points at the notary's swtpm. The first boot
takes a minute or two while cloud-init installs packages. Then:

```sh
ssh -p 2222 ubuntu@127.0.0.1 'ls -l /dev/tpm0 /dev/tpmrm0; cloud-init status --wait'
```

## 4. Turn on IMA in the guest

The guest notary binds its quote to IMA's measurement of its own binary, so the guest kernel
must measure. Because QEMU attaches the TPM at boot, IMA extends PCR 10 in the host-rooted vTPM
from the first measurement.

```sh
ssh -p 2222 ubuntu@127.0.0.1 '
  echo "GRUB_CMDLINE_LINUX_DEFAULT=\"\$GRUB_CMDLINE_LINUX_DEFAULT ima_policy=tcb\"" | sudo tee /etc/default/grub.d/90-eqty-ima.cfg
  sudo update-grub && sudo reboot'
```

Powering the VM off stops the vTPM. If you shut the VM down rather than rebooting it, run
`eqty-notaryctl vtpm start guest1` before booting again.

## 5. Install the guest notary

Turn the Key Guardian off **before** installing: the package starts the notary immediately, and
with Key Guardian on it fetches a Key Guardian certificate that it then prefers over the vTPM
IAK's, so the chain ends at the Key Guardian instead of at your host.

```sh
scp -P 2222 eqty-notary_<version>_<arch>.deb ubuntu@127.0.0.1:
ssh -p 2222 ubuntu@127.0.0.1 '
  sudo mkdir -p /etc/systemd/system/eqty-notary.service.d
  printf "[Service]\nEnvironment=EQTY_KEY_GUARDIAN_URL=\n" | sudo tee /etc/systemd/system/eqty-notary.service.d/no-key-guardian.conf
  sudo apt-get install -y ./eqty-notary_*.deb
  until curl -sf http://127.0.0.1:8066/v1/isReady; do sleep 2; done; echo'
```

On start the guest notary reads the vTPM's EK and IAK certificates from NV, creates its own AK and
has the IAK certify it, quotes PCR 9 and 10, and issues its `VCompTpmV1` identity with all of
that as evidence. Readiness takes about 30 seconds.

## 6. Check the chain

In the guest, the certificates verify with OpenSSL alone: EK to root, and AK to IAK to root.

```sh
ssh -p 2222 ubuntu@127.0.0.1 '
  cd /tmp
  sudo tpm2_nvread 0x01c0000a -o ek.der && sudo tpm2_nvread 0x01c90100 -o iak.der && sudo tpm2_nvread 0x01c00100 -o root.der
  for f in ek iak root; do openssl x509 -inform der -in $f.der -out $f.pem; done
  openssl verify -CAfile root.pem ek.pem iak.pem
  openssl x509 -in root.pem -noout -ext subjectAltName'
```

The root's subject alternative name is the host notary's `did:key`. Compare it with the host:

```sh
curl -s http://127.0.0.1:8066/v1/system_public_key | jq -r .did
```

Then fetch the guest notary's credential and verify it offline:

```sh
ssh -p 2222 ubuntu@127.0.0.1 'curl -s http://127.0.0.1:8066/v1/credential' > guest-identity.json
eqty-notary-verify guest-identity.json
```

`tpmAKCertificate` in the guest's `VCompTpmV1` holds the AK certificate issued by the IAK, the IAK
certificate and the root; `tpmEKCertificate` the EK certificate and the root. A verifier gets one
X.509 chain from the quoting AK to your host notary, plus the TPM's own statement, the IAK's
`TPM2_Certify`, that the AK and IAK share a TPM.

## 7. Sign from a container in the guest

Containers in the VM reach the guest notary at the well-known address. The EQTY SDK's
`simple.py` example from [eqtylab/container_example](https://github.com/eqtylab/container_example)
signs every statement through it:

```sh
ssh -p 2222 ubuntu@127.0.0.1 '
  git clone https://github.com/eqtylab/container_example && cd container_example/simple_py
  docker build -t simple-py . && docker run --rm -e ENDPOINT=http://100.100.100.200:8066 -v $PWD/out:/out simple-py'
```

The resulting manifest's statements are `registeredBy` the container's process key, whose
`VCompContainerV1` is registered by the guest notary, whose `VCompTpmV1` carries the chain to the
host. The chain in full: workload statements, process key, guest notary, AK, vTPM IAK, host notary.

## Day to day

| Task                       | Command                                                                           |
| -------------------------- | --------------------------------------------------------------------------------- |
| Start the vTPM before a boot | `eqty-notaryctl vtpm start guest1`                                              |
| Several VMs                | One vTPM per VM. All containers in one VM share its EK and IAK.                   |
| Remove it                  | `sudo eqty-notaryctl vtpm delete guest1`. Irreversible: the keys are destroyed.   |