Skip to content

chore(security): tighten Terraform provider constraints to exact pins#8019

Open
jordanconway wants to merge 1 commit into
pytorch:mainfrom
jordanconway:hardening/terraform-exact-pins
Open

chore(security): tighten Terraform provider constraints to exact pins#8019
jordanconway wants to merge 1 commit into
pytorch:mainfrom
jordanconway:hardening/terraform-exact-pins

Conversation

@jordanconway
Copy link
Copy Markdown
Contributor

Summary

Replace all loose ~> and >= provider version constraints across all 7 OpenTofu modules with exact = X.Y.Z pins. This eliminates silent provider drift — with loose constraints, every tofu init could install a different version than the last run, and a compromised new release matching the range would be picked up automatically.

⚠️ This PR requires human review before merging. Changing version constraints can cause tofu init to fail if the environment uses cached provider binaries from a different version. Please validate in a non-production environment first.

ℹ️ Dependency note: This PR includes .terraform.lock.hcl via git add -f because the companion PR #8018 removes the *.lock.hcl gitignore entry. Either PR can merge first; if this merges before #8018, the lockfiles are tracked via force-add. If #8018 merges first, the force-add here is redundant but harmless.


Changes

Provider pins — all 7 modules

Module Provider Old constraint New constraint Resolved version
root hashicorp/aws ~> 5.5 = 5.100.0 5.100.0
root hashicorp/random ~> 3.4.2 = 3.4.3 3.4.3
modules/webhook hashicorp/aws ~> 5.5 = 5.100.0 5.100.0
modules/download-lambda hashicorp/null ~> 3.2.1 = 3.2.4 3.2.4
modules/runners-instances hashicorp/aws ~> 5.5 = 5.100.0 5.100.0
modules/setup-iam-permissions hashicorp/aws ~> 5.5 = 5.100.0 5.100.0
modules/runners hashicorp/aws ~> 5.5 = 5.100.0 5.100.0
modules/runner-binaries-syncer hashicorp/aws ~> 5.5 = 5.100.0 5.100.0

All versions were verified against the OpenTofu registry and confirmed as the latest that satisfied each prior constraint. All providers are signed with HashiCorp key 0C0AF313E5FD9F80.

Intentionally unchanged: required_version

The required_version = ">= 1.5" directive (which governs the OpenTofu CLI binary) is left as-is. Pinning it to a single exact version would break anyone running a different tofu release without a coordinated team upgrade. A separate decision is recommended to align CI (tflint.yml currently installs 1.5.7) with the version in active use locally.

Lockfiles updated

Both .terraform.lock.hcl files are regenerated to reflect the updated constraints = field, keeping them consistent with the new exact pins.


Keeping providers up to date going forward

When a Dependabot PR bumps a provider (or you want to upgrade manually):

# 1. Update the = X.Y.Z version in the relevant main.tf
# 2. Reinitialise
cd terraform-aws-github-runner
tofu init -upgrade

# 3. Regenerate multi-platform lockfile hashes
tofu providers lock \
  -platform=linux_amd64 -platform=linux_arm64 \
  -platform=darwin_arm64 -platform=darwin_amd64

# 4. Commit both main.tf and .terraform.lock.hcl

This change is part of a broader supply-chain hardening effort following a repository audit. See https://github.com/jordanconway/package-manager-hardening for the full methodology.

Replace all loose ~> and >= provider version constraints with = exact
pins across all 7 modules. Exact pinning means only the one known-good
version can be installed — no silent drift to a newer release that may
not yet have been reviewed.

Provider versions pinned (derived from current registry latest that
satisfies each prior constraint, verified with tofu providers lock):

  hashicorp/aws    ~> 5.5    → = 5.100.0  (6 modules)
  hashicorp/random ~> 3.4.2  → = 3.4.3    (root module)
  hashicorp/null   ~> 3.2.1  → = 3.2.4    (modules/download-lambda)

required_version (>= 1.5) is intentionally left unchanged — this governs
the OpenTofu CLI binary version and changing it to an exact pin would
break anyone running a different tofu version without a coordinated
upgrade. A separate team decision is needed to align on a pinned CLI
version across local dev and CI.

Lockfiles (.terraform.lock.hcl) are regenerated to reflect the updated
exact constraints. This PR includes the lockfiles via git add -f because
the .gitignore fix (removing *.lock.hcl) is in a companion PR; once that
PR merges, the force-add here becomes unnecessary for future updates.

To update providers going forward:
  1. Change the version to the desired = X.Y.Z in the relevant main.tf
  2. Run: tofu init -upgrade
  3. Run: tofu providers lock -platform=linux_amd64 -platform=linux_arm64              -platform=darwin_arm64 -platform=darwin_amd64
  4. Commit both the updated main.tf and .terraform.lock.hcl

See https://github.com/jordanconway/package-manager-hardening for the
full hardening methodology.

Signed-off-by: Jordan Conway <jconway@linuxfoundation.org>
@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 28, 2026

@jordanconway is attempting to deploy a commit to the Meta Open Source Team on Vercel.

A member of the Team first needs to authorize it.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Apr 28, 2026
Copy link
Copy Markdown
Contributor

@malfet malfet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change LGTM, but I'm not sure why do you want to commit lock files, as they should not change across the runs, should they?

IMO one can have either strict constraints and no lockfiles (as they are redundant) or check in lockfiles but still have loose constraints, so that one can run an update command to change lockfile versions.

@jordanconway
Copy link
Copy Markdown
Contributor Author

@malfet Ideally they wouldn't change but because they do contain hashes of the registry zip and the extracted binary and it can help prevent tag push style takeovers. I've got some more information documented here https://github.com/jordanconway/package-manager-hardening/blob/main/docs/terraform.md#lockfile
Hashicorp Terraform engineers have also suggested that lockfiles should be committed https://discuss.hashicorp.com/t/how-should-we-be-using-dependency-lock-files-in-ci/31728/3
That said, imo tight version pinning is more important here than lockfiles and if it introduces too much complexity I could be convinced to drop them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants