dingelish / SEVAttestation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

SEVAttestation

This project contains all the tools and scripts required to perform SEV attestation and injection of a secret.

Dependencies

  1. QEMU version 6.1 https://www.qemu.org/download/#source (released on August 24, 2021) - None of the previous versions support attestation and secret injection capabilites

How to run

  1. Apply patches and build grub, then include this grub in the patched OVMF build.

  2. git clone git@github.com:khushboo-dfn/SEVAttestation.git

  3. cd SEVAttestation

  4. Prepare image

    • Get an Ubuntu server image
      wget https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img (Rename it to ubuntu-server.img)
    • Prepare iso
      • create a metadata file with the desired instance ID and hostname:
       $ cat > metadata.yaml <<EOF  
       instance-id: iid-local01  
       local-hostname: cloudimg  
       EOF
      
      • Next, create a user data file to provide the SSH key to the instance. The example below uses cloud-init’s cloud-config to pass this information to automatically add the key to the default user.
       $ cat > user-data.yaml <<EOF  
       #cloud-config  
       ssh_authorized_keys:  
          - ssh-rsa AAAAB3NzaC1yc2EAAAABIwJJJQEA3I7VUf3l5gSn5uavROsc5HRDpZ ...  
       EOF
      
  5. Launch a QEMU image using launch_qemu_image script
    ./launch_qemu_image.sh

  6. In another terminal, connect to the QEMU instance using QMP
    telnet 127.0.0.1 5550

  7. Run the following commands:
    { "execute": "qmp_capabilities" }
    {"return": {}}

    { "execute": "query-sev" }
    {"return": {"enabled": true, "api-minor": 22, "handle": 1, "state": "launch-secret", "api-major": 0, "build-id": 13, "policy": 1}}

    { "execute": "query-sev-launch-measure" }
    {"return": {"data": "7vHlsVKpvBaUHU5jzpNtfLMFAljbBnVrkqO51p3Ny3sZHribEtvolLvSRs0SqW8a"}}
    Record these results to pass to the script in next step.

  8. In a third terminal, prepare a secret using secret.py --passwd <Encryption key>.

  9. Run the script to verify attestation
    ./verify_attestation.sh -p secret_file_to_be_injected -m 7vHlsVKpvBaUHU5jzpNtfLMFAljbBnVrkqO51p3Ny3sZHribEtvolLvSRs0SqW8a
    This script assumes sev info parameters, location of qemu and OVMF.fd as default but they can be specified. Run ./verify_attestation.sh -h to find arguments.

  10. Inject secret via qmp
    { "execute": "sev-inject-launch-secret", "arguments": { "packet-header": "AAAAAI0M2R8bw40sg0Hu8PsGRf2LGHcBJcECXCFgkTgnHU4VCLMWx8tz8iAEuW4IKQl/BA==", "secret": "usNTvLEGVvtB2rMHCw=="}}
    {"return": {}}

  11. Continue to launch the guest VM
    { "execute": "cont"}

  12. Login with SSH
    ssh -o "StrictHostKeyChecking no" -p 2222 ubuntu@0.0.0.0

Supporting blogs/articles

  1. How to mount a cqow image: https://docs.j7k6.org/mount-qcow2-disk-image-linux/
  2. Confidential Computing with AMD SEV: https://blog.hansenpartnership.com/building-encrypted-images-for-confidential-computing/#easy-footnote-bottom-2-1196

About


Languages

Language:Shell 80.2%Language:Python 19.8%