@@ -22,7 +22,6 @@ keyserver hkps://keys.openpgp.org
2222keyserver hkps://keyserver.pgp.com"
2323
2424check " tflint version as installed by feature" tflint --version
25- check " cosign version as installed by feature" cosign version
2625
2726architecture=" $( uname -m) "
2827case ${architecture} in
@@ -221,53 +220,82 @@ install_tflint() {
221220 curl -sSL -o /tmp/tf-downloads/${TFLINT_FILENAME} https://github.com/terraform-linters/tflint/releases/download/v${TFLINT_VERSION} /${TFLINT_FILENAME}
222221}
223222
223+ verify_tflint_attestations () {
224+ local checksums=$1
225+ local checksums_sha256=$( sha256sum " $checksums " | cut -d " " -f 1)
224226
225- try_install_dummy_tflint_cosign_version () {
227+ check_packages jq
228+
229+ curl -L -f " https://api.github.com/repos/terraform-linters/tflint/attestations/sha256:${checksums_sha256} " > attestation.json
230+ curl_exit_code=$?
231+ if [ $curl_exit_code -ne 0 ]; then
232+ echo " (*) Failed to fetch GitHub Attestations for tflint checksums"
233+ return 1
234+ fi
235+
236+ jq " .attestations[].bundle" attestation.json > bundle.jsonl
237+ gh at verify " $checksums " -R terraform-linters/tflint -b bundle.jsonl
238+ }
239+
240+
241+ try_install_dummy_tflint_version () {
226242 mode=$1
227243 tflint_url=' https://github.com/terraform-linters/tflint'
228244 mkdir -p /tmp/tf-downloads
229245 cd /tmp/tf-downloads
230246 echo -e " \nTrying to install dummy tflint version..."
231- TFLINT_VERSION=" 0.50 .XYZ"
247+ TFLINT_VERSION=" 0.60 .XYZ"
232248 echo " Downloading tflint...v${TFLINT_VERSION} "
233249 TFLINT_FILENAME=" tflint_linux_${architecture} .zip"
234250 install_tflint " $TFLINT_VERSION "
235251 if grep -q " Not Found" " /tmp/tf-downloads/${TFLINT_FILENAME} " ; then
236252 install_previous_version TFLINT_VERSION " $tflint_url " $mode " install_tflint"
237253 fi
238254 if [ " ${TFLINT_SHA256} " != " dev-mode" ]; then
239-
240- if [ " ${TFLINT_SHA256} " != " automatic" ]; then
255+ if [ " ${TFLINT_SHA256} " != " automatic" ]; then
241256 echo " ${TFLINT_SHA256} *${TFLINT_FILENAME} " > tflint_checksums.txt
242257 sha256sum --ignore-missing -c tflint_checksums.txt
243258 else
244259 curl -sSL -o tflint_checksums.txt https://github.com/terraform-linters/tflint/releases/download/v${TFLINT_VERSION} /checksums.txt
245260
261+ # Attempt GitHub Attestation verification (0.51.1+)
246262 set +e
247- curl -sSL -o checksums.txt.keyless.sig https://github.com/terraform-linters/tflint/releases/download/v${TFLINT_VERSION} /checksums.txt.keyless.sig
263+ verify_tflint_attestations tflint_checksums.txt
264+ verify_result=$?
248265 set -e
249-
250- # Check that checksums.txt.keyless.sig exists and is not empty
251- if [ -s checksums.txt.keyless.sig ]; then
252- # Validate checksums with cosign
253- curl -sSL -o checksums.txt.pem https://github.com/terraform-linters/tflint/releases/download/v${TFLINT_VERSION} /checksums.txt.pem
254- ensure_cosign $mode
255- cosign verify-blob \
256- --certificate=/tmp/tf-downloads/checksums.txt.pem \
257- --signature=/tmp/tf-downloads/checksums.txt.keyless.sig \
258- --certificate-identity-regexp=" ^https://github.com/terraform-linters/tflint" \
259- --certificate-oidc-issuer=https://token.actions.githubusercontent.com \
260- /tmp/tf-downloads/tflint_checksums.txt
261- # Ensure that checksums.txt has $TFLINT_FILENAME
262- grep ${TFLINT_FILENAME} /tmp/tf-downloads/tflint_checksums.txt
263- # Validate downloaded file
266+
267+ if [ $verify_result -eq 0 ]; then
264268 sha256sum --ignore-missing -c tflint_checksums.txt
269+ echo " (*) tflint_checksums.txt verified successfully using GitHub Attestation."
265270 else
266- # Fallback to older, GPG-based verification (pre-0.47.0 of tflint)
267- curl -sSL -o tflint_checksums.txt.sig https://github.com/terraform-linters/tflint/releases/download/v${TFLINT_VERSION} /checksums.txt.sig
268- curl -sSL -o tflint_key " ${TFLINT_GPG_KEY_URI} "
269- gpg -q --import tflint_key
270- gpg --verify tflint_checksums.txt.sig tflint_checksums.txt
271+ # Fallback to cosign verification
272+ echo " (*) GitHub Attestation verification failed or not supported for this version, falling back to Cosign verification..."
273+ set +e
274+ curl -sSL -o checksums.txt.keyless.sig https://github.com/terraform-linters/tflint/releases/download/v${TFLINT_VERSION} /checksums.txt.keyless.sig
275+ set -e
276+
277+ # Check that checksums.txt.keyless.sig exists and is not empty
278+ if [ -s checksums.txt.keyless.sig ]; then
279+ # Validate checksums with cosign
280+ curl -sSL -o checksums.txt.pem https://github.com/terraform-linters/tflint/releases/download/v${TFLINT_VERSION} /checksums.txt.pem
281+ ensure_cosign
282+ cosign verify-blob \
283+ --certificate=/tmp/tf-downloads/checksums.txt.pem \
284+ --signature=/tmp/tf-downloads/checksums.txt.keyless.sig \
285+ --certificate-identity-regexp=" ^https://github.com/terraform-linters/tflint" \
286+ --certificate-oidc-issuer=https://token.actions.githubusercontent.com \
287+ /tmp/tf-downloads/tflint_checksums.txt
288+ # Ensure that checksums.txt has $TFLINT_FILENAME
289+ grep ${TFLINT_FILENAME} /tmp/tf-downloads/tflint_checksums.txt
290+ # Validate downloaded file
291+ sha256sum --ignore-missing -c tflint_checksums.txt
292+ else
293+ # Fallback to older, GPG-based verification (pre-0.47.0 of tflint)
294+ curl -sSL -o tflint_checksums.txt.sig https://github.com/terraform-linters/tflint/releases/download/v${TFLINT_VERSION} /checksums.txt.sig
295+ curl -sSL -o tflint_key " ${TFLINT_GPG_KEY_URI} "
296+ gpg -q --import tflint_key
297+ gpg --verify tflint_checksums.txt.sig tflint_checksums.txt
298+ fi
271299 fi
272300 fi
273301 fi
@@ -276,12 +304,10 @@ try_install_dummy_tflint_cosign_version() {
276304 sudo mv -f tflint /usr/local/bin/
277305}
278306
279- try_install_dummy_tflint_cosign_version " mode1"
307+ try_install_dummy_tflint_version " mode1"
280308
281309check " tflint version as installed when mode=1" tflint --version
282- check " cosign version as installed when mode=1" cosign version
283310
284- try_install_dummy_tflint_cosign_version " mode2"
311+ try_install_dummy_tflint_version " mode2"
285312
286313check " tflint version as installed when mode=2" tflint --version
287- check " cosign version as installed when mode=2" cosign version
0 commit comments