Skip to content

Commit 782f2cf

Browse files
committed
fix(ci): preset GPG passphrase for non-interactive signing
- Configure gpg-agent with allow-preset-passphrase - Preset GPG_PASSPHRASE for all secret keygrips after import - Add GPG_PASSPHRASE secret to release workflow env
1 parent 448ec6c commit 782f2cf

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

.github/workflows/release.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ jobs:
7272
if: github.event_name == 'release'
7373
env:
7474
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
75+
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
7576
run: releaser/apt_release.sh ${GITHUB_REF#refs/tags/}
7677

7778
- name: Upload artifacts to release

releaser/apt_release.sh

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,19 @@ if [[ -n "$GPG_PRIVATE_KEY" ]]; then
136136
echo " Using GPG key: $GPG_KEY_ID"
137137

138138
# Configure gpg-agent for non-interactive signing in CI
139+
# GPG 2.x always protects keys via the agent — preset the passphrase so signing doesn't prompt
139140
mkdir -p ~/.gnupg
140-
echo "allow-loopback-pinentry" >> ~/.gnupg/gpg-agent.conf
141+
chmod 700 ~/.gnupg
142+
cat > ~/.gnupg/gpg-agent.conf <<AGENTCONF
143+
allow-loopback-pinentry
144+
allow-preset-passphrase
145+
AGENTCONF
141146
gpg-connect-agent reloadagent /bye 2>/dev/null || true
147+
148+
# Preset passphrase for every secret subkey keygrip
149+
for KEYGRIP in $(gpg --list-secret-keys --with-keygrip --with-colons 2>/dev/null | awk -F: '/^grp/{print $10}'); do
150+
/usr/lib/gnupg/gpg-preset-passphrase --preset --passphrase "$GPG_PASSPHRASE" "$KEYGRIP"
151+
done
142152
else
143153
if [[ "$DRY_RUN" != "true" ]]; then
144154
echo "Error: GPG_PRIVATE_KEY is required for signing (set DRY_RUN=true to skip)"
@@ -218,14 +228,14 @@ cd -
218228
# GPG sign the Release file
219229
if [[ -n "$GPG_KEY_ID" ]]; then
220230
# Detached signature
221-
echo | gpg --batch --yes --armor --pinentry-mode loopback --passphrase-fd 0 \
231+
gpg --batch --yes --armor \
222232
--default-key "$GPG_KEY_ID" \
223233
--detach-sign \
224234
--output "$APT_DIR/dists/stable/Release.gpg" \
225235
"$APT_DIR/dists/stable/Release"
226236

227237
# Inline signature (InRelease)
228-
echo | gpg --batch --yes --armor --pinentry-mode loopback --passphrase-fd 0 \
238+
gpg --batch --yes --armor \
229239
--default-key "$GPG_KEY_ID" \
230240
--clearsign \
231241
--output "$APT_DIR/dists/stable/InRelease" \

0 commit comments

Comments
 (0)