Article View: linux.gentoo.dev
Article #239[gentoo-dev] [PATCH 5/6] {secureboot,kernel-build,linux-mod-r1}.eclass: add *_SIGN_GNUPGHOME
From: David Seifert
Date: Tue, 01 Dec 2026 16:00
Date: Tue, 01 Dec 2026 16:00
157 lines
7583 bytes
7583 bytes
Let a pre-started gpg-agent, e.g. used via app-crypt/scute, keep a token
unlocked across all signing processes of a build, so the PIN only has
to be entered once.
Signed-off-by: David Seifert <soap@gentoo.org>
---
eclass/kernel-build.eclass | 20 +++++++++++++++++
eclass/linux-mod-r1.eclass | 17 ++++++++++++++
eclass/secureboot.eclass | 46 ++++++++++++++++++++++++++++++++++++++
3 files changed, 83 insertions(+)
diff --git a/eclass/kernel-build.eclass b/eclass/kernel-build.eclass
index 4400fcc9754b2..41777d0fc1c5a 100644
--- a/eclass/kernel-build.eclass
+++ b/eclass/kernel-build.eclass
@@ -150,6 +150,18 @@ REQUIRED_USE="secureboot? ( modules-sign )"
# MOK. With USE=secureboot, also set SECUREBOOT_SIGN_KEY, as the
# discarded key cannot serve as the Secure Boot signing key fallback.
+# @ECLASS_VARIABLE: MODULES_SIGN_GNUPGHOME
+# @USER_VARIABLE
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# Used with USE=modules-sign and a PKCS#11 MODULES_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 an already running gpg-agent, see
+# SECUREBOOT_SIGN_GNUPGHOME in secureboot.eclass for details.
+#
+# With USE=secureboot, it must match SECUREBOOT_SIGN_GNUPGHOME, as the
+# modules and the EFI images are signed in the same phase.
+
# @ECLASS_VARIABLE: KERNEL_GENERIC_UKI_CMDLINE
# @USER_VARIABLE
# @DESCRIPTION:
@@ -182,6 +194,14 @@ kernel-build_pkg_setup() {
secureboot_pkg_setup
if use modules-sign && [[ -n ${MODULES_SIGN_KEY} ]]; then
+ # GNUPGHOME is a single environment variable
+ if use secureboot && [[ -n ${MODULES_SIGN_GNUPGHOME} &&
+ ${MODULES_SIGN_GNUPGHOME} != "${SECUREBOOT_SIGN_GNUPGHOME}" ]]
+ then
+ die "MODULES_SIGN_GNUPGHOME and SECUREBOOT_SIGN_GNUPGHOME must match with USE=secureboot"
+ fi
+ _secureboot_setup_gnupghome MODULES_SIGN_GNUPGHOME
+
# Sanity check: fail early if key/cert in DER format or does not exist.
# If no cert specified, we assume the pem key also contains the cert
_secureboot_check_keypair "${MODULES_SIGN_KEY}" "${MODULES_SIGN_CERT:-${MODULES_SIGN_KEY}}" ||
diff --git a/eclass/linux-mod-r1.eclass b/eclass/linux-mod-r1.eclass
index 247739b951989..5049b90ac7b68 100644
--- a/eclass/linux-mod-r1.eclass
+++ b/eclass/linux-mod-r1.eclass
@@ -249,6 +249,15 @@ fi
# relative to the kernel build directory being used.
: "${MODULES_SIGN_CERT:=certs/signing_key.x509}"
+# @ECLASS_VARIABLE: MODULES_SIGN_GNUPGHOME
+# @USER_VARIABLE
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# Used with USE=modules-sign and a PKCS#11 MODULES_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 an already running gpg-agent, see
+# SECUREBOOT_SIGN_GNUPGHOME in secureboot.eclass for details.
+
# @ECLASS_VARIABLE: MODULES_KERNEL_MAX
# @DEFAULT_UNSET
# @DESCRIPTION:
@@ -783,6 +792,14 @@ _modules_prepare_sign() {
_modules_sign_die "the private key '${MODULES_SIGN_KEY}' was not found"
[[ -f ${MODULES_SIGN_CERT} ]] ||
_modules_sign_die "the public key certificate '${MODULES_SIGN_CERT}' was not found"
+
+ if [[ -n ${MODULES_SIGN_GNUPGHOME} ]]; then
+ [[ -d ${MODULES_SIGN_GNUPGHOME} ]] ||
+ _modules_sign_die "MODULES_SIGN_GNUPGHOME '${MODULES_SIGN_GNUPGHOME}' is not a directory"
+ export GNUPGHOME=${MODULES_SIGN_GNUPGHOME}
+ # gpgsm takes lock files there; carried over into later phases
+ addwrite "${GNUPGHOME}"
+ fi
}
# @FUNCTION: _modules_prepare_toolchain
diff --git a/eclass/secureboot.eclass b/eclass/secureboot.eclass
index 91c3b4f99b4e5..5f0f6ac6ccf09 100644
--- a/eclass/secureboot.eclass
+++ b/eclass/secureboot.eclass
@@ -86,6 +86,34 @@ BDEPEND="
# Default if unset: sbsign
: "${SECUREBOOT_SIGN_TOOL:=sbsign}"
+# @ECLASS_VARIABLE: SECUREBOOT_SIGN_GNUPGHOME
+# @USER_VARIABLE
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# 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
+: "${SECUREBOOT_SIGN_GNUPGHOME:=${MODULES_SIGN_GNUPGHOME}}"
+
if [[ -z ${_SECUREBOOT_ECLASS} ]]; then
_SECUREBOOT_ECLASS=1
@@ -126,6 +154,22 @@ _secureboot_check_keypair() {
[[ ${key_pub} == "${cert_pub}" ]]
}
+# @FUNCTION: _secureboot_setup_gnupghome
+# @USAGE: <variable name>
+# @INTERNAL
+# @DESCRIPTION:
+# If the named variable is set, export its value as GNUPGHOME and allow
+# writes to it in the sandbox, see SECUREBOOT_SIGN_GNUPGHOME.
+_secureboot_setup_gnupghome() {
+ local var=${1}
+ [[ -n ${!var} ]] || return 0
+
+ [[ -d ${!var} ]] || die "${var}=${!var} is not a directory"
+ export GNUPGHOME=${!var}
+ # gpgsm takes lock files there; carried over into later phases
+ addwrite "${GNUPGHOME}"
+}
+
# @FUNCTION: secureboot_pkg_setup
# @DESCRIPTION:
# Checks if required user variables are set before starting the build
@@ -136,6 +180,8 @@ secureboot_pkg_setup() {
# If we are merging a binary then the files in this binary
# are already signed, no need to check the variables.
if [[ ${MERGE_TYPE} != binary ]]; then
+ _secureboot_setup_gnupghome SECUREBOOT_SIGN_GNUPGHOME
+
if [[ -z ${SECUREBOOT_SIGN_KEY} ]]; then
# No key specified, try some usual suspects
linux-info_pkg_setup
--
2.56.1
Technical Details
Message-ID:
<O5yqR-fmyc-19@gated-at.bofh.it>Path:
mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.samoylyk.net!gothmog.csi.it!bofh.it!news.nic.it!robomodReferences:
<O5yqR-fmyc-3@gated-at.bofh.it>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!newsfeed.bofh.team!news.samoylyk.net!gothmog.csi.it!bofh.it!news.nic.it!robomod
From: David Seifert <soap@gentoo.org>
Newsgroups: linux.gentoo.dev
Subject: [gentoo-dev] [PATCH 5/6] {secureboot,kernel-build,linux-mod-r1}.eclass: add *_SIGN_GNUPGHOME
Date: Tue, 01 Dec 2026 17:00:01 +0100
Message-ID: <O5yqR-fmyc-19@gated-at.bofh.it>
References: <O5yqR-fmyc-3@gated-at.bofh.it>
X-Original-To: gentoo-dev@lists.gentoo.org
X-Mailer: git-send-email 2.56.1
List-ID: Gentoo Linux mail <gentoo-dev.gentoo.org>
Reply-To: gentoo-dev@lists.gentoo.org
X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Approved: robomod@news.nic.it
Lines: 157
Organization: linux.* mail to news gateway
Sender: robomod@news.nic.it
X-Original-Cc: David Seifert <soap@gentoo.org>
X-Original-Date: Tue, 1 Dec 2026 16:49:23 +0100
X-Original-Message-ID: <20261201154924.70252-5-soap@gentoo.org>
X-Original-References: <20261201154924.70252-1-soap@gentoo.org>