Skip to content

Commit bea2c36

Browse files
craig[bot]rail
andcommitted
Merge #150232
150232: release: GPG signing for custom releases r=celiala a=rail This commit adds a new script for signing custom releases using GPG keys stored in Google Cloud Secrets. The script is designed to run on a specific signing agent and handles the retrieval of GPG keys, signing of release artifacts, and uploading them to a specified Google Cloud Storage bucket. Release note: none Fixes: RE-970 Co-authored-by: Rail Aliiev <[email protected]>
2 parents 85cfb7b + 2782b07 commit bea2c36

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2023 The Cockroach Authors.
4+
#
5+
# Use of this software is governed by the CockroachDB Software License
6+
# included in the /LICENSE file.
7+
8+
set -xeuo pipefail
9+
10+
service_account=$(curl --header "Metadata-Flavor: Google" "http://metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/email" || echo "")
11+
if [[ $service_account != "[email protected]" ]]; then
12+
echo "Not running on a signing agent, skipping signing"
13+
exit 1
14+
fi
15+
16+
dir="$(dirname $(dirname $(dirname $(dirname $(dirname $(dirname "${0}"))))))"
17+
source "$dir/teamcity-support.sh" # For log_into_gcloud
18+
19+
curr_dir=$(pwd)
20+
21+
remove_files_on_exit() {
22+
rm -f "$curr_dir/.google-credentials.json"
23+
rm -rf "$curr_dir/.secrets"
24+
}
25+
trap remove_files_on_exit EXIT
26+
27+
mkdir -p .secrets
28+
# Explicitly set the account to the signing agent. This is helpful if one of the previous
29+
# commands failed and left the account set to something else.
30+
gcloud config set account "[email protected]"
31+
gcloud secrets versions access latest --secret=gpg-private-key | base64 -d > "$curr_dir/.secrets/gpg-private-key"
32+
gcloud secrets versions access latest --secret=gpg-private-key-password | base64 -d > "$curr_dir/.secrets/gpg-private-key-password"
33+
34+
gpg --homedir "$curr_dir/.secrets" --pinentry-mode loopback \
35+
--passphrase-file "$curr_dir/.secrets/gpg-private-key-password" \
36+
--import "$curr_dir/.secrets/gpg-private-key"
37+
38+
# By default, set dry-run variables
39+
google_credentials="$GCS_CREDENTIALS_DEV"
40+
gcs_staged_bucket="cockroach-release-artifacts-staged-dryrun"
41+
version=$(grep -v "^#" "$dir/../pkg/build/version.txt" | head -n1)
42+
cockroach_archive_prefix="${COCKROACH_ARCHIVE_PREFIX:?COCKROACH_ARCHIVE_PREFIX must be set}"
43+
44+
# override dev defaults with production values
45+
if [[ -z "${DRY_RUN}" ]] ; then
46+
echo "Setting production variable values"
47+
google_credentials="$GCS_CREDENTIALS_PROD"
48+
gcs_staged_bucket="cockroach-release-artifacts-staged-prod"
49+
fi
50+
51+
log_into_gcloud
52+
53+
mkdir -p artifacts
54+
cd artifacts
55+
56+
for platform in linux-amd64 linux-arm64; do
57+
tarball=${cockroach_archive_prefix}-${version}.${platform}.tgz
58+
59+
gsutil cp "gs://$gcs_staged_bucket/$tarball" "$tarball"
60+
gsutil cp "gs://$gcs_staged_bucket/$tarball.sha256sum" "$tarball.sha256sum"
61+
62+
shasum --algorithm 256 --check "$tarball.sha256sum"
63+
64+
gpg --homedir "$curr_dir/.secrets" --pinentry-mode loopback \
65+
--passphrase-file "$curr_dir/.secrets/gpg-private-key-password" \
66+
--detach-sign --armor "$tarball"
67+
gpg --homedir "$curr_dir/.secrets" --verify "$tarball.asc" "$tarball"
68+
69+
gsutil cp "$tarball.asc" "gs://$gcs_staged_bucket/$tarball.asc"
70+
done

0 commit comments

Comments
 (0)