-
Notifications
You must be signed in to change notification settings - Fork 67
Rework handling of the Secure Boot keys and certificates #3044
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,44 +3,23 @@ | |
# found in the LICENSE file. | ||
|
||
if [[ ${COREOS_OFFICIAL:-0} -ne 1 ]]; then | ||
SBSIGN_KEY="/usr/share/sb_keys/shim.key" | ||
SBSIGN_CERT="/usr/share/sb_keys/shim.pem" | ||
SBSIGN_KEY="/usr/share/sb_keys/unofficial/shim.key" | ||
SBSIGN_CERT="/usr/share/sb_keys/unofficial/shim.pem" | ||
else | ||
SBSIGN_KEY="pkcs11:token=flatcar-sb-dev-hsm-sign-2025" | ||
unset SBSIGN_CERT | ||
SBSIGN_CERT="/usr/share/sb_keys/official/signing.pem" | ||
fi | ||
|
||
PKCS11_MODULE_PATH="/usr/$(get_sdk_libdir)/pkcs11/azure-keyvault-pkcs11.so" | ||
PKCS11_MODULE_PATH="$(pkg-config p11-kit-1 --variable p11_module_path)/azure-keyvault-pkcs11.so" | ||
|
||
PKCS11_ENV=( | ||
AZURE_CORE_COLLECT_TELEMETRY=no | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should leave this at the default, though you may want to provide an option for rebuilders to easily override. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I figured the telemetry might not be that useful when it is coming from an ephemeral container, but I don't feel strongly about it. |
||
AZURE_KEYVAULT_URL="https://flatcar-sb-dev-kv.vault.azure.net/" | ||
PKCS11_MODULE_PATH="${PKCS11_MODULE_PATH}" | ||
AZURE_KEYVAULT_PKCS11_DEBUG=1 | ||
) | ||
|
||
get_sbsign_cert() { | ||
if [[ ${SBSIGN_KEY} != pkcs11:* || -s ${SBSIGN_CERT-} ]]; then | ||
return | ||
fi | ||
|
||
SBSIGN_CERT=$(mktemp -t signing-cert.XXXXXXXXXX.pem) | ||
info "Fetching ${SBSIGN_KEY} from Azure" | ||
|
||
# Needs Key Vault Reader role. | ||
env "${PKCS11_ENV[@]}" p11-kit export-object \ | ||
--provider "${PKCS11_MODULE_PATH}" \ | ||
"${SBSIGN_KEY};type=cert" \ | ||
| tee "${SBSIGN_CERT}" | ||
} | ||
|
||
cleanup_sbsign_certs() { | ||
if [[ ${SBSIGN_CERT-} == "${TMPDIR-/tmp}"/* ]]; then | ||
rm -f -- "${SBSIGN_CERT}" | ||
fi | ||
} | ||
|
||
do_sbsign() { | ||
get_sbsign_cert | ||
info "Signing ${@:$#} with ${SBSIGN_KEY}" | ||
|
||
if [[ ${SBSIGN_KEY} == pkcs11:* ]]; then | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Copyright (c) 2015 CoreOS Inc. | ||
# Copyright (c) 2024 The Flatcar Maintainers. | ||
# Distributed under the terms of the GNU General Public License v2 | ||
|
||
EAPI=8 | ||
|
||
DESCRIPTION="Flatcar Secure Boot keys" | ||
HOMEPAGE="https://www.flatcar.org/" | ||
S="${WORKDIR}" | ||
|
||
LICENSE="BSD" | ||
SLOT="0" | ||
KEYWORDS="amd64 arm64" | ||
|
||
BDEPEND=" | ||
app-emulation/virt-firmware | ||
dev-libs/openssl | ||
" | ||
|
||
# Arbitrary value created for Flatcar. | ||
OWNER_GUID="4a974879-bf65-4eb8-b404-ac3a6141121e" | ||
|
||
src_compile() { | ||
local TYPE | ||
for TYPE in unofficial official; do | ||
mkdir "${TYPE}" || die | ||
|
||
# Gather all the shim vendor PEM certs into an array. | ||
local FILES=( "${FILESDIR}/${TYPE}"/shim-*.pem ) | ||
|
||
# Rewrite the newest shim vendor PEM cert in a consistent PEM format, | ||
# checking its validity. Only the newest is needed in PEM format for | ||
# inserting into the kernel to verify the verity root hash at boot time. | ||
openssl x509 -in "${FILES[-1]}" -inform PEM -out "${TYPE}"/shim.pem || die | ||
|
||
local ARGS=() FILE | ||
for FILE in "${FILES[@]}"; do | ||
# Add each shim vendor PEM cert to the DER ESL creation below. | ||
ARGS+=( --add-cert "${OWNER_GUID}" "${FILE}" ) | ||
done | ||
|
||
# This ingests shim vendor PEM certs and outputs a combined DER ESL. | ||
virt-fw-sigdb "${ARGS[@]}" --output "${TYPE}"/shim.esl || die | ||
done | ||
|
||
# Rewrite the official signing PEM cert in a consistent PEM format, checking | ||
# its validity. Only the newest is needed in PEM format to sign the | ||
# bootloader and the kernel image. Unofficial builds are already covered | ||
# above because the shim vendor cert /is/ the signing cert, not a CA. | ||
openssl x509 -in "${FILESDIR}"/official/signing.pem -inform PEM -out official/signing.pem || die | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This certificate is only needed during signing - storing it in the repo means we need to update more places. Fetching it from Keyvault when signing seems like the better choice. |
||
} | ||
|
||
src_install() { | ||
insinto /usr/share/sb_keys | ||
newins - owner.txt <<< "${OWNER_GUID}" | ||
doins -r unofficial official | ||
|
||
insinto /usr/share/sb_keys/unofficial | ||
doins "${FILESDIR}"/unofficial/{DB.{key,pem},shim.key} | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the current solution was a stop-gap solution, my intention was to keep the name as development. Going foward, I'll post the metadata to be used and once vouched for, I'll proceed. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIIDaDCCAlCgAwIBAgIRAINN27bWbE7vq1xOCROIuyM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nqQZsZD+Ugp7iMB3JV9xC01JNWMuMlGoeI1F6orssR6jU3aCjk | ||
jZjSnyqDINcqddkevpYWg+ffvg3ewQ4lMcFPwjGDxqPOCPZmAw/l7xd6LqFTq//C | ||
iAQ/ssvyzfqSgqWN | ||
-----END CERTIFICATE----- |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIIELTCCAxWgAwIBAgICCSkwDQYJKoZIhvcNAQELBQAwPTE7MDkGA1UEAxMyRmxh | ||
dGNhciBDb250YWluZXIgTGludXggU2VjdXJlIEJvb3QgRGV2ZWxvcG1lbnQgQ0Ew | ||
HhcNMjUwMzIwMTE0ODIyWhcNMjgwMzIwMTE0ODIyWjBCMUAwPgYDVQQDEzdGbGF0 | ||
Y2FyIENvbnRhaW5lciBMaW51eCBTZWN1cmUgQm9vdCBEZXZlbG9wbWVudCBTaWdu | ||
aW5nMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAgEAi4DQeJdbATc+6bXu | ||
fC45iOj+fuA9p/L7WvY0FoT4ohmynoaYgBzUXMV333H7Pzy1qknZ1Kz8A8c8nlp0 | ||
BQOr0cnvoJhPt2lOP7EofCdylOBOfWPqP9l73pATp2/jJnUi+288eSTHBX6GgLqk | ||
PYceTjIxQWP6OzjP94ZCOBQnB6Ib4TaMbuylkz7vrog1JMPoGOdrSmZvaWqHebx5 | ||
GaPwNOQzJAw6d4rFrphqso51r/Q4vxps+fMQZoJAMP4xT1SCIQO1kFt+3Q6MFi3m | ||
ztte5Y/Q46IvKEZaWU8K5umFnBaOWCDeFelV268TsvyrBBrCBB4Q5ooo2NiZESh4 | ||
7fS1lT3Jcr8Unw3b2E91Y/hmGRDwrC+yp+7f51gRC3UIP5AsF1oX/nF+kD+mrhhg | ||
3gPtCXdx88ttaJBdOCMfdgoONvY8Yl1WlbjbC5pCEMK3/gV5SGCbvlAaqBkh6gvY | ||
dsFKMCbSHg/eD6PS3bgRtfcb1jCsIXGrzJRVi/Fgu0u9D9UylNkGkrvHQ0r1ffKM | ||
O7hlgooo9SLloU+4MLMHCujOQo978XIdsYy2DCiRQdD33LXEgQMGEcZvENIXkmFU | ||
Iujq32PMKc31P84JPGzyeUN3VkdUPww4HRwEcsfUFJ8b4xEEmAUi/+zqz5XCo3m1 | ||
nh62zX/ByIyCmY56rgWFWmSON4UCAwEAAaMyMDAwCQYDVR0TBAIwADATBgNVHSUE | ||
DDAKBggrBgEFBQcDAzAOBgNVHQ8BAf8EBAMCBaAwDQYJKoZIhvcNAQELBQADggEB | ||
AGKZATREaf6bdjfYmrM0cKwlPcd9Bo95gX/uucRzLmAvgo5KftgFABhqNxQeb6g2 | ||
mkz9EKCtYt8WPH7j914yXQLLes/nrqARPIV2n0IP5SxRDmDxhSl3jhStp97idGvv | ||
zS07tM7oHqPycwitfrJl0kbrIYXr5f2PyG2kANjPgoYHcl5KLnffv95XSokNhWFK | ||
17asGpHUrtOlOJm1mCgjpmiotYgMIGtKFMiKB8yFQRFRnyMb7uowkq/G9btDjW/7 | ||
kVJwppmwXXL5qiAAzvFQcbBbWmiIwVXjb8OLO43dsB0znt+IMDf7itUiUCLSOjqQ | ||
z3S4t9QNWU6jp0RBwEQfI6g= | ||
-----END CERTIFICATE----- |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Copyright 2015 CoreOS, Inc. | ||
# Distributed under the terms of the GNU General Public License v2 | ||
|
||
EAPI=8 | ||
|
||
DESCRIPTION="UEFI Shim loader" | ||
HOMEPAGE="https://github.com/rhboot/shim" | ||
SRC_URI="https://github.com/rhboot/shim/releases/download/${PV}/shim-${PV}.tar.bz2" | ||
KEYWORDS="amd64 arm64" | ||
|
||
LICENSE="BSD" | ||
SLOT="0" | ||
IUSE="official" | ||
|
||
# TODO: Would be ideal to depend on sys-boot/gnu-efi package, but | ||
# currently the shim insists on using the bundled copy. This will need | ||
# to be addressed by patching this check out after making sure that | ||
# our copy of gnu-efi is as usable as the bundled one. | ||
DEPEND=" | ||
dev-libs/openssl | ||
" | ||
BDEPEND=" | ||
coreos-base/coreos-sb-keys | ||
" | ||
|
||
PATCHES=( | ||
"${FILESDIR}/0001-Fix-parallel-build-of-gnu-efi.patch" | ||
) | ||
|
||
src_compile() { | ||
sed -e "s/@@VERSION@@/${PVR}/" "${FILESDIR}"/sbat.csv.in >"${WORKDIR}/sbat.csv" || die | ||
|
||
unset ARCH | ||
emake \ | ||
CROSS_COMPILE="${CHOST}-" \ | ||
ENABLE_SBSIGN=1 \ | ||
SBATPATH="${WORKDIR}"/sbat.csv \ | ||
VENDOR_DB_FILE="${BROOT}"/usr/share/sb_keys/$(usex official official unofficial)/shim.esl | ||
} | ||
|
||
src_install() { | ||
insinto /usr/lib/shim | ||
doins shim?*.efi mm?*.efi | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we can fetch it from Keyvault on demand, and this certificate is needed while signing, why store it in the repo. Better keep the way it's done.