You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Implement the download, cryptographic verification (PGP signatures + SHA256 checksums), and zip extraction pipeline for Terraform binaries.
Parent Epic
Part of #488 — Go Edition: Full Feature Parity Implementation
Motivation
This is the security-critical component that downloads Terraform binaries from HashiCorp's release infrastructure, verifies their authenticity via PGP signatures and integrity via SHA256 checksums, and extracts them for installation. The Go edition embeds the HashiCorp PGP key at compile time, eliminating the Bash edition's fragile 3-tier verification fallback (keybase → gpgv → gpg).
Clean-Room Constraint
This is a clean-room implementation. Contributors MUST NOT read, reference, copy, or adapt source code from tofuutils/tenv, hashicorp/hc-install, or any other third-party tfenv-like tool. The sole reference is tfenv's own Bash source code, documentation, and test suite.
Proposed Design
Package Location
go/internal/install/ (download and verification components)
Override mechanism: TFENV_PGP_KEY_PATH (or similar) allows users to supply a custom key for private mirrors.
PGP Verification Library
Evaluate ProtonMail/gopenpgp or golang.org/x/crypto/openpgp (deprecated but functional) for signature verification. The choice should prioritise correctness, maintenance status, and minimal dependency footprint.
SHA256 Verification
Parse the SHA256SUMS file to find the checksum for the target platform's zip
Compute SHA256 of downloaded zip using crypto/sha256
Compare (constant-time) against expected checksum
Zip Extraction
Use archive/zip stdlib to extract the terraform binary from the zip
Set executable permissions on the extracted binary (0755)
Handle single-file zips (Terraform zips contain only the terraform binary)
Handle Windows: extract terraform.exe
Security: path traversal protection. Reject zip entries with .. path components or absolute paths to prevent zip-slip attacks
Atomic Install
Downloads should go to a temporary directory first. Only after ALL verification passes (PGP + SHA256), the binary is moved to the final ${TFENV_CONFIG_DIR}/versions/${version}/ location. This prevents partially-installed or unverified binaries from being visible.
Bash Edition Verification Modes (for reference)
The Bash edition has a 3-tier PGP verification fallback. The Go edition eliminates this complexity entirely:
Bash Mode
Mechanism
Go Edition Equivalent
use-gnupg config file
User's GnuPG keyring
Not supported — use embedded key
use-gpgv config file
gpgv with optional tfenv trust
Not supported — use embedded key
Keybase installed + following hashicorp
keybase pgp verify
Not supported — use embedded key
None of the above
No PGP verification (SHA256 only)
Always verified — key is embedded
The Go edition always verifies PGP signatures because the key is compiled into the binary. This is a security improvement over the Bash edition where most users have no PGP verification at all.
Summary
Implement the download, cryptographic verification (PGP signatures + SHA256 checksums), and zip extraction pipeline for Terraform binaries.
Parent Epic
Part of #488 — Go Edition: Full Feature Parity Implementation
Motivation
This is the security-critical component that downloads Terraform binaries from HashiCorp's release infrastructure, verifies their authenticity via PGP signatures and integrity via SHA256 checksums, and extracts them for installation. The Go edition embeds the HashiCorp PGP key at compile time, eliminating the Bash edition's fragile 3-tier verification fallback (keybase → gpgv → gpg).
Clean-Room Constraint
This is a clean-room implementation. Contributors MUST NOT read, reference, copy, or adapt source code from
tofuutils/tenv,hashicorp/hc-install, or any other third-party tfenv-like tool. The sole reference is tfenv's own Bash source code, documentation, and test suite.Proposed Design
Package Location
go/internal/install/(download and verification components)Download Pipeline
For a given version and platform:
${TFENV_REMOTE}/terraform/${version}/terraform_${version}_SHA256SUMS${TFENV_REMOTE}/terraform/${version}/terraform_${version}_SHA256SUMS.sig${TFENV_REMOTE}/terraform/${version}/terraform_${version}_${os}_${arch}.zip${TFENV_CONFIG_DIR}/versions/${version}/URL and Filename Conventions
Standard tarball naming:
0.12.0-alpha edge case: Versions
0.12.0-alpha3through0.12.0-alpha9use a double-prefixed filename:Reference:
libexec/tfenv-installline 194.SHA256SUMS file:
Signature file naming: The signature filename includes a key ID postfix:
Note the
.72D7468Fpostfix is the PGP key fingerprint suffix. Reference:libexec/tfenv-installline 199.PGP Key Embedding
The HashiCorp PGP public key is embedded at compile time:
Override mechanism:
TFENV_PGP_KEY_PATH(or similar) allows users to supply a custom key for private mirrors.PGP Verification Library
Evaluate
ProtonMail/gopenpgporgolang.org/x/crypto/openpgp(deprecated but functional) for signature verification. The choice should prioritise correctness, maintenance status, and minimal dependency footprint.SHA256 Verification
SHA256SUMSfile to find the checksum for the target platform's zipcrypto/sha256Zip Extraction
archive/zipstdlib to extract theterraformbinary from the zip0755)terraformbinary)terraform.exe..path components or absolute paths to prevent zip-slip attacksAtomic Install
Downloads should go to a temporary directory first. Only after ALL verification passes (PGP + SHA256), the binary is moved to the final
${TFENV_CONFIG_DIR}/versions/${version}/location. This prevents partially-installed or unverified binaries from being visible.Bash Edition Verification Modes (for reference)
The Bash edition has a 3-tier PGP verification fallback. The Go edition eliminates this complexity entirely:
use-gnupgconfig fileuse-gpgvconfig filegpgvwith optional tfenv trustkeybase pgp verifyThe Go edition always verifies PGP signatures because the key is compiled into the binary. This is a security improvement over the Bash edition where most users have no PGP verification at all.
HTTP Downloads
net/httpwith configurable timeoutHTTPS_PROXY, etc.)TFENV_NETRC_PATHfor authenticated mirrorsTFENV_CURL_OUTPUTcontrols download progress display (mapping to Go progress reporting)tfenv/<version>Error Handling
Every step must fail clearly:
Acceptance Criteria
terraformbinary in correct versions directoryterraform.execorrectlyTFENV_REMOTEis used as the base URL for all downloadsTFENV_NETRC_PATHenables authenticated downloads//go:embedis used for the HashiCorp PGP key fromshare/hashicorp-keys.pgp.72D7468Fkey ID postfix..path components (zip-slip protection)Dependencies
TFENV_REMOTE,TFENV_CONFIG_DIR,TFENV_NETRC_PATHImplementation Notes
libexec/tfenv-installfor the full Bash download/verify/extract flowlib/helpers.shforcurlw()and the PGP/SHA256 verification logicunzip— the Go edition usesarchive/zipstdlibshasum -a 256orsha256sum— the Go edition usescrypto/sha256TFENV_SKIP_REMOTE_CHECKto skip download verification in air-gapped environments with pre-populated versions directoryLabels
type:feature,priority:high,complexity:large,category:verification