Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1edfe4b

Browse files
feat: sign coder binaries with GPG & serve from path /bin/
1 parent 6580971 commit 1edfe4b

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed

.github/workflows/ci.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,6 +1285,24 @@ jobs:
12851285
GCLOUD_ACCESS_TOKEN: ${{ steps.gcloud_auth.outputs.access_token }}
12861286
JSIGN_PATH: /tmp/jsign-6.0.jar
12871287

1288+
- name: Sign binaries with GPG
1289+
run: |
1290+
set -euo pipefail
1291+
1292+
for binary in ./build/coder_{darwin,linux,windows}*; do
1293+
if [[ -f "$binary" ]]; then
1294+
./scripts/sign_with_gpg.sh "$binary"
1295+
fi
1296+
done
1297+
env:
1298+
CODER_GPG_RELEASE_KEY_BASE64: ${{ secrets.CODER_GPG_RELEASE_KEY_BASE64 }}
1299+
1300+
- name: Insert signatures
1301+
run: |
1302+
for sigfile in ./build/*.sig; do
1303+
mv "$sigfile" ./site/out/bin/
1304+
done
1305+
12881306
- name: Build Linux Docker images
12891307
id: build-docker
12901308
env:

.github/workflows/release.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,24 @@ jobs:
342342
- name: Delete Windows EV Signing Cert
343343
run: rm /tmp/ev_cert.pem
344344

345+
- name: Sign binaries with GPG
346+
run: |
347+
set -euo pipefail
348+
349+
for binary in ./build/coder_{darwin,linux,windows}*; do
350+
if [[ -f "$binary" ]]; then
351+
./scripts/sign_with_gpg.sh "$binary"
352+
fi
353+
done
354+
env:
355+
CODER_GPG_RELEASE_KEY_BASE64: ${{ secrets.CODER_GPG_RELEASE_KEY_BASE64 }}
356+
357+
- name: Insert signatures
358+
run: |
359+
for sigfile in ./build/*.sig; do
360+
mv "$sigfile" ./site/out/bin/
361+
done
362+
345363
- name: Determine base image tag
346364
id: image-base-tag
347365
run: |

scripts/sign_with_gpg.sh

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env bash
2+
3+
# This script signs a given binary using GPG.
4+
# It expects the binary to be signed as the first argument.
5+
#
6+
# Usage: ./sign_with_gpg.sh path/to/binary
7+
#
8+
# On success, the input file will be signed using the GPG key.
9+
#
10+
# Depends on the GPG utility. Requires the following environment variables to be set:
11+
# - $CODER_GPG_RELEASE_KEY_BASE64: The base64 encoded private key to use.
12+
13+
set -euo pipefail
14+
15+
requiredenvs CODER_GPG_RELEASE_KEY_BASE64
16+
17+
FILE_TO_SIGN="$1"
18+
19+
if [[ -z "$FILE_TO_SIGN" ]]; then
20+
echo "Usage: $0 <file_to_sign>"
21+
exit 1
22+
fi
23+
24+
if [[ ! -f "$FILE_TO_SIGN" ]]; then
25+
echo "File not found: $FILE_TO_SIGN"
26+
exit 1
27+
fi
28+
29+
# Import the private key.
30+
echo "$CODER_GPG_RELEASE_KEY_BASE64" | base64 --decode | gpg --import 1>&2
31+
32+
# Sign the binary.
33+
gpg --detach-sign --armor "$FILE_TO_SIGN" 1>&2
34+
35+
# Verify the signature.
36+
gpg --verify "${FILE_TO_SIGN}.sig" "$FILE_TO_SIGN" 1>&2
37+
38+
if [[ $? -eq 0 ]]; then
39+
echo "${FILE_TO_SIGN}.sig"
40+
else
41+
echo "Signature verification failed!" >&2
42+
exit 1
43+
fi

0 commit comments

Comments
 (0)