@@ -50,6 +50,15 @@ if [ "$(id -u)" -ne 0 ]; then
50
50
exit 1
51
51
fi
52
52
53
+ # Detect Ubuntu Noble and use new repo setup, else use legacy GPG logic
54
+ IS_NOBLE=0
55
+ if grep -qi ' ubuntu' /etc/os-release; then
56
+ . /etc/os-release
57
+ if [[ " $VERSION_CODENAME " == " noble" ]]; then
58
+ IS_NOBLE=1
59
+ fi
60
+ fi
61
+
53
62
# Get the list of GPG key servers that are reachable
54
63
get_gpg_key_servers () {
55
64
declare -A keyservers_curl_map=(
@@ -89,7 +98,7 @@ receive_gpg_keys() {
89
98
keyring_args=" --no-default-keyring --keyring $2 "
90
99
fi
91
100
if [ ! -z " ${KEYSERVER_PROXY} " ]; then
92
- keyring_args=" ${keyring_args} --keyserver-options http-proxy=${KEYSERVER_PROXY} "
101
+ keyring_args=" ${keyring_args} --keyserver-options http-proxy=${KEYSERVER_PROXY} "
93
102
fi
94
103
95
104
# Install curl
@@ -101,6 +110,21 @@ receive_gpg_keys() {
101
110
export GNUPGHOME=" /tmp/tmp-gnupg"
102
111
mkdir -p ${GNUPGHOME}
103
112
chmod 700 ${GNUPGHOME}
113
+
114
+ # Special handling for HashiCorp GPG key on Ubuntu Noble
115
+ if [ " $IS_NOBLE " -eq 1 ] && [ " $keys " = " $TERRAFORM_GPG_KEY " ]; then
116
+ echo " (*) Ubuntu Noble detected, using Keybase for HashiCorp GPG key import...."
117
+ curl -fsSL https://keybase.io/hashicorp/pgp_keys.asc | gpg --import
118
+ if ! gpg --list-keys " ${TERRAFORM_GPG_KEY} " > /dev/null 2>&1 ; then
119
+ gpg --list-keys
120
+ echo " (*) Warning: HashiCorp GPG key not found in keyring after import."
121
+ echo " Continuing installation without GPG verification on Ubuntu Noble."
122
+ echo " This is expected behavior for Ubuntu Noble due to keyserver issues."
123
+ return 1 # Return failure to indicate GPG verification should be skipped
124
+ fi
125
+ return 0
126
+ fi
127
+
104
128
echo -e " disable-ipv6\n$( get_gpg_key_servers) " > ${GNUPGHOME} /dirmngr.conf
105
129
# GPG key download sometimes fails for some reason and retrying fixes it.
106
130
local retry_count=0
@@ -366,6 +390,32 @@ install_terraform() {
366
390
curl -sSL -o ${terraform_filename} " ${HASHICORP_RELEASES_URL} /terraform/${TERRAFORM_VERSION} /${terraform_filename} "
367
391
}
368
392
393
+ verify_signature () {
394
+ local gpg_key=$1
395
+ local sha256sums_url=$2
396
+ local sig_url=$3
397
+ local sha256sums_file=$4
398
+ local sig_file=$5
399
+ local verify_result=0
400
+
401
+ receive_gpg_keys " $gpg_key "
402
+ verify_result=$?
403
+ if [ $verify_result -ne 0 ] && [ " $IS_NOBLE " -eq 1 ]; then
404
+ echo " Skipping the gpg key validation for ubuntu noble as unable to import the key."
405
+ return 1
406
+ fi
407
+ curl -sSL -o " $sha256sums_file " " $sha256sums_url "
408
+ curl -sSL -o " $sig_file " " $sig_url "
409
+
410
+ # Try GPG verification, but don't fail on Noble
411
+ gpg --verify " $sig_file " " $sha256sums_file "
412
+ verify_result=$?
413
+ if [ $verify_result -ne 0 ]; then
414
+ echo " (!) GPG verification failed."
415
+ exit 1
416
+ fi
417
+ }
418
+
369
419
mkdir -p /tmp/tf-downloads
370
420
cd /tmp/tf-downloads
371
421
# Install Terraform, tflint, Terragrunt
@@ -378,10 +428,25 @@ if grep -q "The specified key does not exist." "${terraform_filename}"; then
378
428
fi
379
429
if [ " ${TERRAFORM_SHA256} " != " dev-mode" ]; then
380
430
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
431
+ # For Ubuntu Noble, try GPG verification but continue if it fails
432
+ if [ " $IS_NOBLE " -eq 1 ]; then
433
+ echo " (*) Ubuntu Noble detected - attempting GPG verification with fallback..."
434
+ set +e
435
+ sha256sums_url=" ${HASHICORP_RELEASES_URL} /terraform/${TERRAFORM_VERSION} /terraform_${TERRAFORM_VERSION} _SHA256SUMS"
436
+ sig_url=" ${HASHICORP_RELEASES_URL} /terraform/${TERRAFORM_VERSION} /terraform_${TERRAFORM_VERSION} _SHA256SUMS.${TERRAFORM_GPG_KEY} .sig"
437
+ verify_signature TERRAFORM_GPG_KEY " $sha256sums_url " " $sig_url " " terraform_SHA256SUMS" " terraform_SHA256SUMS.sig"
438
+ verify_result=$?
439
+ set -e
440
+ if [ $verify_result -ne 0 ]; then
441
+ echo " (*) GPG verification failed on Ubuntu Noble, but continuing installation."
442
+ echo " Downloading checksums for basic integrity check..."
443
+ curl -sSL -o terraform_SHA256SUMS " ${HASHICORP_RELEASES_URL} /terraform/${TERRAFORM_VERSION} /terraform_${TERRAFORM_VERSION} _SHA256SUMS"
444
+ fi
445
+ else
446
+ sha256sums_url=" ${HASHICORP_RELEASES_URL} /terraform/${TERRAFORM_VERSION} /terraform_${TERRAFORM_VERSION} _SHA256SUMS"
447
+ sig_url=" ${HASHICORP_RELEASES_URL} /terraform/${TERRAFORM_VERSION} /terraform_${TERRAFORM_VERSION} _SHA256SUMS.${TERRAFORM_GPG_KEY} .sig"
448
+ verify_signature TERRAFORM_GPG_KEY " $sha256sums_url " " $sig_url " " terraform_SHA256SUMS" " terraform_SHA256SUMS.sig"
449
+ fi
385
450
else
386
451
echo " ${TERRAFORM_SHA256} *${terraform_filename} " > terraform_SHA256SUMS
387
452
fi
@@ -477,12 +542,27 @@ if [ "${INSTALL_SENTINEL}" = "true" ]; then
477
542
curl -sSL -o /tmp/tf-downloads/${sentinel_filename} ${sentinel_releases_url} /${SENTINEL_VERSION} /${sentinel_filename}
478
543
if [ " ${SENTINEL_SHA256} " != " dev-mode" ]; then
479
544
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
545
+ # For Ubuntu Noble, try GPG verification but continue if it fails
546
+ if [ " $IS_NOBLE " -eq 1 ]; then
547
+ echo " (*) Ubuntu Noble detected - attempting Sentinel GPG verification with fallback..."
548
+ set +e
549
+ sha256sums_url=" ${sentinel_releases_url} /${SENTINEL_VERSION} /sentinel_${SENTINEL_VERSION} _SHA256SUMS"
550
+ sig_url=" ${sentinel_releases_url} /${SENTINEL_VERSION} /sentinel_${SENTINEL_VERSION} _SHA256SUMS.${TERRAFORM_GPG_KEY} .sig"
551
+ verify_signature TERRAFORM_GPG_KEY " $sha256sums_url " " $sig_url " " sentinel_checksums.txt" " sentinel_checksums.txt.sig"
552
+ verify_result=$?
553
+ set -e
554
+ if [ $verify_result -ne 0 ]; then
555
+ echo " (*) GPG verification failed on Ubuntu Noble, but continuing installation."
556
+ echo " Downloading checksums for basic integrity check..."
557
+ curl -sSL -o sentinel_checksums.txt " ${sentinel_releases_url} /${SENTINEL_VERSION} /sentinel_${SENTINEL_VERSION} _SHA256SUMS"
558
+ fi
559
+ else
560
+ sha256sums_url=" ${sentinel_releases_url} /${SENTINEL_VERSION} /sentinel_${SENTINEL_VERSION} _SHA256SUMS"
561
+ sig_url=" ${sentinel_releases_url} /${SENTINEL_VERSION} /sentinel_${SENTINEL_VERSION} _SHA256SUMS.${TERRAFORM_GPG_KEY} .sig"
562
+ verify_signature TERRAFORM_GPG_KEY " $sha256sums_url " " $sig_url " " sentinel_checksums.txt" " sentinel_checksums.txt.sig"
563
+ fi
484
564
# Verify the SHASUM matches the archive
485
- shasum -a 256 --ignore-missing -c sentinel_checksums.txt
565
+ shasum -a 256 --ignore-missing -c sentinel_checksums.txt
486
566
else
487
567
echo " ${SENTINEL_SHA256} *${SENTINEL_FILENAME} " > sentinel_checksums.txt
488
568
fi
0 commit comments