Skip to content

Commit 749bbb6

Browse files
sacnaikjudyjoseph
authored andcommitted
secureboot: Enable signing SONiC kernel (#10557)
Why I did it To sign SONiC kernel image and allow secure boot based system to verify SONiC image before loading into the system. How I did it Pass following parameter to rules/config.user Ex: SONIC_ENABLE_SECUREBOOT_SIGNATURE := y SIGNING_KEY := /path/to/key/private.key SIGNING_CERT := /path/to/public/public.cert How to verify it Secure boot enabled system enrolled with right public key of the, image in the platform UEFI database will able to verify image before load. Alternatively one can verify with offline sbsign tool as below. export SBSIGN_KEY=/abc/bcd/xyz/ sbverify --cert $SBSIGN_KEY/public_cert.cert fsroot-platform-XYZ/boot/vmlinuz-5.10.0-8-2-amd64 mage O/P: Signature verification OK
1 parent 4280a23 commit 749bbb6

File tree

6 files changed

+41
-0
lines changed

6 files changed

+41
-0
lines changed

Makefile.work

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,17 @@ ifneq ($(SONIC_DPKG_CACHE_SOURCE),)
188188
DOCKER_RUN += -v "$(SONIC_DPKG_CACHE_SOURCE):/dpkg_cache:rw"
189189
endif
190190

191+
ifeq ($(SONIC_ENABLE_SECUREBOOT_SIGNATURE), y)
192+
ifneq ($(SIGNING_KEY),)
193+
DOCKER_SIGNING_SOURCE := $(shell dirname $(SIGNING_KEY))
194+
DOCKER_RUN += -v "$(DOCKER_SIGNING_SOURCE):$(DOCKER_SIGNING_SOURCE):ro"
195+
endif
196+
ifneq ($(SIGNING_CERT),)
197+
DOCKER_SIGNING_SOURCE := $(shell dirname $(SIGNING_CERT))
198+
DOCKER_RUN += -v "$(DOCKER_SIGNING_SOURCE):$(DOCKER_SIGNING_SOURCE):ro"
199+
endif
200+
endif
201+
191202
ifeq ($(SONIC_CONFIG_USE_NATIVE_DOCKERD_FOR_BUILD), y)
192203
ifneq ($(MULTIARCH_QEMU_ENVIRON), y)
193204
DOCKER_RUN += -v /var/run/docker.sock:/var/run/docker.sock
@@ -290,6 +301,7 @@ SONIC_BUILD_INSTRUCTION := make \
290301
EXTRA_DOCKER_TARGETS=$(EXTRA_DOCKER_TARGETS) \
291302
BUILD_LOG_TIMESTAMP=$(BUILD_LOG_TIMESTAMP) \
292303
SONIC_ENABLE_IMAGE_SIGNATURE=$(ENABLE_IMAGE_SIGNATURE) \
304+
SONIC_ENABLE_SECUREBOOT_SIGNATURE=$(SONIC_ENABLE_SECUREBOOT_SIGNATURE) \
293305
SONIC_DEFAULT_CONTAINER_REGISTRY=$(DEFAULT_CONTAINER_REGISTRY) \
294306
ENABLE_HOST_SERVICE_ON_START=$(ENABLE_HOST_SERVICE_ON_START) \
295307
SLAVE_DIR=$(SLAVE_DIR) \

build_debian.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,23 @@ if [[ $CONFIGURED_ARCH == amd64 ]]; then
143143
sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y install dmidecode hdparm
144144
fi
145145

146+
## Sign the Linux kernel
147+
if [ "$SONIC_ENABLE_SECUREBOOT_SIGNATURE" = "y" ]; then
148+
if [ ! -f $SIGNING_KEY ]; then
149+
echo "Error: SONiC linux kernel signing key missing"
150+
exit 1
151+
fi
152+
if [ ! -f $SIGNING_CERT ]; then
153+
echo "Error: SONiC linux kernel signing certificate missing"
154+
exit 1
155+
fi
156+
157+
echo '[INFO] Signing SONiC linux kernel image'
158+
K=$FILESYSTEM_ROOT/boot/vmlinuz-${LINUX_KERNEL_VERSION}-amd64
159+
sbsign --key $SIGNING_KEY --cert $SIGNING_CERT --output /tmp/${K##*/} ${K}
160+
sudo cp -f /tmp/${K##*/} ${K}
161+
fi
162+
146163
## Update initramfs for booting with squashfs+overlay
147164
cat files/initramfs-tools/modules | sudo tee -a $FILESYSTEM_ROOT/etc/initramfs-tools/modules > /dev/null
148165

rules/config

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,13 @@ K8s_GCR_IO_PAUSE_VERSION = 3.4.1
180180
# The relative path is build root folder.
181181
SONIC_ENABLE_IMAGE_SIGNATURE ?= n
182182

183+
# SONIC_ENABLE_SECUREBOOT_SIGNATURE - enable SONiC kernel signing to support UEFI secureboot
184+
# To support UEFI secureboot chain of trust requires EFI kernel to be signed as a PE binary
185+
# SIGNING_KEY =
186+
# SIGNING_CERT =
187+
# The absolute path should be provided.
188+
SONIC_ENABLE_SECUREBOOT_SIGNATURE ?= n
189+
183190
# PACKAGE_URL_PREFIX - the package url prefix
184191
PACKAGE_URL_PREFIX ?= https://packages.trafficmanager.net/public/packages
185192

slave.mk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,9 @@ $(addprefix $(TARGET_PATH)/, $(SONIC_INSTALLERS)) : $(TARGET_PATH)/% : \
11671167
TARGET_PATH=$(TARGET_PATH) \
11681168
SONIC_ENFORCE_VERSIONS=$(SONIC_ENFORCE_VERSIONS) \
11691169
TRUSTED_GPG_URLS=$(TRUSTED_GPG_URLS) \
1170+
SONIC_ENABLE_SECUREBOOT_SIGNATURE="$(SONIC_ENABLE_SECUREBOOT_SIGNATURE)" \
1171+
SIGNING_KEY="$(SIGNING_KEY)" \
1172+
SIGNING_CERT="$(SIGNING_CERT)" \
11701173
PACKAGE_URL_PREFIX=$(PACKAGE_URL_PREFIX) \
11711174
MULTIARCH_QEMU_ENVIRON=$(MULTIARCH_QEMU_ENVIRON) \
11721175
./build_debian.sh $(LOG)

sonic-slave-bullseye/Dockerfile.j2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ RUN apt-get update && apt-get install -y \
118118
devscripts \
119119
quilt \
120120
stgit \
121+
sbsigntool \
121122
# For platform-modules build
122123
module-assistant \
123124
# For thrift build\

sonic-slave-buster/Dockerfile.j2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ RUN apt-get update && apt-get install -y \
125125
devscripts \
126126
quilt \
127127
stgit \
128+
sbsigntool \
128129
# For platform-modules build
129130
module-assistant \
130131
# For thrift build\

0 commit comments

Comments
 (0)