Skip to content
This repository was archived by the owner on Aug 3, 2026. It is now read-only.

Commit fa19248

Browse files
committed
fix: support GCP Secret Manager enclave key
1 parent 7059c70 commit fa19248

1 file changed

Lines changed: 42 additions & 2 deletions

File tree

script/publish-image.sh

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,51 @@ esac
5454

5555
echo "Build and push $image_name:$tag..."
5656
build_secret_args=()
57+
tmp_enclave_key_path=""
58+
cleanup_tmp_enclave_key() {
59+
if [[ -n "$tmp_enclave_key_path" ]]; then
60+
rm -f "$tmp_enclave_key_path"
61+
fi
62+
}
63+
trap cleanup_tmp_enclave_key EXIT
64+
5765
if [ "$proof_type" = "0" ] || [ "$proof_type" = "tee" ]; then
58-
enclave_key_path="${ENCLAVE_KEY_PATH:-docker/enclave-key.pem}"
66+
if [[ -n "${GCP_ENCLAVE_KEY_SECRET:-}" ]]; then
67+
if ! command -v gcloud >/dev/null 2>&1; then
68+
echo "❌ gcloud is required when GCP_ENCLAVE_KEY_SECRET is set."
69+
exit 1
70+
fi
71+
72+
tmp_enclave_key_path="$(mktemp)"
73+
gcloud_secret_version="${GCP_ENCLAVE_KEY_VERSION:-latest}"
74+
gcloud_secret_args=(
75+
secrets versions access "$gcloud_secret_version"
76+
--secret "$GCP_ENCLAVE_KEY_SECRET"
77+
--out-file "$tmp_enclave_key_path"
78+
)
79+
if [[ -n "${GCP_ENCLAVE_KEY_PROJECT:-}" ]]; then
80+
gcloud_secret_args+=(--project "$GCP_ENCLAVE_KEY_PROJECT")
81+
fi
82+
83+
echo "Fetching enclave signing key from GCP Secret Manager: $GCP_ENCLAVE_KEY_SECRET version $gcloud_secret_version"
84+
case "$-" in
85+
*x*) xtrace_was_on=1 ;;
86+
*) xtrace_was_on=0 ;;
87+
esac
88+
set +x
89+
gcloud "${gcloud_secret_args[@]}"
90+
if [[ "$xtrace_was_on" = "1" ]]; then
91+
set -x
92+
fi
93+
chmod 0600 "$tmp_enclave_key_path"
94+
enclave_key_path="$tmp_enclave_key_path"
95+
else
96+
enclave_key_path="${ENCLAVE_KEY_PATH:-docker/enclave-key.pem}"
97+
fi
98+
5999
if [ ! -s "$enclave_key_path" ]; then
60100
echo "❌ Missing enclave signing key: $enclave_key_path"
61-
echo "Set ENCLAVE_KEY_PATH=/path/to/enclave-key.pem or provide docker/enclave-key.pem locally."
101+
echo "Set GCP_ENCLAVE_KEY_SECRET=<secret-name>, ENCLAVE_KEY_PATH=/path/to/enclave-key.pem, or provide docker/enclave-key.pem locally."
62102
exit 1
63103
fi
64104
enclave_key_public_sha256="$(openssl rsa -in "$enclave_key_path" -pubout 2>/dev/null | openssl sha256 | awk '{print $2}')"

0 commit comments

Comments
 (0)