Verify Terraform binary archives
Hackers can gain access to your critical systems by tricking you into running an executable that includes malicious code. You can avoid this by verifying that HashiCorp created and signed the Terraform executable before you run it.
In this tutorial, you will download a version of the Terraform archive, and verify that no one has tampered with it since HashiCorp created it.
To install Terraform on your system, follow our installation tutorial. The steps in this tutorial will not replace the version of Terraform on your system, if any.
Prerequisites
You will need the following to complete this tutorial.
- The
curl
command line tool, to download files to your local machine. - The
gpg
command line tool, to import and verify HashiCorp's PGP key. - The
shasum
command line tool, to verify the checksum of your Terraform archive file. The shasum command is sometimes distributed along with thegpg
command, or as part of GNU coreutils.
Create a working directory
Make a temporary directory to save your work.
Change into that directory.
Create a temporary GPG configuration
Create a temporary GPG configuration directory and key so that you can follow this tutorial without affecting your personal GPG configuration. If you would rather use your real GPG configuration to verify the Terraform archive, skip this step.
First, configure gpg
to use a temporary directory to hold your configuration
and keys instead of the default directory.
Next create a temporary personal key using a blank passphrase and example email address. You will use this personal key to sign HashiCorp's key in the next step.
Warning
Do not use a blank passphrase or example email address for permanent GPG keys. You are doing so in this tutorial so that you can quickly generate an example key that you will not use for real work.
Download and import HashiCorp's public key
HashiCorp uses a public PGP key to sign certain files, including the checksums for Terraform archives. You can find HashiCorp's public keys on HashiCorp's security page, and HashiCorp also publishes them to Keybase.
Download HashiCorp's public keys from Keybase.io.
Import the keys into your GPG keychain.
Now sign the key with the temporary one you created in the last step. You can
compare this key ID to the one found on HashiCorp's security
page. Respond to the confirmation prompt
with a y
.
Verify PGP key ID and fingerprint
Verify the public key ID and fingerprint with gpg
.
Verify that the fingerprint (C874 011F 0AB4 0511 0D02 1055 3436 5D94 72D7 468F
)
and key ID (34365D9472D7468F
) match those shown in the PGP Public Keys section
of our security page.
Download Terraform archive and checksums
Download an archive of the Terraform CLI from HashiCorp's release
server. You can follow these steps
with any Terraform release, but this tutorial uses the MacOS (darwin
) release
of Terraform v0.15.3 as an example.
Now download the SHA 256 checksums for this version of Terraform. This file contains checksums for each Terraform archive for this version.
Also download the checksum signature file. This file contains a signature of the checksums file, signed with HashiCorp's PGP key.
HashiCorp releases these files along with the Terraform binary archives for each version.
Verify checksum and signature files
Verify that HashiCorp created the signature file using its private PGP key, and that no one has tampered with it since.
Note the line starting with gpg: Good signature...
. This line tells you that
the signature matches the HashiCorp's public key, which you downloaded from
Keybase. Since you signed HashiCorp's key with your personal key earlier in the
tutorial, gpg fully trusts HashiCorp's key.
Verify Terraform archive
Verify the SHA 256 checksum of the Terraform archive you downloaded.
The SHA256SUMS file contains checksums for each Terraform release archive file for the indicated version. For this tutorial, you only downloaded the darwin_amd64 (MacOS) release. The shasum command prints out an "OK" message for that file, and "No such file or directory" for the others.
Now you have verified that no one has tampered with the Terraform archive file since HashiCorp created it, because its checksum matches the one that HashiCorp provides. You also verified that no one tampered with the checksum file itself, since HashiCorp signed it with the appropriate key.
Unset GNUPGHOME environment variable
Unset the GNUPGHOME
environment variable that you configured earlier.
Next steps
For more information on topics covered in this tutorial, check out the following resources.
Manage Terraform Versions as part of a team.
Review HashiCorp's security page for more information about security and HashiCorp products.