Skip to content

Commit 7ce2bb8

Browse files
TUN-6270: Import gpg keys from environment variables
We now keep the gpg key inputs configurable. This PR imports base64 encoded gpg details into the build environment and uses this information to sign the linux builds.
1 parent 6f78ccd commit 7ce2bb8

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

cfsetup.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ stretch: &stretch
4848
- pip3 install pynacl==1.4.0
4949
- pip3 install pygithub==1.55
5050
- pip3 install boto3==1.22.9
51+
- pip3 install gnupg==2.3.1
5152
post-cache:
5253
# build all packages (except macos and FIPS) and move them to /cfsetup/built_artifacts
5354
- ./build-packages.sh

release_pkgs.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
import subprocess
1212
import os
1313
import argparse
14+
import base64
1415
import logging
1516
import shutil
1617
from hashlib import sha256
1718

19+
import gnupg
1820
import boto3
1921
from botocore.client import Config
2022
from botocore.exceptions import ClientError
@@ -133,6 +135,20 @@ def _setup_rpm_pkg_directories(self, artifacts_path, archs=["aarch64", "x86_64",
133135
old_path = os.path.join(root, file)
134136
new_path = os.path.join(new_dir, file)
135137
shutil.copyfile(old_path, new_path)
138+
139+
"""
140+
imports gpg keys into the system so reprepro and createrepo can use it to sign packages.
141+
it returns the GPG ID after a successful import
142+
"""
143+
def import_gpg_keys(self, private_key, public_key):
144+
gpg = gnupg.GPG()
145+
private_key = base64.b64decode(private_key)
146+
gpg.import_keys(private_key)
147+
public_key = base64.b64decode(public_key)
148+
gpg.import_keys(public_key)
149+
data = gpg.list_keys(secret=True)
150+
return (data[0]["fingerprint"])
151+
136152

137153
"""
138154
Walks through a directory and uploads it's assets to R2.
@@ -231,8 +247,13 @@ def parse_args():
231247
)
232248

233249
parser.add_argument(
234-
"--gpg-key-id", default=os.environ.get("GPG_KEY_ID"), help="gpg key ID that's being used to sign release\
235-
packages."
250+
"--gpg-private-key", default=os.environ.get("LINUX_SIGNING_PRIVATE_KEY"), help="GPG private key to sign the\
251+
packages"
252+
)
253+
254+
parser.add_argument(
255+
"--gpg-public-key", default=os.environ.get("LINUX_SIGNING_PUBLIC_KEY"), help="GPG public key used for\
256+
signing packages"
236257
)
237258

238259
parser.add_argument(
@@ -257,8 +278,10 @@ def parse_args():
257278
exit(1)
258279

259280
pkg_creator = PkgCreator()
281+
gpg_key_id = pkg_creator.import_gpg_keys(args.gpg_private_key, args.gpg_public_key)
282+
260283
pkg_uploader = PkgUploader(args.account, args.bucket, args.id, args.secret)
261-
create_deb_packaging(pkg_creator, pkg_uploader, args.deb_based_releases, args.gpg_key_id, args.binary,
262-
args.archs, "main", args.release_tag)
284+
create_deb_packaging(pkg_creator, pkg_uploader, args.deb_based_releases, gpg_key_id, args.binary, args.archs,
285+
"main", args.release_tag)
263286

264287
create_rpm_packaging(pkg_creator, pkg_uploader, "./built_artifacts", args.release_tag, args.binary )

0 commit comments

Comments
 (0)