Skip to content

Commit 6ab675b

Browse files
Add custom guest-components build support (#12)
* Add custom guest-components build support - Add gc_builder stage to Dockerfile.podvm_binaries.ubuntu that compiles attestation-agent and api-server-rest from a configurable guest-components Git repo/ref when AA_FEATURES or GUEST_COMPONENTS_REF are set. - Extend Makefile with AA_FEATURES, GUEST_COMPONENTS_REPO, and GUEST_COMPONENTS_REF variables to pass custom build parameters. - Add /run tmpfs mount (80% RAM) to fstab for container image layers. * Configure kata-agent to read policy from /run/peerpod/policy.rego Without an explicit policy_file, kata-agent falls back to /etc/kata-opa/default-policy.rego and ignores the initdata-provided policy written by process-user-data. The tmpfiles rule already seeds /run/peerpod/policy.rego with allow-all.rego at boot, and process-user-data overwrites it when cc_init_data is present. Made-with: Cursor * Revert "Configure kata-agent to read policy from /run/peerpod/policy.rego" This reverts commit 0a4d980. * Refine mkosi.postinst for systemd unit management - Corrected the quoting issue in rm commands for legacy mount units to ensure proper deletion. - Added symlinks to mask unwanted systemd units that could affect vTPM measurements, enhancing security and predictability during VM boot. This update improves the handling of systemd services related to PCR measurements and ensures a cleaner environment for the container runtime. * Refactor custom guest-components build to use CUSTOM_GC_BINARIES Replace hardcoded per-binary build logic with a generic build-guest-components.sh script driven by a comma-separated CUSTOM_GC_BINARIES variable. Adding new components (e.g. confidential-data-hub) now requires only a new case in the script, with no Dockerfile or Makefile changes. Made-with: Cursor * Fix quoting in mkosi.postinst for systemd unit removal Corrected the escaping of backslashes in rm commands for legacy mount units to ensure proper deletion. This change enhances the reliability of the post-installation script by preventing potential issues with file removal during VM setup. * Update Dockerfile.mkosi.ubuntu for Ubuntu 24.10 and adjust mkosi.postinst for TDX RTMR support - Changed base image to Ubuntu 24.10, which includes systemd 256 EFI stub with TDX RTMR support. - Updated apt sources to redirect to old-releases mirror due to the EOL status of Ubuntu 24.10. - Clarified comments in mkosi.postinst regarding TDX RTMR support for systemd unit management. * Enhance build scripts and Dockerfile for guest components - Updated build-guest-components.sh to include the --locked flag for cargo builds, ensuring consistent dependency resolution. - Added error handling in Dockerfile.podvm_binaries.ubuntu to require GUEST_COMPONENTS_REF when CUSTOM_GC_BINARIES is specified. - Clarified Makefile with comments indicating the necessity of GUEST_COMPONENTS_REF when using custom binaries. * Fix Dockerfile.podvm_binaries.ubuntu to ensure successful installation of binaries by appending 'true' to the loop command, preventing build failures due to non-zero exit codes from the install command.
1 parent 88ba523 commit 6ab675b

6 files changed

Lines changed: 133 additions & 4 deletions

File tree

src/cloud-api-adaptor/podvm-mkosi/Dockerfile.mkosi.ubuntu

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
# syntax=docker/dockerfile:1.5.0-labs
2-
# ubuntu:24.04
3-
FROM ubuntu@sha256:0d39fcc8335d6d74d5502f6df2d30119ff4790ebbb60b364818d5112d9e3e932 AS builder
2+
# ubuntu:24.10 (Oracular) — provides systemd 256 EFI stub with TDX RTMR support
3+
FROM ubuntu@sha256:cdf755952ed117f6126ff4e65810bf93767d4c38f5c7185b50ec1f1078b464cc AS builder
44

55
ARG MKOSI_VERSION="v22"
66
ARG PROFILE="debug"
77
ARG IMAGE_VERSION="0.0.0"
88

99
ARG DEBIAN_FRONTEND=noninteractive
1010

11+
# 24.10 is EOL; redirect apt to old-releases mirror
12+
RUN sed -i 's|archive.ubuntu.com|old-releases.ubuntu.com|g; s|security.ubuntu.com|old-releases.ubuntu.com|g' \
13+
/etc/apt/sources.list.d/ubuntu.sources
14+
1115
RUN apt-get update && \
1216
apt-get install -y \
1317
bubblewrap \

src/cloud-api-adaptor/podvm-mkosi/Makefile

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,23 @@ PODVM_CONTAINER_NAME ?= $(REGISTRY)/podvm-docker-image-$(DISTRO_ARCH)
1515
VERIFY_PROVENANCE ?= no
1616
MKOSI_VERSION ?= v22
1717

18+
# Comma-separated list of guest-components binaries to build from source
19+
# instead of using upstream pre-built OCI artifacts.
20+
# Recognized: attestation-agent, api-server-rest, confidential-data-hub
21+
# Example: CUSTOM_GC_BINARIES=attestation-agent,api-server-rest
22+
CUSTOM_GC_BINARIES ?=
23+
24+
# Cargo features for attestation-agent (required when attestation-agent is
25+
# listed in CUSTOM_GC_BINARIES).
26+
# Example: AA_FEATURES=bin,ttrpc,kbs,coco_as,rust-crypto,tdx-attester,nvidia-attester
27+
AA_FEATURES ?=
28+
29+
# Git repo + ref for guest-components source checkout.
30+
# GUEST_COMPONENTS_REF is required when CUSTOM_GC_BINARIES is set.
31+
# Defaults to the OCI reference from versions.yaml via Makefile.defaults.
32+
GUEST_COMPONENTS_REPO ?= https://github.com/confidential-containers/guest-components.git
33+
# GUEST_COMPONENTS_REF is inherited from Makefile.defaults (oci.guest-components.reference)
34+
1835
_SHA := $(shell git rev-parse --short HEAD)
1936
_SHA_DIRTY := $(shell [ -n "$$(git status --porcelain 2>/dev/null)" ] && printf -- '-dirty')
2037
IMAGE_VERSION ?= $(_SHA)$(_SHA_DIRTY)
@@ -78,6 +95,9 @@ endif
7895
--build-arg PAUSE_BIN=$(PAUSE_BIN) \
7996
--build-arg IMAGE_NAME=mkosi-podvm-binaries \
8097
--build-arg VERIFY_PROVENANCE=$(VERIFY_PROVENANCE) \
98+
$(if $(CUSTOM_GC_BINARIES),--build-arg CUSTOM_GC_BINARIES=$(CUSTOM_GC_BINARIES),) \
99+
$(if $(AA_FEATURES),--build-arg AA_FEATURES=$(AA_FEATURES),) \
100+
$(if $(GUEST_COMPONENTS_REF),--build-arg GUEST_COMPONENTS_REF=$(GUEST_COMPONENTS_REF) --build-arg GUEST_COMPONENTS_REPO=$(GUEST_COMPONENTS_REPO),) \
81101
$(if $(AUTHFILE),--build-arg AUTHFILE=$(AUTHFILE),) \
82102
$(if $(DEFAULT_AGENT_POLICY_FILE),--build-arg DEFAULT_AGENT_POLICY_FILE=$(DEFAULT_AGENT_POLICY_FILE),) \
83103
$(if $(filter $(PUSH),true),,-o type=local,dest="./resources/binaries-tree") \

src/cloud-api-adaptor/podvm-mkosi/mkosi.postinst

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@ mv "${BUILDROOT}/etc/issue.d" "${BUILDROOT}/usr/lib/issue.d" || true
1414
} >> "${BUILDROOT}/etc/os-release"
1515

1616
# remove unused units of legacy image
17-
rm -f "${BUILDROOT}"/etc/systemd/system/{run-image,run-kata\x2dcontainers}.mount
18-
rm -f "${BUILDROOT}"/etc/systemd/system/multi-user.target.wants/{run-image,run-kata\x2dcontainers}.mount
17+
# NB: the systemd-escaped filename contains a literal backslash (\x2d = '-').
18+
# Brace expansion is unquoted, so each alternative must double-escape the
19+
# backslash to survive bash quote removal.
20+
rm -f "${BUILDROOT}"/etc/systemd/system/{run-image,run-kata\\x2dcontainers}.mount
21+
rm -f "${BUILDROOT}"/etc/systemd/system/multi-user.target.wants/{run-image,run-kata\\x2dcontainers}.mount
22+
1923

2024
# mask unwanted sytemd units that measure a bunch of stuff into the vTPM
2125
ln -s /dev/null "${BUILDROOT}/etc/systemd/system/systemd-pcrmachine.service"
@@ -25,3 +29,11 @@ ln -s /dev/null "${BUILDROOT}/etc/systemd/system/systemd-pcrphase@.service"
2529
ln -s /dev/null "${BUILDROOT}/etc/systemd/system/systemd-pcrphase-initrd.service"
2630
ln -s /dev/null "${BUILDROOT}/etc/systemd/system/systemd-pcrphase-sysinit.service"
2731
ln -s /dev/null "${BUILDROOT}/etc/systemd/system/systemd-pcrphase.service"
32+
33+
# Override the target image's systemd-stub with the builder's v256 version.
34+
# mkosi may use the target's stub for UKI creation; ensure TDX RTMR support is present.
35+
if [ -f /usr/lib/systemd/boot/efi/linuxx64.efi.stub ]; then
36+
mkdir -p "${BUILDROOT}/usr/lib/systemd/boot/efi"
37+
cp /usr/lib/systemd/boot/efi/linuxx64.efi.stub \
38+
"${BUILDROOT}/usr/lib/systemd/boot/efi/linuxx64.efi.stub"
39+
fi
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tmpfs /run tmpfs rw,nosuid,nodev,size=80% 0 0

src/cloud-api-adaptor/podvm/Dockerfile.podvm_binaries.ubuntu

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,38 @@
55
#
66
# Build binaries for mkosi podvm image
77
#
8+
# Optional: build guest-components binaries from source.
9+
# Set CUSTOM_GC_BINARIES to a comma-separated list of components to compile
10+
# from the guest-components repo instead of using upstream pre-built artifacts.
11+
# Recognized: attestation-agent, api-server-rest, confidential-data-hub
12+
#
13+
# When attestation-agent is included, AA_FEATURES must also be set.
14+
# GUEST_COMPONENTS_REF controls which git ref to build from.
15+
FROM rust:1.90-bookworm AS gc_builder
16+
ARG CUSTOM_GC_BINARIES=""
17+
ARG AA_FEATURES=""
18+
ARG GUEST_COMPONENTS_REF=""
19+
ARG GUEST_COMPONENTS_REPO="https://github.com/confidential-containers/guest-components.git"
20+
ARG DEBIAN_FRONTEND=noninteractive
21+
RUN set -e; \
22+
if [ -n "${CUSTOM_GC_BINARIES}" ] && [ -z "${GUEST_COMPONENTS_REF}" ]; then \
23+
echo "ERROR: GUEST_COMPONENTS_REF must be set when CUSTOM_GC_BINARIES is specified" >&2; \
24+
exit 1; \
25+
fi; \
26+
if [ -n "${CUSTOM_GC_BINARIES}" ] && [ -n "${GUEST_COMPONENTS_REF}" ]; then \
27+
apt-get update && \
28+
apt-get install -y --no-install-recommends \
29+
protobuf-compiler pkg-config clang libssl-dev libtss2-dev && \
30+
apt-get clean && rm -rf /var/lib/apt/lists/* && \
31+
mkdir -p /build/gc && cd /build/gc && \
32+
git init && \
33+
git remote add origin "${GUEST_COMPONENTS_REPO}" && \
34+
git fetch --depth=1 origin "${GUEST_COMPONENTS_REF}" && \
35+
git reset --hard FETCH_HEAD; \
36+
fi
37+
COPY cloud-api-adaptor/podvm/build-guest-components.sh /build/
38+
RUN /build/build-guest-components.sh "${CUSTOM_GC_BINARIES}" "${AA_FEATURES}"
39+
840
# ubuntu:24.04
941
FROM ubuntu@sha256:0d39fcc8335d6d74d5502f6df2d30119ff4790ebbb60b364818d5112d9e3e932 AS builder
1042

@@ -108,5 +140,11 @@ RUN ./hack/cross-build-extras.sh
108140

109141
RUN LIBC=gnu make binaries
110142

143+
COPY --from=gc_builder /output/ /tmp/gc-overrides/
144+
RUN for bin in /tmp/gc-overrides/*; do \
145+
[ -f "$bin" ] && [ -s "$bin" ] && \
146+
install -m0755 "$bin" /src/cloud-api-adaptor/podvm/files/usr/local/bin/"$(basename "$bin")"; \
147+
done; true
148+
111149
FROM scratch
112150
COPY --from=podvm_binaries_builder /src/cloud-api-adaptor/podvm/files /
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#!/bin/bash
2+
# Build selected guest-components binaries from source.
3+
#
4+
# Usage: build-guest-components.sh <comma-separated-binaries> [aa-features]
5+
#
6+
# Recognized binaries:
7+
# attestation-agent — requires aa-features argument
8+
# api-server-rest
9+
# confidential-data-hub
10+
#
11+
# Source must already be cloned at /build/gc.
12+
# Compiled binaries are placed in /output/.
13+
14+
set -euo pipefail
15+
16+
BINARIES="${1:-}"
17+
AA_FEATURES="${2:-}"
18+
OUTDIR="/output"
19+
mkdir -p "$OUTDIR"
20+
21+
[ -z "$BINARIES" ] && exit 0
22+
23+
IFS=',' read -ra BINS <<< "$BINARIES"
24+
for bin in "${BINS[@]}"; do
25+
bin=$(echo "$bin" | xargs) # trim whitespace
26+
case "$bin" in
27+
attestation-agent)
28+
if [ -z "$AA_FEATURES" ]; then
29+
echo "ERROR: attestation-agent requires AA_FEATURES" >&2
30+
exit 1
31+
fi
32+
cd /build/gc/attestation-agent/attestation-agent
33+
cargo build --release --locked --no-default-features \
34+
--features "$AA_FEATURES" --bin ttrpc-aa
35+
cp /build/gc/target/release/ttrpc-aa "$OUTDIR/attestation-agent"
36+
;;
37+
api-server-rest)
38+
cd /build/gc/api-server-rest
39+
cargo build --release --locked
40+
cp /build/gc/target/release/api-server-rest "$OUTDIR/api-server-rest"
41+
;;
42+
confidential-data-hub)
43+
cd /build/gc/confidential-data-hub
44+
cargo build --release --locked
45+
cp /build/gc/target/release/confidential-data-hub "$OUTDIR/confidential-data-hub"
46+
;;
47+
*)
48+
echo "ERROR: Unknown guest component: $bin" >&2
49+
echo "Recognized: attestation-agent, api-server-rest, confidential-data-hub" >&2
50+
exit 1
51+
;;
52+
esac
53+
echo "Built: $bin"
54+
done

0 commit comments

Comments
 (0)