Implement kernel signing

This commit is contained in:
2025-09-09 21:05:02 -04:00
parent 851b1c048e
commit 756653ae99
16 changed files with 200 additions and 39 deletions

1
.gitignore vendored
View File

@@ -1,5 +1,6 @@
.idea .idea
cosign.key cosign.key
.secure-files/
/Containerfile /Containerfile
/.env /.env
/Containerfile.* /Containerfile.*

View File

@@ -41,14 +41,13 @@ base-images:
parallel: parallel:
matrix: matrix:
- RECIPE: - RECIPE:
- base-kinoite.yml # - base-cosmic.yml
- base-cosmic.yml
- base-kinoite-nvidia.yml
- base-cosmic-nvidia.yml - base-cosmic-nvidia.yml
# - base-kinoite.yml
# - base-kinoite-nvidia.yml
# TAG: 519-device-or-resource-busy-when-trying-to-rechunk-the-image-in-gitlab-ci # TAG: 519-device-or-resource-busy-when-trying-to-rechunk-the-image-in-gitlab-ci
# BB_BUILD_PUSH: 'true' BB_BUILD_PUSH: 'true'
BB_CACHE_LAYERS: 'true' BB_BUILD_RECHUNK: 'true'
# BB_BUILD_RECHUNK: 'true'
build-image: build-image:
extends: extends:

View File

@@ -0,0 +1,58 @@
#!/usr/bin/env bash
# Copyright 2025 Universal Blue
# Copyright 2025 The Secureblue Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and limitations under the License.
set -oue pipefail
mkdir -p /var/tmp
chmod 1777 /var/tmp
KERNEL_VERSION="$(rpm -q "kernel" --queryformat '%{VERSION}-%{RELEASE}.%{ARCH}')"
RELEASE="$(rpm -E '%fedora.%_arch')"
KERNEL_MODULE_TYPE="kernel"
if [[ "$IMAGE_NAME" == *"open"* ]]; then
KERNEL_MODULE_TYPE+="-open"
fi
curl -Lo /etc/yum.repos.d/negativo17-fedora-nvidia.repo https://negativo17.org/repos/fedora-nvidia.repo
sed -i '/^enabled=1/a\priority=90' /etc/yum.repos.d/negativo17-fedora-nvidia.repo
dnf install -y "kernel-devel-matched-$(rpm -q 'kernel' --queryformat '%{VERSION}')"
dnf install -y "akmod-nvidia*.fc${RELEASE}"
echo "Setting kernel.conf to $KERNEL_MODULE_TYPE"
sed -i --sandbox "s/^MODULE_VARIANT=.*/MODULE_VARIANT=$KERNEL_MODULE_TYPE/" /etc/nvidia/kernel.conf
echo "Installing kmod..."
akmods --force --kernels "${KERNEL_VERSION}" --kmod "nvidia"
# Depends on word splitting
# shellcheck disable=SC2086
modinfo /usr/lib/modules/${KERNEL_VERSION}/extra/nvidia/nvidia{,-drm,-modeset,-peermem,-uvm}.ko.xz > /dev/null || \
(cat "/var/cache/akmods/nvidia/*.failed.log" && exit 1)
# View license information
# Depends on word splitting
# shellcheck disable=SC2086
modinfo -l /usr/lib/modules/${KERNEL_VERSION}/extra/nvidia/nvidia{,-drm,-modeset,-peermem,-uvm}.ko.xz
./signmodules.sh "nvidia"
rm -f /etc/yum.repos.d/negativo17-fedora-nvidia.repo
systemctl disable akmods-keygen@akmods-keygen.service
systemctl mask akmods-keygen@akmods-keygen.service
systemctl disable akmods-keygen.target
systemctl mask akmods-keygen.target

View File

@@ -0,0 +1,51 @@
#!/usr/bin/env bash
# Copyright 2025 The Secureblue Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software distributed under the License is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and limitations under the License.
set -oue pipefail
nvidia_packages_list=('nvidia-container-toolkit' 'nvidia-driver-cuda')
if [[ "$IMAGE_NAME" != *"securecore"* ]]; then
nvidia_packages_list+=('libnvidia-fbc' 'libva-nvidia-driver' 'nvidia-driver' 'nvidia-modprobe' 'nvidia-persistenced' 'nvidia-settings')
fi
curl -L https://nvidia.github.io/libnvidia-container/stable/rpm/nvidia-container-toolkit.repo \
-o /etc/yum.repos.d/nvidia-container-toolkit.repo
sed -i 's/^gpgcheck=0/gpgcheck=1/' /etc/yum.repos.d/nvidia-container-toolkit.repo
curl -L https://negativo17.org/repos/fedora-nvidia.repo -o /etc/yum.repos.d/negativo17-fedora-nvidia.repo
sed -i 's/^enabled=0.*/enabled=1/' /etc/yum.repos.d/nvidia-container-toolkit.repo
sed -i 's/^enabled=0.*/enabled=1\npriority=90/' /etc/yum.repos.d/negativo17-fedora-nvidia.repo
# required for rpm-ostree to function properly
# shellcheck disable=SC2068
rpm-ostree install ${nvidia_packages_list[@]}
kmod_version=$(rpm -qa | grep akmod-nvidia | awk -F':' '{print $(NF)}' | awk -F'-' '{print $(NF-1)}')
negativo_version=$(rpm -qa | grep nvidia-modprobe | awk -F':' '{print $(NF)}' | awk -F'-' '{print $(NF-1)}')
echo "kmod_version: ${kmod_version}"
echo "negativo_version: ${negativo_version}"
if [[ "$kmod_version" != "$negativo_version" ]]; then
echo "Version mismatch!"
exit 1
fi
curl -L https://raw.githubusercontent.com/NVIDIA/dgx-selinux/master/bin/RHEL9/nvidia-container.pp \
-o nvidia-container.pp
semodule -i nvidia-container.pp
rm -f nvidia-container.pp
rm -f /etc/yum.repos.d/negativo17-fedora-nvidia.repo
rm -f /etc/yum.repos.d/nvidia-container-toolkit.repo

View File

@@ -17,8 +17,7 @@ set -oue pipefail
KERNEL_VERSION="$(rpm -q "kernel" --queryformat '%{VERSION}-%{RELEASE}.%{ARCH}')" KERNEL_VERSION="$(rpm -q "kernel" --queryformat '%{VERSION}-%{RELEASE}.%{ARCH}')"
PUBLIC_KEY_DER_PATH="../system/etc/pki/akmods/certs/akmods-secureblue.der" PUBLIC_KEY_CRT_PATH="/tmp/certs/public_key.crt"
PUBLIC_KEY_CRT_PATH="./certs/public_key.crt"
PRIVATE_KEY_PATH="/tmp/certs/private_key.priv" PRIVATE_KEY_PATH="/tmp/certs/private_key.priv"
openssl x509 -in "$PUBLIC_KEY_DER_PATH" -out "$PUBLIC_KEY_CRT_PATH" openssl x509 -in "$PUBLIC_KEY_DER_PATH" -out "$PUBLIC_KEY_CRT_PATH"

View File

@@ -23,13 +23,12 @@ fi
KERNEL_VERSION="$(rpm -q "kernel" --queryformat '%{VERSION}-%{RELEASE}.%{ARCH}')" KERNEL_VERSION="$(rpm -q "kernel" --queryformat '%{VERSION}-%{RELEASE}.%{ARCH}')"
PUBLIC_KEY_DER_PATH="../system/etc/pki/akmods/certs/akmods-secureblue.der" PUBLIC_KEY_CRT_PATH="/tmp/certs/public_key.crt"
PUBLIC_KEY_CRT_PATH="./certs/public_key.crt"
PRIVATE_KEY_PATH="/tmp/certs/private_key.priv" PRIVATE_KEY_PATH="/tmp/certs/private_key.priv"
openssl x509 -in "$PUBLIC_KEY_DER_PATH" -out "$PUBLIC_KEY_CRT_PATH" openssl x509 -in "$PUBLIC_KEY_DER_PATH" -out "$PUBLIC_KEY_CRT_PATH"
PRIVATE_KEY_PATH="/tmp/certs/private_key.priv" PRIVATE_KEY_PATH="/tmp/certs/private_key.priv"
SIGNING_KEY="./certs/signing_key.pem" SIGNING_KEY="/tmp/certs/signing_key.pem"
cat "$PRIVATE_KEY_PATH" <(echo) "$PUBLIC_KEY_CRT_PATH" >> "$SIGNING_KEY" cat "$PRIVATE_KEY_PATH" <(echo) "$PUBLIC_KEY_CRT_PATH" >> "$SIGNING_KEY"
for module in /usr/lib/modules/"${KERNEL_VERSION}"/extra/"${MODULE_NAME}"/*.ko*; do for module in /usr/lib/modules/"${KERNEL_VERSION}"/extra/"${MODULE_NAME}"/*.ko*; do

View File

@@ -46,3 +46,10 @@ toggle-nvk:
echo "Rebasing to ${NEW_IMAGE}" echo "Rebasing to ${NEW_IMAGE}"
rpm-ostree rebase ${CURRENT_URI}${NEW_IMAGE} rpm-ostree rebase ${CURRENT_URI}${NEW_IMAGE}
just _configure-nvidia ${CONFIG_ACTION} just _configure-nvidia ${CONFIG_ACTION}
generate-secureboot-key:
openssl req -config ./openssl.cnf \
-new -x509 -newkey rsa:2048 \
-nodes -days 36500 -outform DER \
-keyout ./.secure-files/MOK.priv \
-out ./files/base/etc/pki/akmods/certs/akmods-wunker-bunker.der

23
openssl.cnf Normal file
View File

@@ -0,0 +1,23 @@
# This definition stops the following lines choking if HOME isn't
# defined.
HOME = .
RANDFILE = $ENV::HOME/.rnd
[ req ]
distinguished_name = req_distinguished_name
x509_extensions = v3
string_mask = utf8only
prompt = no
[ req_distinguished_name ]
countryName = US
stateOrProvinceName = NC
0.organizationName = wunker-bunker
commonName = Wunker Bunker
emailAddress = gmpinder@gmail.com
[ v3 ]
subjectKeyIdentifier = hash
authorityKeyIdentifier = keyid:always,issuer
basicConstraints = critical,CA:FALSE
extendedKeyUsage = codeSigning,1.3.6.1.4.1.311.10.3.6
nsComment = "OpenSSL Generated Certificate"

View File

@@ -5,5 +5,7 @@ base-image: quay.io/fedora/fedora-bootc
image-version: 42 image-version: 42
description: The base image of Wunker OS description: The base image of Wunker OS
modules: modules:
- from-file: base/nvidia.yml
- from-file: base/common.yml - from-file: base/common.yml
- from-file: base/cosmic.yml
- from-file: base/nvidia.yml
- from-file: base/post-build.yml

View File

@@ -5,5 +5,6 @@ base-image: quay.io/fedora/fedora-bootc
image-version: 42 image-version: 42
description: The base image of Wunker OS description: The base image of Wunker OS
modules: modules:
- from-file: base/cosmic.yml
- from-file: base/common.yml - from-file: base/common.yml
- from-file: base/cosmic.yml
- from-file: base/post-build.yml

View File

@@ -5,7 +5,7 @@ base-image: quay.io/fedora/fedora-bootc
image-version: 42 image-version: 42
description: The base image of Wunker OS description: The base image of Wunker OS
modules: modules:
- from-file: base/common.yml
- from-file: base/kinoite.yml - from-file: base/kinoite.yml
- from-file: base/nvidia.yml - from-file: base/nvidia.yml
- from-file: base/common.yml - from-file: base/post-build.yml

View File

@@ -5,5 +5,6 @@ base-image: quay.io/fedora/fedora-bootc
image-version: 42 image-version: 42
description: The base image of Wunker OS description: The base image of Wunker OS
modules: modules:
- from-file: base/kinoite.yml
- from-file: base/common.yml - from-file: base/common.yml
- from-file: base/kinoite.yml
- from-file: base/post-build.yml

View File

@@ -1,4 +1,12 @@
---
# yaml-language-server: $schema=https://schema.blue-build.org/module-list-v1.json
modules: modules:
- type: files
files:
- source: bootc-update
destination: /usr/lib/systemd/system
- source: base
destination: /
- type: script - type: script
env: env:
CSFG: /usr/lib/systemd/system-generators/coreos-sulogin-force-generator CSFG: /usr/lib/systemd/system-generators/coreos-sulogin-force-generator
@@ -8,22 +16,13 @@ modules:
# see detail: https://github.com/ublue-os/main/issues/653 # see detail: https://github.com/ublue-os/main/issues/653
- curl -sSLo ${CSFG} https://raw.githubusercontent.com/coreos/fedora-coreos-config/refs/heads/stable/overlay.d/05core/usr/lib/systemd/system-generators/coreos-sulogin-force-generator - curl -sSLo ${CSFG} https://raw.githubusercontent.com/coreos/fedora-coreos-config/refs/heads/stable/overlay.d/05core/usr/lib/systemd/system-generators/coreos-sulogin-force-generator
- chmod +x ${CSFG} - chmod +x ${CSFG}
- type: files - type: dnf
files: install:
- source: bootc-update packages:
destination: /usr/lib/systemd/system - sbsign
- type: systemd - type: systemd
system: system:
masked: masked:
- rpm-ostreed-automatic.timer - rpm-ostreed-automatic.timer
enabled: enabled:
- bootc-fetch-apply-updates.timer - bootc-fetch-apply-updates.timer
- type: copy
src: files/base/usr/share/plymouth
dest: /usr/share/plymouth
# - type: os-release
# properties:
# NAME: WunkerOS
# ID: wunker_os
# PRETTY_NAME: Wunker OS
- from-file: common/post-build.yml

View File

@@ -1,17 +1,20 @@
--- ---
# yaml-language-server: $schema=https://schema.blue-build.org/module-list-v1.json # yaml-language-server: $schema=https://schema.blue-build.org/module-list-v1.json
modules: modules:
- type: dnf
repos:
cleanup: true
nonfree: rpmfusion
install:
packages:
- akmod-nvidia
- type: script - type: script
snippets: env:
- echo "%_with_kmod_nvidia_open 1" > /etc/rpm/macros.nvidia-kmod PUBLIC_KEY_DER_PATH: /etc/pki/akmods/certs/akmods-wunker-bunker.der
- akmods --kernels "$(rpm -q "kernel" --queryformat '%{VERSION}-%{RELEASE}.%{ARCH}')" --rebuild secrets:
- type: file
source: ./.secure-files/MOK.priv
mount:
type: file
destination: /tmp/certs/private_key.priv
scripts:
- installnvidiakmod.sh
- type: script
scripts:
- installnvidiapackages.sh
- type: files - type: files
files: files:
- source: nvidia-kargs - source: nvidia-kargs

View File

@@ -0,0 +1,18 @@
---
# yaml-language-server: $schema=https://schema.blue-build.org/module-list-v1.json
modules:
- type: script
env:
PUBLIC_KEY_DER_PATH: /etc/pki/akmods/certs/akmods-wunker-bunker.der
secrets:
- type: file
source: ./.secure-files/MOK.priv
mount:
type: file
destination: /tmp/certs/private_key.priv
scripts:
- signkernel.sh
- type: initramfs
env:
DRACUT_NO_XATTR: '1'
source: local