-
Notifications
You must be signed in to change notification settings - Fork 1
feat(launcher): hardened reproducible TDX image build pipeline #75
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
Open
0xHansLee
wants to merge
3
commits into
feat/impl-tdx-backend
Choose a base branch
from
feat/launcher
base: feat/impl-tdx-backend
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| name: launcher reproducible build | ||
|
|
||
| # Reproducibility is a release gate, not a per-commit check: a full run | ||
| # builds the TD image twice (privileged mkosi in a pinned container) and | ||
| # asserts every artifact is byte-identical. That is minutes-long and | ||
| # Linux/Docker-only, so it runs only when a release is published. | ||
| # | ||
| # Precondition: at release cut, launcher/build/Dockerfile.builder must be | ||
| # pinned to a real Debian digest (Pinning protocol in launcher/build/README.md). | ||
| # build.sh refuses to run while the PLACEHOLDER digest is present, so an | ||
| # unpinned (non-reproducible) release fails this job by design — we do NOT | ||
| # set ALLOW_UNPINNED_BUILDER here. | ||
| on: | ||
| release: | ||
| types: [published] | ||
| workflow_dispatch: {} | ||
|
|
||
| jobs: | ||
| reproducible: | ||
| # ubuntu-latest can run privileged Docker; if the hosted runner cannot | ||
| # complete the mkosi image build, move this to a self-hosted Linux runner. | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Check out the repo | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Install Go | ||
| uses: actions/setup-go@v6 | ||
| with: | ||
|
0xHansLee marked this conversation as resolved.
0xHansLee marked this conversation as resolved.
|
||
| go-version: '1.24' | ||
|
|
||
| - name: Cache OpenSSL static build | ||
| id: cache-openssl | ||
| uses: actions/cache@v4 | ||
| with: | ||
| path: /usr/local/lib64 | ||
| key: openssl-3.0.13-static-${{ runner.os }} | ||
|
|
||
| - name: Install build dependencies | ||
| run: | | ||
| sudo apt-get update | ||
| sudo apt-get install -y build-essential cmake libssl-dev | ||
|
|
||
| - name: Build static OpenSSL (if not cached) | ||
| if: steps.cache-openssl.outputs.cache-hit != 'true' | ||
| run: | | ||
| cd /tmp | ||
| wget -q https://www.openssl.org/source/openssl-3.0.13.tar.gz | ||
| tar xzf openssl-3.0.13.tar.gz | ||
| cd openssl-3.0.13 | ||
| ./config --prefix=/usr/local --openssldir=/usr/local/openssl no-shared | ||
| make -j"$(nproc)" | ||
| sudo make install_sw | ||
|
|
||
| - name: Verify reproducible build (build twice, diff every artifact) | ||
| run: ./launcher/build/verify-reproducible.sh | ||
|
|
||
| # The custom TDX kernel must be reproducible AND keyless (CONFIG_MODULE_SIG=n), | ||
| # so anyone can rebuild it byte-identically with no private signing key and | ||
| # independently rederive platform_commitment. Heavy (~full kernel build) — same | ||
| # release gate; move to a self-hosted runner if the hosted one is too slow. | ||
| kernel: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Check out the repo | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: Install kernel build dependencies | ||
| run: | | ||
| sudo apt-get update | ||
| sudo apt-get install -y build-essential bc bison flex libelf-dev \ | ||
| libssl-dev dpkg-dev xz-utils kmod cpio | ||
|
|
||
| - name: Build kernel twice (keyless assertion + byte-identical determinism) | ||
| run: | | ||
| set -e | ||
| KERNEL_WORKDIR=/tmp/kbuild-a ./launcher/kernel/build-kernel.sh /tmp/kernel-a.deb | ||
| KERNEL_WORKDIR=/tmp/kbuild-b ./launcher/kernel/build-kernel.sh /tmp/kernel-b.deb | ||
| a=$(sha256sum /tmp/kernel-a.deb | awk '{print $1}') | ||
| b=$(sha256sum /tmp/kernel-b.deb | awk '{print $1}') | ||
| echo "build A: $a"; echo "build B: $b" | ||
| [ "$a" = "$b" ] || { echo "kernel build is NOT reproducible ($a != $b)"; exit 1; } | ||
| echo "kernel is reproducible + keyless (MODULE_SIG=n asserted in build-kernel.sh)" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| # story-kernel-launcher | ||
|
|
||
| Reproducible, hardened Trust Domain (TD) image build pipeline and runtime | ||
| environment for story-kernel validators. Everything required to deliver, | ||
| verify, and operate a production-grade TDX node lives under this directory. | ||
|
|
||
| ## What it provides | ||
|
|
||
| - **Reproducible image build** via `mkosi` — same source produces a | ||
| byte-identical rootfs (and deterministic `code_commitment`) across | ||
| machines and time | ||
| - **Keyless reproducible kernel** — the custom TDX kernel is built with | ||
| `CONFIG_MODULE_SIG=n` (`kernel/`), so anyone can rebuild it byte-identically | ||
| with **no private signing key** and independently verify `platform_commitment` | ||
| - **Boot-bound sealing** — key shares are sealed on the GCP confidential-VM | ||
| vTPM (`/dev/tpmrm0`) under `PolicyPCR(PCR 7, 11, 12)`, tying them to the exact | ||
| Secure-Boot policy, dm-verity rootfs, and story-kernel ELF; they unseal only in | ||
| that measured boot (see `docs/operator-guide.md` → Measured-boot chain and sealing) | ||
| - **`dm-verity` rootfs** — block-level integrity for the booted image; | ||
| any tampering after boot crashes the kernel | ||
| - **OS hardening** — no SSH, root locked, all getty masked, ptrace | ||
| disabled, `/dev/mem` unavailable, no shell after handoff | ||
| - **RTMR3 self-extend** — story-kernel binary identity is baked into | ||
| the TDX attestation chain before any DKG work begins | ||
| - **External config injection** — the light-client config (which chain to | ||
| follow) is fetched at boot from cloud instance metadata into tmpfs, not | ||
| baked into the rootfs, so `code_commitment`/`platform_commitment` stay | ||
| stable across chains and resets (see `docs/operator-guide.md` → Node config) | ||
| - **Platform & code commitment extraction tooling** — operators and | ||
| auditors derive both on-chain governance values from a real quote | ||
| (`attestation/verify-platform.sh`, `attestation/verify-rtmr3.sh`) | ||
|
|
||
| ## Threat model | ||
|
|
||
| The launcher defends threats (A) host memory read, (B) root-in-TD code | ||
| tampering, (B') validator share extraction, (C) fork-chain light-client | ||
| spoofing, and (D) Sybil committee joins. The full matrix — one row per | ||
| threat, one column per component — is in | ||
| [`docs/threat-model.md`](docs/threat-model.md). | ||
|
|
||
| This launcher is **not** a confidentiality replacement. The cryptographic | ||
| protocol (DKG + threshold decryption) provides confidentiality. The | ||
| launcher exists so the protocol's assumptions about validator code | ||
| integrity actually hold in deployed environments. | ||
|
|
||
| ## Layout | ||
|
|
||
| | Subdirectory | Purpose | | ||
| |---|---| | ||
| | `kernel/` | Keyless reproducible custom TDX kernel: pinned `.config` + `build-kernel.sh` | | ||
| | `mkosi/` | Reproducible image build configuration | | ||
| | `initrd/` | Custom initrd: early-load modules + dm-verity rootfs setup | | ||
| | `boot/` | Boot artifacts: kernel cmdline, dm-verity setup | | ||
| | `attestation/` | RTMR3 self-extend flow at boot | | ||
| | `hardening/` | OS hardening policies (sysctl, modprobe blacklist) | | ||
| | `build/` | Reproducible build pipeline (containerized) | | ||
| | `docs/` | Operator + auditor + threat-model documentation | | ||
|
|
||
| ## Related code outside launcher/ | ||
|
|
||
| - `enclave/tdx/` — TDX backend Go code (attestation, sealing client) | ||
| - `enclave/tdx/README.md` — TDX backend overview | ||
|
|
||
| ## Building | ||
|
|
||
| ```sh | ||
| # Build the reproducible TD image (containerized, deterministic) | ||
| ./build/build.sh | ||
|
|
||
| # Verify a rebuild is byte-identical to a published reference | ||
| ./build/verify-reproducible.sh | ||
| ``` | ||
|
|
||
| After a TD boots the image, extract the on-chain governance values from a | ||
| fresh quote with `attestation/verify-platform.sh` (platform_commitment) and | ||
| `attestation/verify-rtmr3.sh` (code_commitment). End-to-end deploy steps — | ||
| download, verify, launch, register, upgrade, halt-recovery — are in | ||
| [`docs/operator-guide.md`](docs/operator-guide.md). | ||
|
|
||
| ## Why this is its own component | ||
|
|
||
| story-kernel is the Go binary that performs DKG work. The launcher is the | ||
| *substrate* around it — image, boot, attestation, sealing, hardening — that | ||
| makes the binary's security guarantees real. Keeping them in the same repo | ||
| but in distinct trees lets the binary and its substrate be versioned and | ||
| audited together while staying organizationally separate. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| # attestation/ | ||
|
|
||
| RTMR3 self-extend flow. Before story-kernel runs any DKG work, RTMR3 | ||
| is extended with the SHA-384 of its ELF, binding its identity to the | ||
| TDX attestation chain. | ||
|
|
||
| ## Status | ||
|
|
||
| Implemented. The boot-time extender lives in | ||
| `../mkosi/mkosi.skeleton/usr/local/lib/story-kernel/extend-rtmr3.sh` | ||
| and is driven by `story-kernel-rtmr3-extend.service`. This directory | ||
| holds the *verification* tooling. | ||
|
|
||
| ## Commitments | ||
|
|
||
| The boot chain (firmware, bootloader, kernel, cmdline) extends | ||
| RTMR0..RTMR2, which form the **platform_commitment**: | ||
|
|
||
| ``` | ||
| platform_commitment = keccak256(MRTD || RTMR0 || RTMR1 || RTMR2) | ||
| ``` | ||
|
|
||
| RTMR3 is extended once at startup with the kernel ELF SHA-384, giving the | ||
| **code_commitment**: | ||
|
|
||
| ``` | ||
| code_commitment = keccak256(RTMR3) | ||
| ``` | ||
|
|
||
| This lets governance approve a platform (firmware vintage, boot chain) | ||
| independently from a specific story-kernel binary. | ||
|
|
||
| ## Contents | ||
|
|
||
| This directory holds the operator/auditor **verification** tooling. The | ||
| boot-time *extenders* run inside the image: `extend-rtmr3.sh` (RTMR3) and | ||
| `measure-binary.sh` (PCR 12) are copied verbatim into the rootfs from | ||
| `mkosi.skeleton/`. The `measure-binary.sh` here is a standalone reference | ||
| that the `test/` harness exercises. | ||
|
|
||
| | File | Purpose | | ||
| |---|---| | ||
| | `verify-rtmr3.sh` | Post-boot check: extracts RTMR3 from a fresh quote → `code_commitment = keccak256(RTMR3)` | | ||
| | `verify-platform.sh` | Extracts MRTD/RTMR0..2 → `platform_commitment = keccak256(MRTD‖RTMR0‖RTMR1‖RTMR2)` | | ||
| | `verify-pcr12.sh` | Asserts vTPM PCR 12 == `SHA-256(0x00*32 ‖ SHA-256(ELF))` — the sealing bind | | ||
| | `measure-binary.sh` | PCR 12 extend helper (reference copy; the in-image one runs at boot) | | ||
| | `test/` | Docker harness: runs measure-binary.sh + verify-pcr12.sh against swtpm, asserts tamper detection | | ||
| | `README.md` | This file | | ||
|
|
||
| ## Reference | ||
|
|
||
| `contracts/src/protocol/TDXValidationHook.sol` consumes both | ||
| commitments via the `approvedPlatform[platform_commitment]` and | ||
| `approvedBinary[code_commitment]` mappings. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.