Skip to content

feat(tee): AMD SEV-SNP supported VM image build scripts#388

Open
kariy wants to merge 33 commits intomainfrom
tee/reproducible-builds
Open

feat(tee): AMD SEV-SNP supported VM image build scripts#388
kariy wants to merge 33 commits intomainfrom
tee/reproducible-builds

Conversation

@kariy
Copy link
Member

@kariy kariy commented Dec 24, 2025

Related #378

Reproducibility

The scripts takes into account all variables that may affect the build process for each component of the VM image. A build-config file that pins the exact version (as well as the checksum) of each required dependencies.

The katana binary that is used in the VM image is a statically-linked version using the musl C standard library. We're not vendoring the cargo dependencies for now so there's a possibility that it may not be reproducible. Vendoring is important for hermetic builds and is considered the gold standard for reproducibility. So, we should tackle this in the future.

@kariy kariy changed the base branch from main to tarrencev/megathink December 24, 2025 09:16
@kariy kariy force-pushed the tee/reproducible-builds branch 2 times, most recently from 73bd52a to 96ab475 Compare January 1, 2026 16:27
Base automatically changed from tarrencev/megathink to main January 1, 2026 18:17
@kariy kariy force-pushed the tee/reproducible-builds branch from 96ab475 to 7f6d8e2 Compare January 1, 2026 18:30
kariy and others added 19 commits January 2, 2026 11:41
Enhancements to TEE VM image build scripts:

- Fix init script bugs that caused kernel panic
  - Mount /proc before reading /proc/cmdline
  - Fix dbg() function to work with set -eu
  - Add error handling to mknod commands

- Add network configuration to initrd
  - Include ip command in busybox symlinks
  - Configure eth0 with static IP (10.0.2.15) for QEMU user networking
  - Enable RPC access via QEMU port forwarding

- Enhance measurement calculation script
  - Support both UEFI and direct kernel boot modes
  - Automatic fallback when SNP_KERNEL_HASHES not supported
  - Generate JSON manifest with measurement metadata

- Add VM boot test script (test-vm-boot.sh)
  - Automated QEMU testing with timeout
  - Serial console monitoring for boot progress
  - Validates kernel boot, init, and Katana launch

Tested: VM boots successfully, Katana RPC responds to requests

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Integrate VM image building into the CI/CD pipeline:

- Add vm-image-build job after reproducible-build
  - Builds complete VM image using vm-image.Dockerfile
  - Extracts all components (disk, kernel, initrd, OVMF)
  - Calculates SEV-SNP measurement using sev-snp-measure
  - Generates structured manifest with all component hashes
  - Compresses disk image for distribution
  - Creates GitHub attestation for provenance

- Outputs:
  - Bootable VM disk image (compressed)
  - Expected SEV-SNP measurement for attestation
  - Component manifest with SHA hashes
  - Individual components (kernel, initrd, OVMF)

- Validates YAML syntax
- Tested with local measurement calculation

This enables automated, reproducible VM image builds
for AMD SEV-SNP TEE deployment.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Technical documentation for the TEE VM image build pipeline:

- Complete architecture overview
- Detailed explanation of all build stages
- Initrd structure and init script flow
- Reproducibility measures and guarantees
- CI/CD integration guide
- Local build instructions
- Testing procedures with QEMU
- Security considerations
- Troubleshooting guide
- Performance metrics

This provides developers and operators with complete
understanding of the VM image build process for
reproducible TEE deployments.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Security Fix: The previous disk-based boot only measured OVMF firmware,
leaving the kernel, initrd, and Katana binary unmeasured. This allowed
post-attestation binary replacement attacks.

Direct kernel boot solves this by having the hypervisor pass kernel,
initrd, and cmdline directly to the AMD secure processor for measurement
before boot, creating a complete chain of trust.

Changes:
- Remove disk image building from Dockerfile (stages 4-5)
- Export only kernel, initrd, OVMF from final stage
- Update CI workflow to build boot components instead of disk
- Create boot components archive instead of disk image
- Update manifest with direct kernel boot deployment info
- Comprehensive documentation updates explaining security model
- Add detailed troubleshooting for measurement tool limitations

Security guarantee: All components (OVMF + kernel + initrd with Katana
+ cmdline) are measured by SEV-SNP at launch when using direct kernel
boot on real hardware, preventing binary replacement attacks.

Note: The sev-snp-measure tool cannot pre-calculate measurements without
OVMF SNP_KERNEL_HASHES support, but real SEV-SNP hardware will perform
full measurement via hypervisor interface.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Enable full attestation testing on SEV-SNP hardware by adding tools
to verify the launch measurement matches the expected value.

New Tools:
- verify-attestation.sh: Calls tee_generateQuote RPC, extracts the
  launch measurement from the SEV-SNP attestation report (offset 0x90),
  and compares it with the expected measurement from the build

- E2E_TESTING.md: Comprehensive guide for running attestation tests
  on actual SEV-SNP hardware, including QEMU launch parameters,
  attestation report structure documentation, and troubleshooting

Test Flow:
1. Build boot components with reproducible build
2. Calculate expected measurement with sev-snp-measure
3. Launch VM with QEMU on SEV-SNP hardware (direct kernel boot)
4. Call tee_generateQuote to get attestation report
5. Extract measurement from report (AMD spec offset 0x90, 48 bytes)
6. Compare with expected measurement - must match exactly

Security Guarantee:
When measurements match, it cryptographically proves the running
Katana instance was launched with the exact boot components from
the reproducible build, preventing binary replacement attacks.

The attestation report is signed by the AMD secure processor and
includes both the launch measurement and blockchain state commitment
(Poseidon hash of state_root and block_hash).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Pin OVMF to commit fbe0805b2091393406952e84724188f8c1941837 from
AMD's OVMF fork (snp-latest branch) instead of using Ubuntu's
packaged OVMF which lacks SEV-SNP specific features.

Key changes:
- Add ovmf-builder stage to compile from source
- Pin to specific commit for reproducibility
- Patch grub.sh to remove unavailable modules (linuxefi, sevsecret)
- Include build-info.txt with commit hash for traceability

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
build-tee-components.sh runs both Dockerfiles in sequence:
1. reproducible.Dockerfile - builds katana binary
2. vm-image.Dockerfile - builds kernel, initrd, OVMF

This avoids duplicating build steps while keeping both
Dockerfiles independent and reusable.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Skip BaseTools tests in OVMF build (require 'python' symlink)
- Extract components from initrd-builder stage instead of scratch
- Use --target to build only needed stages

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Replace AmdSevX64.dsc with OvmfPkgX64.dsc to fix boot issues:
- AmdSevX64 has embedded GRUB that expects SEV secrets for disk decryption
- OvmfPkgX64 supports direct kernel boot via QemuKernelLoaderFsDxe
- Kernel, initrd, and cmdline are included in SNP launch measurement

Changes:
- Build OvmfPkgX64.dsc with SMM_REQUIRE=FALSE, TPM_ENABLE=FALSE
- Output ovmf_code.fd and ovmf_vars.fd for split pflash usage
- Remove GRUB-related build dependencies (grub-efi, mtools, etc.)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- build.sh: Auto-build musl katana binary if --katana not provided
- build.sh: Copy katana binary to output directory
- build-qemu.sh: New script to build QEMU 10.2.0 from source
- start-vm.sh: Simplified VM launcher without persistent storage
- start-vm.sh: Document launch measurement inputs for attestation
- README.md: Comprehensive documentation for all scripts

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add CLI tools for working with AMD SEV-SNP attestation:
- snp-digest: Calculate launch measurement digest
- snp-report: Decode attestation reports
- ovmf-metadata: Extract OVMF SEV metadata sections

Also update README with documentation for start-vm.sh and
measurement verification workflows.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@kariy kariy force-pushed the tee/reproducible-builds branch from 1d5dad5 to 652cf50 Compare January 28, 2026 07:10
kariy and others added 6 commits January 28, 2026 01:15
- Add tabled crate for pretty table output
- Display attestation report in organized tables
- Add --raw flag to preserve original verbose output
- Show TCB version, platform info, and CPUID details in separate sections

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Install missing dependencies automatically via apt-get or pacman
instead of just failing with an error message.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Pin OVMF commit (fbe0805b2091393406952e84724188f8c1941837) in build-config
- Add environment normalization (TZ, LANG, LC_ALL) to build scripts
- Require checksum verification for kernel, busybox, and modules packages
- Add OVMF commit verification after checkout
- Add --strict flag to build-musl.sh for vendored dependency enforcement
- Add vendored dependencies detection for offline builds
- Create verify-build.sh script to compare build artifacts
- Export OVMF_COMMIT from build.sh and add reproducibility warnings

Verified: two clean builds with same SOURCE_DATE_EPOCH produce
identical checksums for all artifacts (OVMF.fd, vmlinuz, initrd.img, katana).

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@kariy kariy marked this pull request as ready for review January 28, 2026 18:50
@kariy kariy changed the title feat(ci): add reproducible builds for TEE attestation feat(tee): AMD SEV-SNP supported VM image build scripts Jan 28, 2026
@kariy kariy force-pushed the tee/reproducible-builds branch from 3fbb335 to 5a0c6c7 Compare January 28, 2026 19:24
@codecov
Copy link

codecov bot commented Jan 28, 2026

Codecov Report

❌ Patch coverage is 0% with 275 lines in your changes missing coverage. Please review.
✅ Project coverage is 71.92%. Comparing base (9bde0ae) to head (7dbbc89).
⚠️ Report is 234 commits behind head on main.

Files with missing lines Patch % Lines
misc/AMDSEV/snp-tools/src/bin/snp-report.rs 0.00% 172 Missing ⚠️
misc/AMDSEV/snp-tools/src/bin/snp-digest.rs 0.00% 55 Missing ⚠️
misc/AMDSEV/snp-tools/src/bin/ovmf-metadata.rs 0.00% 48 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #388      +/-   ##
==========================================
- Coverage   73.32%   71.92%   -1.41%     
==========================================
  Files         209      256      +47     
  Lines       23132    30086    +6954     
==========================================
+ Hits        16961    21638    +4677     
- Misses       6171     8448    +2277     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant