Skip to content

Commit

Permalink
Initial binary signing implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
cveticm committed Jan 28, 2025
1 parent e7edf97 commit a7f7c14
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 4 deletions.
21 changes: 17 additions & 4 deletions build/ci/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,18 @@ functions:
set -Eeou pipefail
curl -sfL ${goreleaser_pro_tar_gz} | tar zx
"install macos notarization service":
- command: shell.exec
type: setup
params:
working_dir: src/github.com/mongodb/mongodb-atlas-cli
include_expansions_in_env:
- notary_service_url
script: |
set -Eeou pipefail
curl "${notary_service_url}" --output macos-notary.zip
unzip -u macos-notary.zip
chmod 755 ./linux_amd64/macnotary
"generate notices":
- command: subprocess.exec
type: test
Expand Down Expand Up @@ -121,12 +133,13 @@ functions:
tasks:
- name: package_goreleaser
tags: ["packaging"]
depends_on:
- name: compile
variant: "code_health"
# depends_on:
# - name: compile
# variant: "code_health"
commands:
- func: "generate notices"
- func: "install goreleaser"
- func: "install macos notarization service"
- func: "install gh-token"
- func: "package"
- name: copybara
Expand Down Expand Up @@ -156,7 +169,7 @@ tasks:
buildvariants:
- name: release
display_name: "Release AtlasCLI Plugin Kubernetes (goreleaser)"
git_tag_only: true
# git_tag_only: true
run_on:
- rhel90-small
expansions:
Expand Down
10 changes: 10 additions & 0 deletions build/package/.goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,21 @@ builds:
id: macos
goos: [darwin]
goarch: [amd64,arm64]
hooks:
# This will notarize Apple binaries and replace goreleaser bins with the notarized ones
post:
- cmd: ./build/package/mac_notarize.sh
output: true
- <<: *build_defaults
id: windows
goos: [windows]
goarch: [amd64]
goamd64: [v1]
hooks:
# This will notarize the Windows binary and replace goreleaser bin with the notarized one
post:
- cmd: ./build/package/windows_notarize.sh
output: true
gomod: # https://goreleaser.com/customization/verifiable_builds/
# Proxy a module from proxy.golang.org, making the builds verifiable.
# This will only be effective if running against a tag. Snapshots will ignore
Expand Down
35 changes: 35 additions & 0 deletions build/package/mac_notarize.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash

# Copyright 2025 MongoDB Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -Eeou pipefail

# mac_notarize generated binaries with Apple and replace the original binary with the notarized one
# This depends on binaries being generated in a goreleaser manner and gon being set up.
# goreleaser should already take care of calling this script as a hook.

if [[ -f "./dist/macos_darwin_amd64_v1/bin/atlas-cli-plugin-kubernetes" && -f "./dist/macos_darwin_arm64/bin/atlas-cli-plugin-kubernetes" && ! -f "./dist/atlas-cli-plugin-kubernetes_macos_signed.zip" ]]; then
echo "notarizing macOs binaries"
zip -r ./dist/atlas-cli-plugin-kubernetes_amd64_arm64_bin.zip ./dist/macos_darwin_amd64_v1/bin/atlas-cli-plugin-kubernetes ./dist/macos_darwin_arm64/bin/atlas-cli-plugin-kubernetes # The Notarization Service takes an archive as input
./linux_amd64/macnotary \
-f ./dist/atlas-cli-plugin-kubernetes_amd64_arm64_bin.zip \
-m notarizeAndSign -u https://dev.macos-notary.build.10gen.cc/api \
-b com.mongodb.atlas-cli-plugin-kubernetes \
-o ./dist/atlas-cli-plugin-kubernetes_macos_signed.zip

echo "replacing original files"
unzip -oj ./dist/atlas-cli-plugin-kubernetes_macos_signed.zip dist/macos_darwin_amd64_v1/bin/atlas-cli-plugin-kubernetes -d ./dist/macos_darwin_amd64_v1/bin/
unzip -oj ./dist/atlas-cli-plugin-kubernetes_macos_signed.zip dist/macos_darwin_arm64/bin/atlas-cli-plugin-kubernetes -d ./dist/macos_darwin_arm64/bin/
fi
39 changes: 39 additions & 0 deletions build/package/windows_notarize.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env bash

# Copyright 2025 MongoDB Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

set -Eeou pipefail

VERSION_GIT="$(git tag --list "v*" --sort=taggerdate | tail -1 | cut -d "v" -f 2)"

EXE_FILE="./dist/windows_windows_amd64_v1/atlas-cli-plugin-kubernetes.exe"

if [[ -f "$EXE_FILE"]]; then
echo "${ARTIFACTORY_PASSWORD}" | podman login --password-stdin --username "${ARTIFACTORY_USERNAME}" artifactory.corp.mongodb.com

echo "GRS_CONFIG_USER1_USERNAME=${GRS_USERNAME}" > .env
echo "GRS_CONFIG_USER1_PASSWORD=${GRS_PASSWORD}" >> .env

echo "signing $EXE_FILE"
podman run \
--env-file=.env \
--rm \
-v "$(pwd):$(pwd)" \
-w "$(pwd)" \
artifactory.corp.mongodb.com/release-tools-container-registry-local/garasign-jsign \
/bin/bash -c "jsign --tsaurl http://timestamp.digicert.com -a ${AUTHENTICODE_KEY_NAME} \"$EXE_FILE\""

rm .env
fi

0 comments on commit a7f7c14

Please sign in to comment.