Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

e2e-docs: Update docs with upstream changes #23

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c14a040
Update Readme.md
mkulke Mar 10, 2023
2cd16a8
github: Add rust workflow
jepio Mar 14, 2023
22cefc0
github: Install libtss2-dev before building
jepio Mar 14, 2023
6bd3a3e
Add retrieval of akpub from vTPM
mkulke Mar 14, 2023
95cc7c2
vtpm-snp-report: Add definitions for HCL structures
jepio Mar 13, 2023
823a1da
vtpm-snp-report: Add ReportData types
jepio Mar 13, 2023
fe14a13
vtpm-snp-report: Add methods to verify report_data and extract AK pub…
jepio Mar 13, 2023
e4bd6b9
vtpm-snp-report: Replace ::from_slice() with TryFrom trait
jepio Mar 14, 2023
028c447
Add quote retrieval/validation code
mkulke Mar 16, 2023
7060e83
Housekeeping
mkulke Mar 15, 2023
ab31c38
Export HCL report as library
mkulke Mar 15, 2023
7203e90
Merge pull request #1 from kinvolk/mkulke/expose-hcl-as-lib
mkulke Mar 23, 2023
49adbd5
Polish az-snp-vtpm package (#3)
mkulke Mar 28, 2023
cfdb809
Rename readme; libs should not have a lock file (#5)
mkulke Mar 29, 2023
6329c65
docs: Add instructions to run e2e tests
surajssd Apr 12, 2023
c49707d
Merge pull request #7 from surajssd/surajssd/update-documentation
surajssd Apr 17, 2023
6e1cfc7
Add feature flags for attester/verifier code (#10)
mkulke Apr 19, 2023
0a9b1d6
Expose HCL Data Struct (#12)
mkulke Apr 20, 2023
6071a32
Add example code (#14)
mkulke Apr 25, 2023
ffd743d
Remove platform detection heuristic (#18)
mkulke Apr 26, 2023
247a572
Fix feature compilation (#21)
mkulke Apr 28, 2023
f0a6d7b
Add e2e test workflow (#19)
mkulke May 4, 2023
65ad4a2
az-snp-vtpm: Fix Makefile to use predictable DNS name
surajssd May 22, 2023
d0490da
e2e-docs: Update docs with upstream changes
surajssd May 22, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: e2e

on:
pull_request:
branches: [ "main" ]

permissions:
id-token: write
contents: read

jobs:
build-and-run-example:
runs-on: ubuntu-latest
environment: restricted
steps:
- name: Create resource suffix
run: >
echo "SUFFIX=${{ github.event.number }}-$(echo $RANDOM | md5sum | head -c6)"
>> "$GITHUB_ENV"

- uses: actions/checkout@v3

- name: Az CLI login
uses: azure/login@v1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}

- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable

- name: Build example project
working-directory: ./az-snp-vtpm
run: |
sudo apt-get update
sudo apt-get install -y libtss2-dev
cargo build --release -p example

- name: Create SSH key pair
run: ssh-keygen -t rsa -b 4096 -N "" -f ~/.ssh/id_rsa

- name: Create VM resources
working-directory: ./az-snp-vtpm
env:
LOCATION: eastus
ASSIGN_PUBLIC_IP: 'true'
CVM_RESOURCE_GROUP: ${{ vars.RESOURCE_GROUP }}
run: |
make deploy
public_ip=$(az network public-ip show \
-g "$CVM_RESOURCE_GROUP" \
-n "cvm-${SUFFIX}-ip" \
--query ipAddress \
-o tsv)
echo "PUBLIC_IP=$public_ip" >> "$GITHUB_ENV"

- name: Copy bin to cvm
working-directory: ./az-snp-vtpm
run: >
scp
-o StrictHostKeyChecking=no
target/release/example
"azureuser@${PUBLIC_IP}:"

- name: Install dependency on CVM
run: >
ssh
-o StrictHostKeyChecking=no
"azureuser@${PUBLIC_IP}"
-C "sudo apt-get update && sudo apt-get install -y libtss2-tctildr0"

- name: Execute example on CVM
run: >
ssh
-o StrictHostKeyChecking=no
"azureuser@${PUBLIC_IP}"
-C "sudo ./example"

- name: Delete VM resources
if: always()
working-directory: ./az-snp-vtpm
env:
CVM_RESOURCE_GROUP: ${{ vars.RESOURCE_GROUP }}
run: make delete
57 changes: 57 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Rust

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

env:
CARGO_TERM_COLOR: always

jobs:
build:

runs-on: ubuntu-latest

steps:
- name: Install deps
run: sudo apt-get update && sudo apt-get install -y libtss2-dev

- uses: actions/checkout@v3

- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true

- name: Install additional components
shell: bash
run: |
rustup component add rustfmt
rustup component add clippy

- name: Build
run: cargo build --verbose --all
working-directory: az-snp-vtpm

- name: Check verifier-only
run: cargo check --verbose --no-default-features --features=verifier
working-directory: az-snp-vtpm

- name: Check attester-only
run: cargo check --verbose --no-default-features --features=attester
working-directory: az-snp-vtpm

- name: Run tests
run: cargo test --verbose --all
working-directory: az-snp-vtpm

- name: Format
run: cargo fmt --all -- --check
working-directory: az-snp-vtpm

- name: Lint
run: cargo clippy --all-targets --all-features --all -- -D warnings
working-directory: az-snp-vtpm
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright © 2022 Microsoft Corporation

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the “Software”), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
8 changes: 6 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# CAA CVMs with RHEL on Azure
# Azure CVM Tooling

Collaborative Playground
Assorted tools and libraries to use with [Azure CVMs](https://azure.microsoft.com/en-us/solutions/confidential-compute/).

# vTPM-SNP

Library and CLI to integrate with vTPM on SEV-SNP enabled machines.
1 change: 1 addition & 0 deletions vtpm-snp-report/.gitignore → az-snp-vtpm/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
target
arm/*.json
Cargo.lock
41 changes: 41 additions & 0 deletions az-snp-vtpm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[package]
name = "az-snp-vtpm"
version = "0.2.1"
edition = "2021"
repository = "https://github.com/kinvolk/azure-cvm-tooling/"
license = "MIT"
keywords = ["azure", "tpm", "sev-snp"]
categories = ["cryptography", "virtualization"]
description = "vTPM based SEV-SNP attestation for Azure Confidential VMs"

[lib]
path = "src/lib.rs"

[[bin]]
name = "snp-vtpm"
path = "src/main.rs"
required-features = ["attester", "verifier"]

[dependencies]
bincode = "1"
clap = { version = "4", features = ["derive"] }
jsonwebkey = { version = "0.3.5", features = ["pkcs-convert"] }
memoffset = "0.8.0"
openssl = { version = "0.10.45", features = ["vendored"], optional = true }
rsa = { version = "0.8.2", features = ["pkcs5", "sha2"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
sev = "1"
sha2 = "0.10.6"
static_assertions = "^1.1.0"
thiserror = "1.0.38"
tss-esapi = "7.2"
ureq = { version = "2.6.2", default-features = false, features = ["json"] }

[features]
default = ["attester", "verifier"]
attester = []
verifier = ["openssl", "sev/openssl", "ureq/tls"]

[workspace]
members = ["example"]
47 changes: 47 additions & 0 deletions az-snp-vtpm/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
CVM_RESOURCE_GROUP ?= azure-cvm-tooling-ci
LOCATION ?= eastus
IMAGE_ID ?= -
SSH_PUB_KEY_PATH ?= ~/.ssh/id_rsa.pub
SSH_PRIV_KEY ?= $(basename $(SSH_PUB_KEY_PATH) .pub)
ADMIN_PUBLIC_KEY = $(shell cat $(SSH_PUB_KEY_PATH))
VM_NAME ?= cvm
ASSIGN_PUBLIC_IP ?= false

.PHONY: deploy
deploy:
az deployment group create \
--template-file ./arm/cvm.bicep \
--resource-group=$(CVM_RESOURCE_GROUP) \
--name $(VM_NAME) \
--parameters virtualMachineName=$(VM_NAME) \
--parameters location=$(LOCATION) \
$(if $(IMAGE_ID:-=),--parameters imageId=$(IMAGE_ID)) \
--parameters adminPublicKey='$(ADMIN_PUBLIC_KEY)' \
--parameters assignPublicIP=$(ASSIGN_PUBLIC_IP)

.PHONY: ssh
ssh:
@echo "Run the following command to ssh into the VM:"
ifeq ($(ASSIGN_PUBLIC_IP),true)
@echo "ssh -i $(SSH_PRIV_KEY) azureuser@$(VM_NAME).$(LOCATION).cloudapp.azure.com"
else
@PRIV_IP_ADDRESS=$$(az network nic show \
--resource-group $(CVM_RESOURCE_GROUP) \
--name $(VM_NAME)-nic \
--query 'ipConfigurations[0].privateIPAddress' \
--output tsv) && \
echo "ssh -i $(SSH_PRIV_KEY) azureuser@$${PRIV_IP_ADDRESS}"
endif

.PHONY: delete
delete:
az vm delete \
--resource-group $(CVM_RESOURCE_GROUP) \
--name cvm-$(SUFFIX) \
--yes && \
az network public-ip delete \
--resource-group $(CVM_RESOURCE_GROUP) \
--name $(VM_NAME)-ip && \
az network vnet delete \
--resource-group azure-cvm-tooling-ci \
--name $(VM_NAME)-vnet
69 changes: 69 additions & 0 deletions az-snp-vtpm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# vTPM based SEV-SNP attestation for Azure Confidential VMs

This library enables guest attestation flows for [SEV-SNP CVMs on Azure](https://learn.microsoft.com/en-us/azure/confidential-computing/confidential-vm-overview). Please refer to the documentation in [this repository](https://github.com/Azure/confidential-computing-cvm-guest-attestation) for details on the attestation procedure.

## Create a CVM

Default image is Ubuntu 22.04 cvm

```bash
export IMAGE_ID=/subscriptions/.../resourceGroups/.../providers/Microsoft.Compute/galleries/.../images/.../versions/1.0.0
make deploy
```

## Build & Install

```bash
cargo b --release
scp target/release/snp-vtpm azureuser@$CONFIDENTIAL_VM:
```

## Run Binary

Retrieve SEV-SNP report, validate and print it:

```bash
sudo ./snp-vtpm -p
```

## Example Project

There is a project in the `./example` folder depicting how the crate can be leveraged in a Remote Attestation flow. **Note:** the code is merely illustrative and doesn't feature exhaustive validation, which would be required in a production scenario.

```bash
cargo b -p example
```

## SEV-SNP Report & vTPM

The vTPM is linked to the SEV-SNP report via the vTPM Attestation Key (AK). The public AK is part of a Runtime Data struct, which is hashed and submitted as Report Data when generating the SNP report. To provide freshness guarantees in an attestation exchange we can request a vTPM quote with a nonce. The resulting message is signed by the AK.

```
┌────────────────────────┐
│ HCL Data │
│ │
│ ┌──────────────────────┴─┐ ─┐
│ │ Runtime Data │ │
│ │ │ │
┌──────────────────────┐ │ │ ┌────────────────────┐ │ ├─┐
┌─┤ vTPM AK ├──┼─┼─┤ vTPM Public AK │ │ │ │
│ └──────────────────────┘ │ │ └────────────────────┘ │ │ │
│ ┌──────────────┐ │ └──────────────────────┬─┘ ─┘ │
│ │ vTPM Quote │ │ ┌────────────────────┐ │ │
│ │ │ │ │ HCL Report │ │ │
signs ┌─ ┌─┴────────────┐ │ │ │ │ │ sha256
│ │ │ Message │ │ │ │ ┌────────────────┐ │ │ │
│ │ │ │ │ │ │ │ SEV-SNP Report │ │ │ │
│ │ │ ┌──────────┐ │ │ │ │ │ │ │ │ │
│ │ │ │ PCR0 │ │ │ │ │ │ ┌──────────────┴─┴─┴─┐ │
│ │ │ └──────────┘ │ │ │ │ │ │ Report Data │ ◄───┘
│ │ │ ... │ │ │ │ │ └──────────────┬─┬─┬─┘
│ │ │ ┌──────────┐ │ │ │ │ └────────────────┘ │ │
└─► │ │ │ PCRn │ │ │ │ └────────────────────┘ │
│ │ └──────────┘ │ │ └────────────────────────┘
│ │ ┌──────────┐ │ │
│ │ │ Nonce │ │ │
│ │ └──────────┘ │ │
└─ └─┬────────────┘ │
└──────────────┘
```
Loading