eBPF-based security platform
github: Add a workflow to build kernel-obs
Michi Mutsuzaki2c4f0d405c7d
diff --git a/.github/workflows/kernel-obs.yml b/.github/workflows/kernel-obs.ymlnew file mode 100644index 00000000..c22375f5--- /dev/null+++ b/.github/workflows/kernel-obs.yml@@ -0,0 +1,222 @@+name: Build kernel-obs BPM package++on:+ workflow_run:+ workflows: ["Build packages"]+ types: [completed]++permissions:+ actions: read+ contents: read++jobs:+ filter:+ if: >-+ github.event.workflow_run.conclusion == 'success' &&+ ((github.event.workflow_run.event == 'push' &&+ github.event.workflow_run.head_branch == 'main') ||+ (github.event.workflow_run.event == 'pull_request' &&+ github.event.workflow_run.pull_requests[0].head.repo.full_name ==+ github.repository))+ runs-on: ubuntu-latest+ timeout-minutes: 15+ outputs:+ eligible: ${{ steps.prepare.outputs.eligible }}+ source_sha: ${{ steps.prepare.outputs.source_sha }}+ version: ${{ steps.prepare.outputs.version }}+ steps:+ - name: Check out source revision+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1+ with:+ ref: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.pull_requests[0].head.sha || github.event.workflow_run.head_sha }}+ path: source-code+ persist-credentials: false+ fetch-depth: 0++ - name: Select package revision and version+ id: prepare+ env:+ SOURCE_EVENT: ${{ github.event.workflow_run.event }}+ SOURCE_SHA: ${{ github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.pull_requests[0].head.sha || github.event.workflow_run.head_sha }}+ BASE_SHA: ${{ github.event.workflow_run.pull_requests[0].base.sha }}+ PR_NUMBER: ${{ github.event.workflow_run.pull_requests[0].number }}+ RUN_NUMBER: ${{ github.event.workflow_run.run_number }}+ run: |+ set -eu++ case "$SOURCE_EVENT" in+ push)+ version="0.1.$RUN_NUMBER"+ eligible=true+ ;;+ pull_request)+ version="0.1.$RUN_NUMBER-pr.$PR_NUMBER"+ if ! git -C source-code cat-file -e "$BASE_SHA^{commit}" 2>/dev/null; then+ git -C source-code fetch --no-tags --depth=1 origin "$BASE_SHA"+ fi+ changed=$(git -C source-code diff --name-only \+ "$BASE_SHA...$SOURCE_SHA")+ if [ -n "$changed" ] &&+ ! printf '%s\n' "$changed" | grep -Eqv '^upatches/kernel-obs/'; then+ eligible=true+ else+ eligible=false+ fi+ ;;+ *)+ echo "unsupported source event: $SOURCE_EVENT" >&2+ exit 1+ ;;+ esac++ printf 'source_sha=%s\n' "$SOURCE_SHA" >> "$GITHUB_OUTPUT"+ printf 'version=%s\n' "$version" >> "$GITHUB_OUTPUT"+ printf 'eligible=%s\n' "$eligible" >> "$GITHUB_OUTPUT"++ build-and-publish:+ needs: filter+ if: needs.filter.outputs.eligible == 'true'+ runs-on: ubuntu-latest+ timeout-minutes: 15+ environment:+ name: kernel-obs+ permissions:+ actions: read+ contents: read+ packages: write+ steps:+ - name: Check out package source+ uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1+ with:+ ref: ${{ needs.filter.outputs.source_sha }}+ path: source-code+ persist-credentials: false++ - name: Download Shirudo operator package+ uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2+ with:+ name: shirudo-deb+ path: upstream/shirudo-deb+ repository: ${{ github.repository }}+ run-id: ${{ github.event.workflow_run.id }}+ github-token: ${{ secrets.GITHUB_TOKEN }}++ - 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+ repository: ${{ github.repository }}+ run-id: ${{ github.event.workflow_run.id }}+ github-token: ${{ secrets.GITHUB_TOKEN }}++ - name: Write package version+ env:+ KERNEL_OBS_VERSION: ${{ needs.filter.outputs.version }}+ run: |+ set -eu+ test -n "$KERNEL_OBS_VERSION"+ mkdir -p build+ printf '%s\n' "$KERNEL_OBS_VERSION" > build/kernel-obs-version++ - name: Materialize signing key+ env:+ KERNEL_OBS_SIGNING_KEY_PEM: ${{ secrets.KERNEL_OBS_SIGNING_KEY_PEM }}+ KERNEL_OBS_CERT_DER_B64: ${{ secrets.KERNEL_OBS_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: Build BPM package in LVH+ uses: cilium/little-vm-helper@f86d344aca812dda5aef167867a9a0a90ca6cca5 # v0.0.31+ with:+ test-name: shirudo-kernel-obs+ 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: true+ cpu: 4+ mem: 8G+ cmd: |+ set -eu+ cd /host+ apt-get update+ apt-get install -y /host/upstream/shirudo-deb/shirudo-operator_*.deb++ keys_dir=/host/.ci/kernel-obs-keys+ version=\$(cat /host/build/kernel-obs-version)+ /usr/bin/shirudo bpm build /host/source-code/upatches/kernel-obs \+ --version "\$version" \+ --keys-dir "\$keys_dir" \+ --vmlinux /host/upstream/bpf-next-vmlinux-h/vmlinux.h++ test -s "/host/kernel-obs-\$version.bee"+ /usr/bin/shirudo bpm info "/host/kernel-obs-\$version.bee"++ - name: Upload BPM package+ uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2+ with:+ name: kernel-obs-bpm+ path: kernel-obs-*.bee+ if-no-files-found: error++ - name: Materialize registry credentials+ env:+ KERNEL_OBS_REGISTRY_USERNAME: ${{ github.actor }}+ KERNEL_OBS_REGISTRY_TOKEN: ${{ secrets.GITHUB_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: Publish BPM package+ uses: cilium/little-vm-helper@f86d344aca812dda5aef167867a9a0a90ca6cca5 # v0.0.31+ with:+ test-name: shirudo-kernel-obs-publish+ 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: true+ cpu: 4+ mem: 8G+ cmd: |+ set -eu+ cd /host+ apt-get update+ apt-get install -y /host/upstream/shirudo-deb/shirudo-operator_*.deb++ install -d -m 0755 /etc/shirudo+ printf '%s\n' 'tls.classical_hosts = ghcr.io' \+ > /etc/shirudo/shirudo.conf+ /usr/bin/shirudo config >/dev/null++ version=\$(cat /host/build/kernel-obs-version)+ package="/host/package/kernel-obs-\$version.bee"+ test -s "\$package"+ {+ 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 /host/.ci/kernel-obs-keys++ - name: Remove credentials and signing key material+ if: always()+ run: rm -rf .ci/kernel-obs-keys .ci/kernel-obs-registry-credentials