-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor SB signing code and sign official builds with Azure Key Vault
Signed-off-by: James Le Cuirot <jlecuirot@microsoft.com>
- Loading branch information
Showing
3 changed files
with
110 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Copyright (c) 2024 The Flatcar Maintainers. | ||
# Use of this source code is governed by a BSD-style license that can be | ||
# 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" | ||
else | ||
SBSIGN_KEY="pkcs11:token=flatcar-dev-cert" | ||
unset SBSIGN_CERT | ||
fi | ||
|
||
PKCS11_MODULE_PATH="/usr/$(get_sdk_libdir)/pkcs11/azure_kms_pkcs11.so" | ||
|
||
PKCS11_ENV=( | ||
AZURE_KEYVAULT_URL="https://chewi-test.vault.azure.net/" | ||
PKCS11_MODULE_PATH="${PKCS11_MODULE_PATH}" | ||
AWS_KMS_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 | ||
set -- --engine pkcs11 "${@}" | ||
fi | ||
|
||
# Needs Key Vault Crypto User role. | ||
sudo env "${PKCS11_ENV[@]}" sbsign \ | ||
--key "${SBSIGN_KEY}" \ | ||
--cert "${SBSIGN_CERT}" \ | ||
"${@}" | ||
} |