Implement kernel signing
This commit is contained in:
58
files/scripts/installnvidiakmod.sh
Normal file
58
files/scripts/installnvidiakmod.sh
Normal 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
|
||||
51
files/scripts/installnvidiapackages.sh
Normal file
51
files/scripts/installnvidiapackages.sh
Normal 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
|
||||
@@ -17,8 +17,7 @@ set -oue pipefail
|
||||
|
||||
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="./certs/public_key.crt"
|
||||
PUBLIC_KEY_CRT_PATH="/tmp/certs/public_key.crt"
|
||||
PRIVATE_KEY_PATH="/tmp/certs/private_key.priv"
|
||||
|
||||
openssl x509 -in "$PUBLIC_KEY_DER_PATH" -out "$PUBLIC_KEY_CRT_PATH"
|
||||
|
||||
@@ -23,13 +23,12 @@ fi
|
||||
|
||||
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="./certs/public_key.crt"
|
||||
PUBLIC_KEY_CRT_PATH="/tmp/certs/public_key.crt"
|
||||
PRIVATE_KEY_PATH="/tmp/certs/private_key.priv"
|
||||
openssl x509 -in "$PUBLIC_KEY_DER_PATH" -out "$PUBLIC_KEY_CRT_PATH"
|
||||
|
||||
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"
|
||||
|
||||
for module in /usr/lib/modules/"${KERNEL_VERSION}"/extra/"${MODULE_NAME}"/*.ko*; do
|
||||
|
||||
Reference in New Issue
Block a user