Skip to content

Commit 699cff5

Browse files
committed
added scripts for generating gpg
1 parent f2b6889 commit 699cff5

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

scripts/gpg/README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
This folder contains helper scripts to generate and manage a dedicated GPG key for the Terraform provider releases.
2+
3+
Security note: Do not commit private keys. These scripts write keys into `terraform-provider-logstruct/.gpg/` which is ignored by git (and the whole provider dir is ignored in this repo).
4+
5+
Quick start
6+
7+
1) Generate a CI keypair and export ASCII-armored keys:
8+
9+
bash scripts/gpg/generate_provider_gpg.sh
10+
11+
Outputs:
12+
- terraform-provider-logstruct/.gpg/public_gpg_key.asc
13+
- terraform-provider-logstruct/.gpg/private_gpg_key.asc
14+
15+
2) Upload public key to the Terraform Registry namespace:
16+
- Copy contents of `public_gpg_key.asc` to the HashiCorp Registry UI → Namespace → GPG Keys → Add.
17+
18+
3) Store private key in GitHub Actions secrets for the provider repo:
19+
- In DocSpring/terraform-provider-logstruct → Settings → Secrets and variables → Actions → New repository secret
20+
- `GPG_PRIVATE_KEY`: paste the entire contents of `private_gpg_key.asc`
21+
- (Optional) `GPG_PASSPHRASE`: if you set a passphrase during key generation
22+
23+
4) Verify a release (on v* tag in provider):
24+
- Provider CI imports the key and GoReleaser signs checksums per `.goreleaser.yaml`.
25+
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
# Generates a dedicated GPG key for Terraform provider releases
5+
# and exports ASCII-armored public/private keys into
6+
# .gpg/
7+
#
8+
# Defaults are safe for CI: RSA4096, no passphrase (non-interactive signing).
9+
# If you want a passphrase, set GPG_PASSPHRASE env var and export will prompt once.
10+
11+
NAME_DEFAULT="DocSpring Terraform Provider"
12+
EMAIL_DEFAULT="[email protected]"
13+
KEY_DIR=".gpg"
14+
15+
NAME="${GPG_NAME:-$NAME_DEFAULT}"
16+
EMAIL="${GPG_EMAIL:-$EMAIL_DEFAULT}"
17+
18+
mkdir -p "$KEY_DIR"
19+
20+
cat >"$KEY_DIR"/gpg-batch.cfg <<CFG
21+
Key-Type: RSA
22+
Key-Length: 4096
23+
Subkey-Type: RSA
24+
Subkey-Length: 4096
25+
Name-Real: $NAME
26+
Name-Email: $EMAIL
27+
Expire-Date: 1y
28+
%no-protection
29+
%commit
30+
CFG
31+
32+
if [[ -n "${GPG_PASSPHRASE:-}" ]]; then
33+
# Replace %no-protection with passphrase config
34+
sed -i'' -e '/^%no-protection$/d' "$KEY_DIR"/gpg-batch.cfg || true
35+
{
36+
echo "Passphrase: $GPG_PASSPHRASE"
37+
} >> "$KEY_DIR"/gpg-batch.cfg
38+
fi
39+
40+
echo "Generating GPG key for $NAME <$EMAIL> ..."
41+
gpg --batch --gen-key "$KEY_DIR"/gpg-batch.cfg
42+
43+
echo "Exporting ASCII-armored keys..."
44+
gpg --armor --export "$EMAIL" > "$KEY_DIR"/public_gpg_key.asc
45+
gpg --armor --export-secret-keys "$EMAIL" > "$KEY_DIR"/private_gpg_key.asc
46+
47+
echo "Done. Files created in $KEY_DIR:"
48+
ls -la "$KEY_DIR"
49+
50+
cat <<'NEXT'
51+
52+
Next steps:
53+
- Upload the public key to the Terraform Registry namespace (copy from public_gpg_key.asc).
54+
- Add provider repo secrets:
55+
- GPG_PRIVATE_KEY = contents of private_gpg_key.asc
56+
- (Optional) GPG_PASSPHRASE if you set one
57+
- Re-run provider release to sign checksums.
58+
59+
For safekeeping, move private_gpg_key.asc into your password manager.
60+
NEXT

0 commit comments

Comments
 (0)