Skip to content

Commit 6fee25b

Browse files
authored
chore(ci): rpm signing COMPASS-7588 (#5379)
* wip rpm signing * update package * verify correctly
1 parent 92f267e commit 6fee25b

File tree

6 files changed

+57
-36
lines changed

6 files changed

+57
-36
lines changed

.evergreen/functions.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -664,13 +664,6 @@ functions:
664664
remote_file: ${project}/${revision}_${revision_order_id}/${linux_rpm_filename}
665665
content_type: application/x-redhat-package-manager
666666
optional: true
667-
- command: s3.put
668-
params:
669-
<<: *save-artifact-params-public
670-
local_file: src/packages/compass/dist/${linux_rpm_sign_filename}
671-
remote_file: ${project}/${revision}_${revision_order_id}/${linux_rpm_sign_filename}
672-
content_type: application/pgp-signature
673-
optional: true
674667
- command: s3.put
675668
params:
676669
<<: *save-artifact-params-public

.evergreen/verify-artifacts.sh

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ ls -l $ARTIFACTS_DIR
99
# Use tmp directory for all gpg operations
1010
GPG_HOME=$(mktemp -d)
1111
TMP_FILE=$(mktemp)
12+
COMPASS_KEY="https://pgp.mongodb.com/compass.asc"
1213

1314
trap_handler() {
1415
local code=$?
@@ -40,9 +41,28 @@ verify_using_codesign() {
4041
codesign -dv --verbose=4 $ARTIFACTS_DIR/$1 > "$TMP_FILE" 2>&1
4142
}
4243

44+
verify_using_rpm() {
45+
# RPM packages are signed using gpg and the signature is embedded in the package.
46+
# Here, we need to import the key in `rpm` and then verify the signature.
47+
echo "Importing key into rpm"
48+
rpm --import $COMPASS_KEY > "$TMP_FILE" 2>&1
49+
# Even if the file is not signed, the command below will exit with 0 and output something like: sha1 md5 OK
50+
# So we need to check the output of the command to see if the file is signed successfully.
51+
echo "Verifying $1 using rpm"
52+
output=$(rpm -K $ARTIFACTS_DIR/$1)
53+
# Remove the imported key from rpm
54+
rpm -e $(rpm -q gpg-pubkey --qf '%{name}-%{version}-%{release}:%{summary}\n' | grep compass | awk -F: '{print $1}')
55+
56+
# Check if the output contains the string "pgp md5 OK"
57+
if [[ $output != *"pgp md5 OK"* ]]; then
58+
echo "File $1 is not signed"
59+
exit 1
60+
fi
61+
}
62+
4363
setup_gpg() {
4464
echo "Importing Compass public key"
45-
curl https://pgp.mongodb.com/compass.asc | gpg --homedir $GPG_HOME --import > "$TMP_FILE" 2>&1
65+
curl $COMPASS_KEY | gpg --homedir $GPG_HOME --import > "$TMP_FILE" 2>&1
4666
}
4767

4868
if [ "$IS_WINDOWS" = true ]; then
@@ -55,7 +75,7 @@ elif [ "$IS_UBUNTU" = true ]; then
5575
verify_using_gpg $LINUX_TAR_NAME
5676
elif [ "$IS_RHEL" = true ]; then
5777
setup_gpg
58-
verify_using_gpg $RHEL_RPM_NAME
78+
verify_using_rpm $RHEL_RPM_NAME
5979
verify_using_gpg $RHEL_TAR_NAME
6080
elif [ "$IS_OSX" = true ]; then
6181
setup_gpg

package-lock.json

Lines changed: 18 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/hadron-build/lib/signtool.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,21 @@ function signArchive(target, cb) {
3636
sign(target.dest(app_archive_name)).then(cb).catch(cb);
3737
}
3838

39+
/**
40+
* @param {string} src
41+
*/
42+
function getSigningMethod(src) {
43+
switch (path.extname(src)) {
44+
case '.exe':
45+
case '.msi':
46+
return 'jsign';
47+
case '.rpm':
48+
return 'rpm_gpg';
49+
default:
50+
return 'gpg';
51+
}
52+
}
53+
3954
/**
4055
* We are signing the file using `gpg` or `jsign` depending on the
4156
* file extension. If the extension is `.exe` or `.msi`, we use `jsign`
@@ -58,7 +73,7 @@ async function sign(src, garasign = _garasign) {
5873
username: process.env.SIGNING_SERVER_USERNAME,
5974
port: process.env.SIGNING_SERVER_PORT,
6075
privateKey: process.env.SIGNING_SERVER_PRIVATE_KEY,
61-
signingMethod: path.extname(src) === '.exe' || path.extname(src) === '.msi' ? 'jsign' : 'gpg'
76+
signingMethod: getSigningMethod(src),
6277
};
6378

6479
return await garasign(src, clientOptions);

packages/hadron-build/lib/target.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,6 @@ class Target {
639639
this.linux_rpm_filename = `${this.slug}-${this.version}.${rhelArch}.rpm`;
640640
this.rhel_tar_filename = `${this.slug}-${this.version}-rhel-${this.arch}.tar.gz`;
641641

642-
this.linux_rpm_sign_filename = getSignedFilename(this.linux_rpm_filename);
643642
this.rhel_tar_sign_filename = getSignedFilename(this.rhel_tar_filename);
644643

645644
this.assets = [
@@ -657,10 +656,6 @@ class Target {
657656
path: this.dest(this.linux_rpm_filename),
658657
downloadCenter: true
659658
},
660-
{
661-
name: this.linux_rpm_sign_filename,
662-
path: this.dest(this.linux_rpm_sign_filename),
663-
},
664659
{
665660
name: this.linux_tar_filename,
666661
path: this.dest(this.linux_tar_filename)

packages/hadron-build/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"@mongodb-js/devtools-github-repo": "^1.4.1",
2424
"@mongodb-js/dl-center": "^1.0.1",
2525
"@mongodb-js/electron-wix-msi": "^3.0.0",
26-
"@mongodb-js/signing-utils": "^0.2.3",
26+
"@mongodb-js/signing-utils": "^0.3.1",
2727
"@npmcli/arborist": "^6.2.0",
2828
"@octokit/rest": "^18.6.2",
2929
"asar": "^3.0.3",

0 commit comments

Comments
 (0)