secureboot.eclass

Name

secureboot.eclass — A small eclass to sign efi files for Secure Boot

Description

Eclass for packages that install .efi files. A use flag and two user variables allow signing these .efi files for use on systems with Secure Boot enabled.

Signing the files during emerge ensures that any tooling that actually installs the bootloaders and kernels to ESP always uses a signed version. This prevents Secure Boot from accidentally breaking when upgrading the kernel or the bootloader.

Example use

src_install() {
      default
      secureboot_sign_efi_file in.efi out.efi.signed
}

Or

src_install() {

default secureboot_auto_sign

}

Some tools will automatically detect and use EFI executables with the .signed suffix. For tools that do not do this the --in-place argument for secureboot_auto_sign can be used to ensure that the signed version is used.

Supported EAPIs

7 8

Exported Phases

  • pkg_setup

Functions

secureboot_pkg_setup

Checks if required user variables are set before starting the build

secureboot_sign_efi_file <input file> [<output file>]

Sign a file using sbsign and the requested key/certificate. If the file is already signed with our key then the file is skipped. If no output file is specified the output file will be the same as the input file, i.e. the file will be overwritten.

secureboot_auto_sign [--in-place]

Automatically discover and sign efi files in the image directory.

By default signed files gain the .signed suffix. If the --in-place argument is given the efi files are replaced with a signed version in place.

Variables

SECUREBOOT_SIGN_CERT (user variable)

Used with USE=secureboot. Should be set to the path of the public key certificate in PEM format to use. If unspecified the SECUREBOOT_SIGN_KEY is assumed to also contain the certificate belonging to it.

SECUREBOOT_SIGN_KEY (user variable)

Used with USE=secureboot. Should be set to the path of the private key in PEM format to use, or a PKCS#11 URI. With OpenSSL 4, PKCS#11 URIs require dev-libs/pkcs11-provider. If unspecified the following locations are tried in order: - /etc/portage/secureboot.pem - /var/lib/sbctl/keys/db/db.{key,pem} (from app-crypt/sbctl) - the MODULES_SIGN_KEY (and MODULES_SIGN_CERT if set) - the contents of CONFIG_MODULE_SIG_KEY in the current kernel If none of these exist, a new key will be generated at /etc/portage/secureboot.pem.

SECUREBOOT_SIGN_TOOL ?= sbsign (user variable)

Used with USE=secureboot. May be set to a signing tool to use when signing EFI files.

Valid values: sbsign,systemd-sbsign

Default if unset: sbsign

SECUREBOOT_SIGN_GNUPGHOME ?= ${MODULES_SIGN_GNUPGHOME} (user variable)

Used with USE=secureboot and a PKCS#11 SECUREBOOT_SIGN_KEY provided by a module that talks to gpg-agent, such as app-crypt/scute. Can be set to the GnuPG home directory of a gpg-agent that the user started before the build. The agent keeps the token unlocked, so the PIN is only entered once instead of once per signing process.

The eclass exports it as GNUPGHOME and allows writes to it in the sandbox. Signing in pkg_setup and src_install runs as root, so the agent must be reachable for root, either by running it as root with this home directory, or via an Assuan socket redirection file named S.gpg-agent in this directory. kernel-build.eclass also signs the in-tree modules in src_test, which runs as the portage user with FEATURES=userpriv; the agent must then be reachable for that user too, and the directory writable by it, as gpgsm takes lock files there.

While the token is unlocked, any process that can reach the agent can sign without entering the PIN. scute also sends "SCD LEARN --force" to the agent, which may rewrite the agent's card stubs, so a dedicated agent is preferable to the user's own one.

Default if unset: MODULES_SIGN_GNUPGHOME

Authors

Author: Nowa Ammerlaan <nowa@gentoo.org>

Maintainers

Nowa Ammerlaan <nowa@gentoo.org>

Reporting Bugs

Please report bugs via https://bugs.gentoo.org/