Skip to content

Commit d37c8cf

Browse files
committed
Custom signing key for precompiled drivers on RHEL
This change adds the opportunity to use trusted signing key, instead of a self-signed key generated on the fly for every build. This is required to let users leverage their own key for Secure Boot. The addition of the public certificate to the authorized signatures database remains the responsibility of the user. Signed-off-by: Fabien Dupont <fdupont@redhat.com>
1 parent 79f178d commit d37c8cf

File tree

4 files changed

+49
-13
lines changed

4 files changed

+49
-13
lines changed

rhel8/precompiled/Dockerfile

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ RUN useradd -u 1001 -m -s /bin/bash builder
1616
USER builder
1717

1818
WORKDIR /home/builder
19-
COPY --chown=1001:0 x509-configuration.ini x509-configuration.ini
19+
COPY --chown=1001:0 x509-configuration.ini private_key.priv* public_key.der* /home/builder/
2020

2121
RUN export KVER=$(echo ${KERNEL_VERSION} | cut -d '-' -f 1) \
2222
TARGET_ARCH=${KERNEL_VERSION##*.} \
@@ -33,11 +33,15 @@ RUN export KVER=$(echo ${KERNEL_VERSION} | cut -d '-' -f 1) \
3333
&& mv tmp/kernel nvidia-kmod-${DRIVER_VERSION}-${TARGET_ARCH}/ \
3434
&& tar -cJf SOURCES/nvidia-kmod-${DRIVER_VERSION}-${TARGET_ARCH}.tar.xz nvidia-kmod-${DRIVER_VERSION}-${TARGET_ARCH} \
3535
&& mv kmod-nvidia.spec SPECS/ \
36-
&& sed -i -e "s/\$USER/${BUILDER_USER}/" -e "s/\$EMAIL/${BUILDER_EMAIL}/" ${HOME}/x509-configuration.ini \
37-
&& openssl req -x509 -new -nodes -utf8 -sha256 -days 36500 -batch \
38-
-config ${HOME}/x509-configuration.ini \
39-
-outform DER -out SOURCES/public_key.der \
40-
-keyout SOURCES/private_key.priv \
36+
&& if test -f "/home/builder/private_key.priv" -a -f "/home/builder/public_key.der" ; then \
37+
mv /home/builder/private_key.priv /home/builder/public_key.der SOURCES ; \
38+
else \
39+
sed -i -e "s/\$USER/${BUILDER_USER}/" -e "s/\$EMAIL/${BUILDER_EMAIL}/" ${HOME}/x509-configuration.ini ; \
40+
openssl req -x509 -new -nodes -utf8 -sha256 -days 36500 -batch \
41+
-config ${HOME}/x509-configuration.ini \
42+
-outform DER -out SOURCES/public_key.der \
43+
-keyout SOURCES/private_key.priv ; \
44+
fi \
4145
&& rpmbuild \
4246
--define "%_topdir $(pwd)" \
4347
--define "debug_package %{nil}" \

rhel8/precompiled/README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,21 @@ The procedure is based on [building custom kmod packages](https://github.com/NVI
3636
...
3737
```
3838
39-
5. Set environment variables, build and push the image:
39+
5. [Optional] Use custom signing keys
40+
41+
By default, the build process generates self-signed key and certificate,
42+
because the spec file expects them during the build. It uses the
43+
`x509-configuration.ini` file to set the OpenSSL configuration. However,
44+
for Secure Boot, it is recommended to use signing keys that are trusted by
45+
the machines, i.e. that are part of the authorized keys database.
46+
47+
To pass custom signing key and certificate during the build, you can put
48+
them in the current folder as `private_key.priv` for the private key and
49+
`public_key.der` for the public certificate in DER format. The build process
50+
will use them if they are present, and fallback to self-signed certificate
51+
otherwise.
52+
53+
6. Set environment variables, build and push the image:
4054
4155
```
4256
export RHSM_ORG_FILE=$HOME/rhsm_org

rhel9/precompiled/Dockerfile

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ RUN useradd -u 1001 -m -s /bin/bash builder
2626
USER builder
2727

2828
WORKDIR /home/builder
29-
COPY --chown=1001:0 x509-configuration.ini x509-configuration.ini
29+
COPY --chown=1001:0 x509-configuration.ini private_key.priv* public_key.der* /home/builder/
3030

3131
RUN export KVER=$(echo ${KERNEL_VERSION} | cut -d '-' -f 1) \
3232
KREL=$(echo ${KERNEL_VERSION} | cut -d '-' -f 2 | sed 's/\.el._.\..\+$//') \
@@ -48,11 +48,15 @@ RUN export KVER=$(echo ${KERNEL_VERSION} | cut -d '-' -f 1) \
4848
fi \
4949
&& tar -cJf SOURCES/nvidia-kmod-${DRIVER_VERSION}-${BUILD_ARCH}.tar.xz nvidia-kmod-${DRIVER_VERSION}-${BUILD_ARCH} \
5050
&& mv kmod-nvidia.spec SPECS/ \
51-
&& sed -i -e "s/\$USER/${BUILDER_USER}/" -e "s/\$EMAIL/${BUILDER_EMAIL}/" ${HOME}/x509-configuration.ini \
52-
&& openssl req -x509 -new -nodes -utf8 -sha256 -days 36500 -batch \
53-
-config ${HOME}/x509-configuration.ini \
54-
-outform DER -out SOURCES/public_key.der \
55-
-keyout SOURCES/private_key.priv \
51+
&& if test -f "/home/builder/private_key.priv" -a -f "/home/builder/public_key.der" ; then \
52+
mv /home/builder/private_key.priv /home/builder/public_key.der SOURCES ; \
53+
else \
54+
sed -i -e "s/\$USER/${BUILDER_USER}/" -e "s/\$EMAIL/${BUILDER_EMAIL}/" ${HOME}/x509-configuration.ini ; \
55+
openssl req -x509 -new -nodes -utf8 -sha256 -days 36500 -batch \
56+
-config ${HOME}/x509-configuration.ini \
57+
-outform DER -out SOURCES/public_key.der \
58+
-keyout SOURCES/private_key.priv ; \
59+
fi \
5660
&& rpmbuild \
5761
--define "% _arch ${BUILD_ARCH}" \
5862
--define "%_topdir $(pwd)" \

rhel9/precompiled/README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,20 @@ The procedure is based on [building custom kmod packages](https://github.com/NVI
108108
export DRIVER_VERSION=550.163.01
109109
```
110110

111+
6. [Optional] Use custom signing keys
112+
113+
By default, the build process generates self-signed key and certificate,
114+
because the spec file expects them during the build. It uses the
115+
`x509-configuration.ini` file to set the OpenSSL configuration. However,
116+
for Secure Boot, it is recommended to use signing keys that are trusted by
117+
the machines, i.e. that are part of the authorized keys database.
118+
119+
To pass custom signing key and certificate during the build, you can put
120+
them in the current folder as `private_key.priv` for the private key and
121+
`public_key.der` for the public certificate in DER format. The build process
122+
will use them if they are present, and fallback to self-signed certificate
123+
otherwise.
124+
111125
6. [Optional] Build the vGPU guest driver
112126

113127
To build the vGPU guest driver, set the `DRIVER_TYPE` environment

0 commit comments

Comments
 (0)