Skip to content

eBPF-based security platform

ci: Build kernel-obs for pull requests with temporary keys

Michi Mutsuzakica1eef3034d2
diff --git a/.github/actions/kernel-obs/action.yml b/.github/actions/kernel-obs/action.yml
new file mode 100644
index 00000000..28084381
--- /dev/null
+++ b/.github/actions/kernel-obs/action.yml
@@ -0,0 +1,140 @@
+name: Build kernel-obs BPM package
+description: Build a kernel-obs BPM package with preview or production signing
+
+inputs:
+ mode:
+ description: Either preview or publish
+ required: true
+ version:
+ description: BPM package version
+ required: true
+ artifact-name:
+ description: Name of the uploaded artifact
+ required: true
+ signing-key-pem:
+ description: Production ML-DSA signing key in PEM format
+ required: false
+ cert-der-b64:
+ description: Production signing certificate in base64-encoded DER format
+ required: false
+ registry-username:
+ description: Registry username for production publishing
+ required: false
+ registry-token:
+ description: Registry token for production publishing
+ required: false
+
+runs:
+ using: composite
+ steps:
+ - name: Download shirudo operator package
+ uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
+ with:
+ name: shirudo-deb
+ path: upstream/shirudo-deb
+
+ - name: Download bpf-next kernel header
+ uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
+ with:
+ name: bpf-next-vmlinux-h
+ path: upstream/bpf-next-vmlinux-h
+
+ - name: Write build inputs
+ shell: bash
+ env:
+ KERNEL_OBS_MODE: ${{ inputs.mode }}
+ KERNEL_OBS_VERSION: ${{ inputs.version }}
+ run: |
+ set -eu
+ case "$KERNEL_OBS_MODE" in
+ preview|publish) ;;
+ *)
+ echo "unsupported kernel-obs build mode: $KERNEL_OBS_MODE" >&2
+ exit 1
+ ;;
+ esac
+ test -n "$KERNEL_OBS_VERSION"
+ install -d -m 0755 build
+ printf '%s\n' "$KERNEL_OBS_MODE" > build/kernel-obs-mode
+ printf '%s\n' "$KERNEL_OBS_VERSION" > build/kernel-obs-version
+
+ - name: Ensure QEMU is installed
+ shell: bash
+ run: |
+ set -eu
+ if ! command -v qemu-system-x86_64 >/dev/null 2>&1; then
+ sudo apt-get update
+ sudo apt-get install -y --reinstall qemu-system-x86
+ fi
+ command -v qemu-system-x86_64
+
+ - name: Materialize production signing key
+ if: inputs.mode == 'publish'
+ shell: bash
+ env:
+ KERNEL_OBS_SIGNING_KEY_PEM: ${{ inputs['signing-key-pem'] }}
+ KERNEL_OBS_CERT_DER_B64: ${{ inputs['cert-der-b64'] }}
+ run: |
+ set -eu
+ keys_dir=.ci/kernel-obs-keys
+ test -n "$KERNEL_OBS_SIGNING_KEY_PEM"
+ test -n "$KERNEL_OBS_CERT_DER_B64"
+ install -d -m 0700 "$keys_dir"
+ printf '%s\n' "$KERNEL_OBS_SIGNING_KEY_PEM" > "$keys_dir/signing_key.pem"
+ printf '%s' "$KERNEL_OBS_CERT_DER_B64" | base64 --decode > "$keys_dir/cert.der"
+ chmod 0600 "$keys_dir/signing_key.pem" "$keys_dir/cert.der"
+
+ - name: Materialize registry credentials
+ if: inputs.mode == 'publish'
+ shell: bash
+ env:
+ KERNEL_OBS_REGISTRY_USERNAME: ${{ inputs['registry-username'] }}
+ KERNEL_OBS_REGISTRY_TOKEN: ${{ inputs['registry-token'] }}
+ run: |
+ set -eu
+ test -n "$KERNEL_OBS_REGISTRY_USERNAME"
+ test -n "$KERNEL_OBS_REGISTRY_TOKEN"
+ install -d -m 0700 .ci
+ umask 077
+ printf '%s\n%s\n' "$KERNEL_OBS_REGISTRY_USERNAME" \
+ "$KERNEL_OBS_REGISTRY_TOKEN" > .ci/kernel-obs-registry-credentials
+
+ - name: Prepare preview signer directory
+ if: inputs.mode == 'preview'
+ shell: bash
+ run: install -d -m 0700 .ci/kernel-obs-preview-keys
+
+ - name: Build package in LVH
+ uses: cilium/little-vm-helper@c8b0bfbae3bdda7bc69fb9cd370e4b74ce84986d # v0.0.33
+ with:
+ test-name: shirudo-kernel-obs-${{ inputs.mode }}
+ image: kind
+ image-version: bpf-next-20260603.072225
+ kernel-version: bpf-next-main
+ host-mount: ${{ github.workspace }}
+ images-folder-parent: ${{ github.workspace }}/../lvh
+ install-dependencies: false
+ ssh-port: 2222
+ cmd: /bin/sh /host/.github/scripts/kernel-obs-in-lvh.sh
+
+ - name: Upload preview package and public certificate
+ if: inputs.mode == 'preview'
+ uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
+ with:
+ name: ${{ inputs['artifact-name'] }}
+ path: kernel-obs-preview/
+ if-no-files-found: error
+ retention-days: 14
+
+ - name: Upload published BPM package
+ if: always() && inputs.mode == 'publish'
+ uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2
+ with:
+ name: ${{ inputs['artifact-name'] }}
+ path: kernel-obs-*.bee
+ if-no-files-found: ignore
+
+ - name: Remove signer and registry credentials
+ if: always()
+ shell: bash
+ run: rm -rf .ci/kernel-obs-keys .ci/kernel-obs-preview-keys .ci/kernel-obs-registry-credentials
diff --git a/.github/scripts/kernel-obs-in-lvh.sh b/.github/scripts/kernel-obs-in-lvh.sh
new file mode 100755
index 00000000..14dfb1e6
--- /dev/null
+++ b/.github/scripts/kernel-obs-in-lvh.sh
@@ -0,0 +1,65 @@
+#!/bin/sh
+# SPDX-License-Identifier: BSD-2-Clause
+# Copyright (c) 2026 Authors of shirudo
+
+set -eu
+
+cd /host
+mode=$(cat build/kernel-obs-mode)
+version=$(cat build/kernel-obs-version)
+test -n "$version"
+
+apt-get update
+if ! DEBIAN_FRONTEND=noninteractive apt-get -o Dpkg::Use-Pty=0 \
+ install -y /host/upstream/shirudo-deb/shirudo-operator_*.deb; then
+ /bin/sh /host/.github/scripts/kernel-obs-apt-diagnostics.sh
+ exit 1
+fi
+
+case "$mode" in
+preview)
+ keys_dir=/host/.ci/kernel-obs-preview-keys
+ trap 'rm -rf "$keys_dir"' EXIT
+ install -d -m 0700 "$keys_dir"
+ /usr/bin/shirudo genkey --keys-dir "$keys_dir"
+ ;;
+publish)
+ keys_dir=/host/.ci/kernel-obs-keys
+ test -s "$keys_dir/signing_key.pem"
+ test -s "$keys_dir/cert.der"
+ ;;
+*)
+ echo "unsupported kernel-obs build mode: $mode" >&2
+ exit 1
+ ;;
+esac
+
+/usr/bin/shirudo bpm build /host/upatches/kernel-obs \
+ --version "$version" \
+ --keys-dir "$keys_dir" \
+ --vmlinux /host/upstream/bpf-next-vmlinux-h/vmlinux.h
+
+package="/host/kernel-obs-$version.bee"
+test -s "$package"
+/usr/bin/shirudo bpm info "$package"
+
+case "$mode" in
+preview)
+ install -d -m 0755 /host/kernel-obs-preview
+ cp "$package" /host/kernel-obs-preview/
+ install -m 0644 "$keys_dir/cert.der" /host/kernel-obs-preview/cert.der
+ ;;
+publish)
+ install -d -m 0755 /etc/shirudo
+ printf '%s\n' 'tls.classical_hosts = ghcr.io' > /etc/shirudo/shirudo.conf
+ /usr/bin/shirudo config
+ {
+ IFS= read -r BPM_OCI_USERNAME
+ IFS= read -r BPM_OCI_PASSWORD
+ } < /host/.ci/kernel-obs-registry-credentials
+ export BPM_OCI_USERNAME BPM_OCI_PASSWORD
+ /usr/bin/shirudo bpm push "$package" \
+ oci://ghcr.io/shirudo-dev/kernel-obs \
+ --keys-dir "$keys_dir"
+ ;;
+esac
diff --git a/.github/workflows/packages.yml b/.github/workflows/packages.yml
index 890d9b18..73d29658 100644
--- a/.github/workflows/packages.yml
+++ b/.github/workflows/packages.yml
@@ -320,6 +320,52 @@ jobs:
path: vmlinux.h
if-no-files-found: error
+ kernel-obs-preview:
+ if: github.event_name == 'pull_request'
+ needs: [deb, rpm-target]
+ runs-on: ubuntu-latest
+ timeout-minutes: 30
+ steps:
+ - name: Check out repository
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ with:
+ persist-credentials: false
+
+ - name: Build preview package with a temporary signer
+ uses: ./.github/actions/kernel-obs
+ with:
+ mode: preview
+ version: 0.1.${{ github.run_number }}-pr.${{ github.event.pull_request.number }}
+ artifact-name: kernel-obs-preview-pr-${{ github.event.pull_request.number }}
+
+ kernel-obs-publish:
+ if: github.event_name == 'push' && github.ref == 'refs/heads/main'
+ needs: [deb, rpm-target]
+ runs-on: ubuntu-latest
+ timeout-minutes: 30
+ environment:
+ name: kernel-obs
+ permissions:
+ actions: read
+ contents: read
+ packages: write
+ steps:
+ - name: Check out repository
+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ with:
+ persist-credentials: false
+
+ - name: Build and publish BPM package
+ uses: ./.github/actions/kernel-obs
+ with:
+ mode: publish
+ version: 0.1.${{ github.run_number }}
+ artifact-name: kernel-obs-bpm
+ signing-key-pem: ${{ secrets.KERNEL_OBS_SIGNING_KEY_PEM }}
+ cert-der-b64: ${{ secrets.KERNEL_OBS_CERT_DER_B64 }}
+ registry-username: ${{ github.actor }}
+ registry-token: ${{ secrets.GITHUB_TOKEN }}
+
rpm-operator:
needs: rpm-target
runs-on: ubuntu-latest