Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 7 additions & 2 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
# toolchain has not), rustc emits std panic-location paths from the sysroot instead of the baked
# /rustc/<hash>, so we remap the sysroot rust-src path to that same /rustc/<hash>. UPDATE THE HASH
# when bumping the toolchain (rustc -Vv commit-hash); a stale value silently no-ops (CI==local catches it).
#
# /DEBUG:NONE (UEFI targets): rustc links these with /DEBUG, which puts a debug record in the image
# whose GUID is a hash of the .pdb, and the .pdb records where the toolchain is installed (the rustc
# path, the sysroot's rlib paths: /tmp/.rustup in CI, /src/.rustup locally). The linker writes those,
# so --remap-path-prefix does not reach them. With no .pdb the image carries no debug record.

[target.x86_64-unknown-linux-musl]
# Fully static musl for the host-side signer (stage0-sign); rust-lld, no system cc.
Expand All @@ -24,10 +29,10 @@ rustflags = ["-C", "linker=rust-lld", "-C", "target-feature=+crt-static", "-C",

[target.x86_64-unknown-uefi]
# The measured bootloader + payloads. Static, rust-lld.
rustflags = ["-C", "linker=rust-lld", "-C", "target-feature=+crt-static", "-C", "link-arg=-static", "--remap-path-prefix=/src/.cargo=/cargo", "--remap-path-prefix=/tmp/.cargo=/cargo", "--remap-path-prefix=/src/.rustup/toolchains/1.91.1-x86_64-unknown-linux-gnu/lib/rustlib/src/rust=/rustc/ed61e7d7e242494fb7057f2657300d9e77bb4fcb"]
rustflags = ["-C", "linker=rust-lld", "-C", "target-feature=+crt-static", "-C", "link-arg=-static", "-C", "link-arg=/DEBUG:NONE", "--remap-path-prefix=/src/.cargo=/cargo", "--remap-path-prefix=/tmp/.cargo=/cargo", "--remap-path-prefix=/src/.rustup/toolchains/1.91.1-x86_64-unknown-linux-gnu/lib/rustlib/src/rust=/rustc/ed61e7d7e242494fb7057f2657300d9e77bb4fcb"]

[target.aarch64-unknown-uefi]
rustflags = ["-C", "linker=rust-lld", "-C", "target-feature=+crt-static", "-C", "link-arg=-static", "--remap-path-prefix=/src/.cargo=/cargo", "--remap-path-prefix=/tmp/.cargo=/cargo", "--remap-path-prefix=/src/.rustup/toolchains/1.91.1-x86_64-unknown-linux-gnu/lib/rustlib/src/rust=/rustc/ed61e7d7e242494fb7057f2657300d9e77bb4fcb"]
rustflags = ["-C", "linker=rust-lld", "-C", "target-feature=+crt-static", "-C", "link-arg=-static", "-C", "link-arg=/DEBUG:NONE", "--remap-path-prefix=/src/.cargo=/cargo", "--remap-path-prefix=/tmp/.cargo=/cargo", "--remap-path-prefix=/src/.rustup/toolchains/1.91.1-x86_64-unknown-linux-gnu/lib/rustlib/src/rust=/rustc/ed61e7d7e242494fb7057f2657300d9e77bb4fcb"]

# Host target for proc-macros and build scripts: rust-lld only (no crt-static), so they link with no
# system cc. Kept out of the shared workspace config because the gnu-host repos link C and need cc.
Expand Down
12 changes: 10 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ jobs:
with:
subject-checksums: subjects.sha256

- name: Create stage0 release
# Created as a draft with its assets, then published: a release is immutable from the
# moment it is published (repo setting, workspace tools/rulesets.sh) and then accepts no
# uploads, so publishing first leaves it empty (as vaportpm v0.4.0 was).
- name: Create draft stage0 release
uses: softprops/action-gh-release@718ea10b132b3b2eba29c1007bb80653f286566b # v3.0.1
with:
tag_name: ${{ github.ref_name }}
Expand All @@ -109,11 +112,16 @@ jobs:
stage0-x86_64.zip
stage0-aarch64.zip
tools/qemu-test.sh
draft: false
draft: true
prerelease: true
generate_release_notes: true
make_latest: true

- name: Publish stage0 release
env:
GH_TOKEN: ${{ github.token }}
run: gh release edit "${{ github.ref_name }}" -R "${{ github.repository }}" --draft=false

# ---- QEMU test-harness image (tag: v*) -----------------------------
# End-user harness: qemu + swtpm + OVMF/AAVMF + the EC2 metadata mock, qemu-test.sh as entrypoint.
# Published with the stage0 release it ships beside: its firmware boots that release's efi-vars.
Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,11 @@ build/%/stage0.efi: build/%/ena.efi build/%/gvnic.efi docker-build-base
bash -c "mkdir -p build/$* && rustup target add $*-unknown-uefi && cargo build --release --manifest-path $(STAGE0_DIR)/Cargo.toml --target $*-unknown-uefi $(if $(STAGE0_FEATURES),--features $(STAGE0_FEATURES)) && cp -v $(STAGE0_DIR)/target/$*-unknown-uefi/release/stage0.efi $@"

# ---- Assemble + db-sign the boot disk (privileged: losetup/mount) ----
# os-release carries a yy.mm version: the committer date (UTC) of the commit being built, not the
# build date. Read here because the build image has no git.
COMMIT_YEAR_MONTH := $(shell TZ=UTC git log -1 --format=%cd --date=format-local:%y.%m)
build/%/boot.disk: build/%/stage0.efi build/keys/db.crt
$(DOCKER_RUN) -e ARCH=$* $(BUILD_IMAGE) ./tools/build.sh
$(DOCKER_RUN) -e ARCH=$* -e COMMIT_YEAR_MONTH=$(COMMIT_YEAR_MONTH) $(BUILD_IMAGE) ./tools/build.sh

build-amd64 build-x86_64: build/x86_64/boot.disk
build-arm64 build-aarch64: build/aarch64/boot.disk
Expand Down
3 changes: 2 additions & 1 deletion tools/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ echo "EFI vars written: ${EFI_VARS_OVMF}"
# Emit os-release so the cloud publishers can name/tag the image. BUILD_ID is
# derived from the signed stage0 hash so each build is traceable.
OSREL_PATH="${OUTPUT_DIR}/os-release"
YEAR_MONTH=$(date +%y.%m)
# yy.mm of the commit being built (from the Makefile), never the build date.
YEAR_MONTH="${COMMIT_YEAR_MONTH:?set COMMIT_YEAR_MONTH (yy.mm of the commit being built; the Makefile does)}"
{
echo "ID=lockboot"
echo "VERSION_ID=${YEAR_MONTH}"
Expand Down
8 changes: 6 additions & 2 deletions tools/predict-pcrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
# (The embedded NIC drivers and the payload are loaded through stage0's own
# Security2 override, which bypasses the firmware's image measurement: the
# drivers are covered by stage0's own hash, the payload by PCR14.)
# PCR5 EV_SEPARATOR, EV_EFI_GPT_EVENT = UEFI_GPT_DATA of boot.disk.
# PCR5 EV_SEPARATOR, EV_EFI_GPT_EVENT = UEFI_GPT_DATA of boot.disk. That is the GPT a
# first boot measures; stage2 rewrites it, so the event is marked
# "from_attestation": "gpt" and a replay takes the attestation's GPT digests.
# PCR7 SecureBoot, PK, KEK, db, dbx (EV_EFI_VARIABLE_DRIVER_CONFIG, the enrolled ESLs),
# EV_SEPARATOR, EV_EFI_VARIABLE_AUTHORITY = the db entry that verified stage0.
# The ESLs are rebuilt with mkvarstore.py's own code; on GCP they are
Expand All @@ -30,7 +32,7 @@
# updates: a per-platform replay file (golden readings) supplies them.
#
# Also writes pcrs.json (vaportpm layout): replaying this file alone, i.e. every PCR it models
# except the payload-dependent PCR14 -- the reference a verifier compares a quote against.
# except the payload-dependent PCR14, with boot.disk's GPT (a first boot's PCR5).
#
# usage: predict-pcrs.py <build-dir> [--banks sha256,sha384] --replay F [--out pcrs.json]
from __future__ import annotations
Expand Down Expand Up @@ -179,6 +181,8 @@ def esl(role: str) -> dict[str, Any]:
e["digest"] = mode
e["digests"] = {b: (authenticode(data, getattr(hashlib, b)) if mode == "authenticode"
else getattr(hashlib, b)(data).digest()).hex() for b in banks}
if typ == "EV_EFI_GPT_EVENT":
e["from_attestation"] = "gpt"
events.append(e)
events.append({"pcr": 14, "type": "unlogged", "by": "stage0",
"about": "the payload stage0 verified and runs: H_bank(sha256(payload))",
Expand Down
23 changes: 18 additions & 5 deletions tools/publish/ec2/create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,12 @@ if [ "${VERSION}" != "local" ]; then
echo "Repository: ${GH_REPO}; fetching stage0-${ARCH}.zip @ ${VERSION}"
gh release download "${VERSION}" --repo "${GH_REPO}" --pattern "stage0-${ARCH}.zip" --dir "${TEMP_DIR}" \
|| die "failed to download stage0-${ARCH}.zip from release ${VERSION}"
gh attestation verify "${ZIP}" --repo "${GH_REPO}" \
|| die "attestation verification failed for stage0-${ARCH}.zip"
# The provenance must come from a build of this release's tag (only admins create v*
# tags, and none can be moved), and the zip must be the asset of the immutable release.
gh attestation verify "${ZIP}" --repo "${GH_REPO}" --source-ref "refs/tags/${VERSION}" \
|| die "attestation verification failed for stage0-${ARCH}.zip (built from refs/tags/${VERSION}?)"
gh release verify-asset "${VERSION}" "${ZIP}" --repo "${GH_REPO}" \
|| die "stage0-${ARCH}.zip is not an asset of the immutable release ${VERSION}"
fi
unzip -q "${ZIP}" -d "${TEMP_DIR}"
WORK_DIR="${TEMP_DIR}"
Expand All @@ -146,9 +150,18 @@ for f in "${OS_RELEASE_FILE}" "${IMAGE_FILE}" "${UEFI_DATA_FILE}"; do
[ -f "$f" ] || die "required file not found: $f (build it first: make build-${ARCH})"
done

# os-release provides ID, VERSION_ID, BUILD_ID, NAME, PRETTY_NAME (our own artifact).
# shellcheck disable=SC1090
source "${OS_RELEASE_FILE}"
# os-release provides ID, VERSION_ID, BUILD_ID, PRETTY_NAME. Read as data, never sourced:
# under --no-verify it is unverified downloaded content.
os_release() { # KEY -> its value, surrounding double quotes removed
local v
v=$(grep -m1 "^$1=" "${OS_RELEASE_FILE}") || die "os-release: no $1 in ${OS_RELEASE_FILE}"
v="${v#*=}"; v="${v%\"}"; v="${v#\"}"
printf '%s' "$v"
}
ID=$(os_release ID)
VERSION_ID=$(os_release VERSION_ID)
BUILD_ID=$(os_release BUILD_ID)
PRETTY_NAME=$(os_release PRETTY_NAME)

AMI_NAME="${ID}-${ARCH}-${VERSION_ID}-${BUILD_ID}"
# A no-Secure-Boot debug AMI is a distinct image (don't collide with the real one).
Expand Down
24 changes: 19 additions & 5 deletions tools/publish/gcp/create.sh
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,12 @@ if [ "${VERSION}" != "local" ]; then
echo "Repository: ${GH_REPO}; fetching stage0-${ARCH}.zip @ ${VERSION}"
gh release download "${VERSION}" --repo "${GH_REPO}" --pattern "stage0-${ARCH}.zip" --dir "${TEMP_DIR}" \
|| die "failed to download stage0-${ARCH}.zip from release ${VERSION}"
gh attestation verify "${ZIP}" --repo "${GH_REPO}" \
|| die "attestation verification failed for stage0-${ARCH}.zip"
# The provenance must come from a build of this release's tag (only admins create v*
# tags, and none can be moved), and the zip must be the asset of the immutable release.
gh attestation verify "${ZIP}" --repo "${GH_REPO}" --source-ref "refs/tags/${VERSION}" \
|| die "attestation verification failed for stage0-${ARCH}.zip (built from refs/tags/${VERSION}?)"
gh release verify-asset "${VERSION}" "${ZIP}" --repo "${GH_REPO}" \
|| die "stage0-${ARCH}.zip is not an asset of the immutable release ${VERSION}"
fi
unzip -q "${ZIP}" -d "${TEMP_DIR}"
WORK_DIR="${TEMP_DIR}"
Expand Down Expand Up @@ -160,9 +164,19 @@ if [ "${DEFAULT_DBX}" != "true" ]; then
[ -f "${DBX_FILE}" ] || die "dbx.auth.bin not found: ${DBX_FILE} (rebuild: make build-${ARCH})"
fi

# os-release provides ID, VERSION_ID, BUILD_ID, NAME, PRETTY_NAME (our own artifact).
# shellcheck disable=SC1090
source "${OS_RELEASE_FILE}"
# os-release provides ID, VERSION_ID, BUILD_ID, NAME, PRETTY_NAME. Read as data, never sourced:
# under --no-verify it is unverified downloaded content.
os_release() { # KEY -> its value, surrounding double quotes removed
local v
v=$(grep -m1 "^$1=" "${OS_RELEASE_FILE}") || die "os-release: no $1 in ${OS_RELEASE_FILE}"
v="${v#*=}"; v="${v%\"}"; v="${v#\"}"
printf '%s' "$v"
}
ID=$(os_release ID)
VERSION_ID=$(os_release VERSION_ID)
BUILD_ID=$(os_release BUILD_ID)
NAME=$(os_release NAME)
PRETTY_NAME=$(os_release PRETTY_NAME)

VERSION_DASH=$(echo "${VERSION_ID}" | tr '.' '-')
ARCH_DASH=$(echo "${ARCH}" | tr '_' '-')
Expand Down
Loading