@@ -50,6 +50,25 @@ if [ "$(id -u)" -ne 0 ]; then
5050 exit 1
5151fi
5252
53+ import_hashicorp_gpg_key_noble () {
54+ unset GNUPGHOME
55+ curl -fsSL https://keybase.io/hashicorp/pgp_keys.asc | gpg --import
56+ if ! gpg --list-keys " ${TERRAFORM_GPG_KEY} " > /dev/null 2>&1 ; then
57+ gpg --list-keys
58+ echo " (!) HashiCorp GPG key not found in keyring after import. Aborting."
59+ exit 1
60+ fi
61+ }
62+
63+ # Detect Ubuntu Noble and use new repo setup, else use legacy GPG logic
64+ IS_NOBLE=0
65+ if grep -qi ' ubuntu' /etc/os-release; then
66+ . /etc/os-release
67+ if [[ " $VERSION_CODENAME " == " noble" ]]; then
68+ IS_NOBLE=1
69+ fi
70+ fi
71+
5372# Get the list of GPG key servers that are reachable
5473get_gpg_key_servers () {
5574 declare -A keyservers_curl_map=(
@@ -366,6 +385,13 @@ install_terraform() {
366385 curl -sSL -o ${terraform_filename} " ${HASHICORP_RELEASES_URL} /terraform/${TERRAFORM_VERSION} /${terraform_filename} "
367386}
368387
388+ verify_terraform_sig () {
389+ receive_gpg_keys TERRAFORM_GPG_KEY
390+ curl -sSL -o terraform_SHA256SUMS " ${HASHICORP_RELEASES_URL} /terraform/${TERRAFORM_VERSION} /terraform_${TERRAFORM_VERSION} _SHA256SUMS"
391+ curl -sSL -o terraform_SHA256SUMS.sig " ${HASHICORP_RELEASES_URL} /terraform/${TERRAFORM_VERSION} /terraform_${TERRAFORM_VERSION} _SHA256SUMS.${TERRAFORM_GPG_KEY} .sig"
392+ gpg --verify terraform_SHA256SUMS.sig terraform_SHA256SUMS
393+ }
394+
369395mkdir -p /tmp/tf-downloads
370396cd /tmp/tf-downloads
371397# Install Terraform, tflint, Terragrunt
@@ -378,10 +404,18 @@ if grep -q "The specified key does not exist." "${terraform_filename}"; then
378404fi
379405if [ " ${TERRAFORM_SHA256} " != " dev-mode" ]; then
380406 if [ " ${TERRAFORM_SHA256} " = " automatic" ]; then
381- receive_gpg_keys TERRAFORM_GPG_KEY
382- curl -sSL -o terraform_SHA256SUMS " ${HASHICORP_RELEASES_URL} /terraform/${TERRAFORM_VERSION} /terraform_${TERRAFORM_VERSION} _SHA256SUMS"
383- curl -sSL -o terraform_SHA256SUMS.sig " ${HASHICORP_RELEASES_URL} /terraform/${TERRAFORM_VERSION} /terraform_${TERRAFORM_VERSION} _SHA256SUMS.${TERRAFORM_GPG_KEY} .sig"
384- gpg --verify terraform_SHA256SUMS.sig terraform_SHA256SUMS
407+ if [ " $IS_NOBLE " -eq 1 ]; then
408+ import_hashicorp_gpg_key_noble
409+ curl -sSL -o terraform_SHA256SUMS " ${HASHICORP_RELEASES_URL} /terraform/${TERRAFORM_VERSION} /terraform_${TERRAFORM_VERSION} _SHA256SUMS"
410+ curl -sSL -o terraform_SHA256SUMS.sig " ${HASHICORP_RELEASES_URL} /terraform/${TERRAFORM_VERSION} /terraform_${TERRAFORM_VERSION} _SHA256SUMS.${TERRAFORM_GPG_KEY} .sig"
411+ gpg --list-keys
412+ if ! gpg --verify terraform_SHA256SUMS.sig terraform_SHA256SUMS; then
413+ echo " Primary GPG verification failed, attempting fallback verification..."
414+ verify_terraform_sig
415+ fi
416+ else
417+ verify_terraform_sig
418+ fi
385419 else
386420 echo " ${TERRAFORM_SHA256} *${terraform_filename} " > terraform_SHA256SUMS
387421 fi
@@ -443,6 +477,13 @@ if [ "${TFLINT_VERSION}" != "none" ]; then
443477 mv -f tflint /usr/local/bin/
444478fi
445479
480+ verify_sentinel_sig () {
481+ receive_gpg_keys TERRAFORM_GPG_KEY
482+ curl -sSL -o sentinel_checksums.txt ${sentinel_releases_url} /${SENTINEL_VERSION} /sentinel_${SENTINEL_VERSION} _SHA256SUMS
483+ curl -sSL -o sentinel_checksums.txt.sig ${sentinel_releases_url} /${SENTINEL_VERSION} /sentinel_${SENTINEL_VERSION} _SHA256SUMS.${TERRAFORM_GPG_KEY} .sig
484+ gpg --verify sentinel_checksums.txt.sig sentinel_checksums.txt
485+ }
486+
446487install_terragrunt () {
447488 TERRAGRUNT_VERSION=$1
448489 curl -sSL -o /tmp/tf-downloads/${terragrunt_filename} https://github.com/gruntwork-io/terragrunt/releases/download/v${TERRAGRUNT_VERSION} /${terragrunt_filename}
@@ -477,12 +518,21 @@ if [ "${INSTALL_SENTINEL}" = "true" ]; then
477518 curl -sSL -o /tmp/tf-downloads/${sentinel_filename} ${sentinel_releases_url} /${SENTINEL_VERSION} /${sentinel_filename}
478519 if [ " ${SENTINEL_SHA256} " != " dev-mode" ]; then
479520 if [ " ${SENTINEL_SHA256} " = " automatic" ]; then
480- receive_gpg_keys TERRAFORM_GPG_KEY
481- curl -sSL -o sentinel_checksums.txt ${sentinel_releases_url} /${SENTINEL_VERSION} /sentinel_${SENTINEL_VERSION} _SHA256SUMS
482- curl -sSL -o sentinel_checksums.txt.sig ${sentinel_releases_url} /${SENTINEL_VERSION} /sentinel_${SENTINEL_VERSION} _SHA256SUMS.${TERRAFORM_GPG_KEY} .sig
483- gpg --verify sentinel_checksums.txt.sig sentinel_checksums.txt
484- # Verify the SHASUM matches the archive
485- shasum -a 256 --ignore-missing -c sentinel_checksums.txt
521+ if [ " $IS_NOBLE " -eq 1 ]; then
522+ import_hashicorp_gpg_key_noble
523+ curl -sSL -o sentinel_checksums.txt ${sentinel_releases_url} /${SENTINEL_VERSION} /sentinel_${SENTINEL_VERSION} _SHA256SUMS
524+ curl -sSL -o sentinel_checksums.txt.sig ${sentinel_releases_url} /${SENTINEL_VERSION} /sentinel_${SENTINEL_VERSION} _SHA256SUMS.${TERRAFORM_GPG_KEY} .sig
525+ if ! gpg --verify sentinel_checksums.txt.sig sentinel_checksums.txt; then
526+ echo " Primary GPG verification failed, attempting fallback verification..."
527+ verify_sentinel_sig
528+ fi
529+ # Verify the SHASUM matches the archive
530+ shasum -a 256 --ignore-missing -c sentinel_checksums.txt
531+ else
532+ verify_sentinel_sig
533+ # Verify the SHASUM matches the archive
534+ shasum -a 256 --ignore-missing -c sentinel_checksums.txt
535+ fi
486536 else
487537 echo " ${SENTINEL_SHA256} *${SENTINEL_FILENAME} " > sentinel_checksums.txt
488538 fi
0 commit comments