Skip to content

eBPF-based security platform

ci: Build signed image assets

Michi Mutsuzakif93ff2a872cb
diff --git a/.github/scripts/build-image-assets.sh b/.github/scripts/build-image-assets.sh
new file mode 100755
index 00000000..ff55fab1
--- /dev/null
+++ b/.github/scripts/build-image-assets.sh
@@ -0,0 +1,116 @@
+#!/usr/bin/env bash
+# SPDX-License-Identifier: BSD-2-Clause
+# Copyright (c) 2026 Authors of shirudo
+
+set -euo pipefail
+
+: "${SHIRUDO_DIR:?SHIRUDO_DIR must name the Shirudo checkout}"
+: "${SHIRUDO_PACKAGE_DIR:?SHIRUDO_PACKAGE_DIR must name the downloaded Shirudo package artifact}"
+: "${OUTPUT_DIR:?OUTPUT_DIR must name the artifact output directory}"
+
+config_root="${SHIRUDO_DIR}/infra/image-inputs/config-root"
+runtime_conf="${SHIRUDO_DIR}/infra/image-inputs/runtime-root/etc/shirudo/shirudo.conf"
+bpf_cert="${SHIRUDO_DIR}/infra/certs/shirudo.der"
+work_dir="$(mktemp -d "${RUNNER_TEMP:-/tmp}/shirudo-image-build.XXXXXX")"
+trap 'rm -rf "$work_dir"' EXIT
+
+config_keys_dir="${work_dir}/config-image-signing"
+image_dir="${work_dir}/images"
+asset_dir="${work_dir}/assets"
+config_prefix="${image_dir}/initial"
+runtime_prefix="${image_dir}/runtime"
+runtime_service="${image_dir}/runtime-service.conf"
+asset_tarball="${OUTPUT_DIR}/shirudo-image-assets.tar.gz"
+
+test -d "$config_root"
+test -s "$runtime_conf"
+test -s "$bpf_cert"
+test -x "${SHIRUDO_DIR}/tools/gen-image/shirudo-gen-image"
+test -x "${SHIRUDO_DIR}/tools/gen-image/shirudo-gen-runtime"
+
+install -d -m 0700 "$config_keys_dir" "$image_dir" "$asset_dir" "$OUTPUT_DIR"
+
+target_deb="$(find "$SHIRUDO_PACKAGE_DIR" -type f -name 'shirudo-target_*_amd64.deb' -print -quit)"
+operator_deb="$(find "$SHIRUDO_PACKAGE_DIR" -type f -name 'shirudo-operator_*_amd64.deb' -print -quit)"
+if [[ -z "$target_deb" || -z "$operator_deb" ]]; then
+ echo "shirudo-deb artifact must contain target and operator amd64 packages" >&2
+ exit 1
+fi
+
+target_root="${work_dir}/target-package"
+dpkg-deb -x "$target_deb" "$target_root"
+target_binary="${target_root}/usr/bin/shirudo"
+builder=/usr/libexec/shirudo/shirudo-build
+sudo apt-get install -y --no-install-recommends "$operator_deb"
+test -x "$target_binary"
+test -x "$builder"
+shirudo_binary="$(command -v shirudo)"
+sudo setcap cap_ipc_lock+ep "$shirudo_binary"
+getcap "$shirudo_binary" | grep -Fq 'cap_ipc_lock=ep'
+sudo setcap cap_ipc_lock+ep "$builder"
+getcap "$builder" | grep -Fq 'cap_ipc_lock=ep'
+# The config signer is temporary and exists only for this image build.
+shirudo genkey --keys-dir "$config_keys_dir"
+
+"${SHIRUDO_DIR}/tools/gen-image/shirudo-gen-image" \
+ --source "$config_root" \
+ --output "$config_prefix" \
+ --kind config \
+ --keys-dir "$config_keys_dir" \
+ --builder "$builder"
+
+"${SHIRUDO_DIR}/tools/gen-image/shirudo-gen-runtime" \
+ --binary "$target_binary" \
+ --bootstrap-conf "$runtime_conf" \
+ --cert "$bpf_cert" \
+ --config-cert "${config_keys_dir}/cert.der" \
+ --output "$runtime_prefix" \
+ --keys-dir "$config_keys_dir" \
+ --builder "$builder" \
+ --unit-output "$runtime_service"
+
+for suffix in img verity roothash p7s; do
+ test -s "${config_prefix}.${suffix}"
+ test -s "${runtime_prefix}.${suffix}"
+ install -m 0644 "${config_prefix}.${suffix}" "$asset_dir/initial.${suffix}"
+ install -m 0644 "${runtime_prefix}.${suffix}" "$asset_dir/runtime.${suffix}"
+done
+
+install -m 0644 "$runtime_service" "$asset_dir/runtime-service.conf"
+install -m 0755 "$target_binary" "$asset_dir/shirudo-target"
+
+runtime_root_hash="$(cat "${runtime_prefix}.roothash")"
+if [[ ! "$runtime_root_hash" =~ ^[[:xdigit:]]{64}$ ]]; then
+ echo "Invalid runtime root hash: ${runtime_root_hash}" >&2
+ exit 1
+fi
+printf 'runtime.image = /var/lib/shirudo/images/runtime\nruntime.root_hash = %s\n' \
+ "$runtime_root_hash" > "$asset_dir/initrd-bootstrap.conf"
+chmod 0644 "$asset_dir/initrd-bootstrap.conf"
+
+tar -czf "$asset_tarball" -C "$asset_dir" \
+ shirudo-target \
+ initial.img initial.verity initial.roothash initial.p7s \
+ runtime.img runtime.verity runtime.roothash runtime.p7s \
+ runtime-service.conf initrd-bootstrap.conf
+(cd "$OUTPUT_DIR" && sha256sum "$(basename "$asset_tarball")" \
+ > "$(basename "$asset_tarball").sha256")
+
+# Check the published bundle contains the complete signed image asset set.
+tar -tzf "$asset_tarball" | LC_ALL=C sort > "${work_dir}/asset-list"
+cat > "${work_dir}/expected-asset-list" <<'EOF'
+initrd-bootstrap.conf
+initial.img
+initial.p7s
+initial.roothash
+initial.verity
+runtime-service.conf
+runtime.img
+runtime.p7s
+runtime.roothash
+runtime.verity
+shirudo-target
+EOF
+LC_ALL=C sort -o "${work_dir}/expected-asset-list" \
+ "${work_dir}/expected-asset-list"
+diff -u "${work_dir}/expected-asset-list" "${work_dir}/asset-list"
diff --git a/.github/workflows/packages.yml b/.github/workflows/packages.yml
index 3d1e0215..2a20e388 100644
--- a/.github/workflows/packages.yml
+++ b/.github/workflows/packages.yml
@@ -162,6 +162,63 @@ jobs:
shirudo-static.tar.gz.spdx.json
if-no-files-found: error
+ image-assets:
+ needs: deb
+ runs-on: ubuntu-26.04
+ timeout-minutes: 5
+
+ steps:
+ - name: Check out repository
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ with:
+ persist-credentials: false
+
+ - name: Install image tools
+ run: |
+ sudo apt-get update
+ sudo apt-get install -y --no-install-recommends \
+ binutils \
+ ca-certificates \
+ clang \
+ coreutils \
+ cryptsetup-bin \
+ dpkg-dev \
+ e2fsprogs \
+ file \
+ libcap2-bin \
+ libcurl4 \
+ libssl3t64 \
+ libtss2-tctildr0 \
+ openssl \
+ python3 \
+ xz-utils
+
+ - name: Install clang 23
+ run: sudo sh .github/scripts/install-clang.sh
+
+ - name: Download Debian packages
+ uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
+ with:
+ name: shirudo-deb
+ path: ${{ runner.temp }}/shirudo-packages
+
+ - name: Build image assets with a temporary signer
+ env:
+ SHIRUDO_DIR: ${{ github.workspace }}
+ SHIRUDO_PACKAGE_DIR: ${{ runner.temp }}/shirudo-packages
+ OUTPUT_DIR: ${{ runner.temp }}/shirudo-image-assets
+ run: .github/scripts/build-image-assets.sh
+
+ - name: Upload image assets
+ uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
+ with:
+ name: shirudo-image-assets-${{ github.run_number }}-${{ github.run_attempt }}
+ path: |
+ ${{ runner.temp }}/shirudo-image-assets/shirudo-image-assets.tar.gz
+ ${{ runner.temp }}/shirudo-image-assets/shirudo-image-assets.tar.gz.sha256
+ if-no-files-found: error
+ retention-days: 14
+
rpm-target:
outputs:
version: ${{ steps.build-version.outputs.version }}
diff --git a/infra/certs/shirudo.der b/infra/certs/shirudo.der
new file mode 100644
index 00000000..16820a27
Binary files /dev/null and b/infra/certs/shirudo.der differ
diff --git a/infra/image-inputs/config-root/etc/shirudo/shirudo.conf b/infra/image-inputs/config-root/etc/shirudo/shirudo.conf
new file mode 100644
index 00000000..b83653da
--- /dev/null
+++ b/infra/image-inputs/config-root/etc/shirudo/shirudo.conf
@@ -0,0 +1,3 @@
+# Initial config-image settings.
+# Add eventlog, map-export, repository, and node settings here as needed.
+eventlog.max_bytes = 0
diff --git a/infra/image-inputs/runtime-root/etc/shirudo/shirudo.conf b/infra/image-inputs/runtime-root/etc/shirudo/shirudo.conf
new file mode 100644
index 00000000..90deaf3d
--- /dev/null
+++ b/infra/image-inputs/runtime-root/etc/shirudo/shirudo.conf
@@ -0,0 +1,7 @@
+# Runtime policy for the initial config image.
+config.image = /var/lib/shirudo/images/initial
+config.verification_key = /run/shirudo/runtime/etc/shirudo/config-cert.der
+config.pcr = 13
+tpm.tcti = device:/dev/tpmrm0
+# Allow classical TLS key exchange for ghcr.io. It does not offer hybrid TLS yet.
+tls.classical_hosts = ghcr.io