feat(security): consume-side hash verification in TF module#4
Merged
Conversation
added 2 commits
May 5, 2026 12:01
Closes the loop on PR 3's publish-side hardening. The Terraform module
now fetches SHA256SUMS at plan time and verifies each feed body's
sha256 against the manifest via postcondition. Default on; no-op in
local source_files mode (customer controls those bytes).
Module changes (terraform/main.tf, variables.tf):
- New input verify_checksums (bool, default true).
- New data "http" "checksums" — fetched once when verify is enabled.
- Parses GNU sha256sum format ("<64-hex> <filename>") into a map,
tolerates blank lines and # comments.
- Postcondition on data.http.feed: short-circuits when verify is off,
otherwise compares sha256(body) against the manifest entry.
- Error message names the URL, expected hash, actual hash, and the
fix path — pin to a known-good ref or set verify_checksums = false.
Tests (terraform/tests/checksums.tftest.hcl): 6 new mock-based runs
using override_data. No network — runs in seconds. Covers:
- Hash matches → output cidrs as expected
- Hash mismatch → fail with actionable error
- File missing from manifest → fail (lookup default empty string)
- verify_checksums = false → checksums data resource not instantiated
- Local source_files mode → checksum fetch silently suppressed
- Manifest with blank lines and # comments → parsed correctly
Total terraform tests: 15/15 (was 9/9). Python tests still 39/39.
Docs (terraform/README.md, SECURITY.md):
- README inputs table includes verify_checksums.
- Debugging table covers SHA256 mismatch and SHA256SUMS fetch failure
with explicit fix paths.
- Test coverage table updated.
- SECURITY.md "stricter" recommendation now points at the shipped
module behaviour rather than a planned PR. Future work list pruned.
Three-layer validation recipe — test suite (no network), manual SHA256SUMS check (curl + shasum), end-to-end terraform plan against the live URL. Captures the smoke-test pattern we used to prove the checksum verification chain works, so future contributors don't have to rediscover it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes the loop on PR 3's publish-side hardening. The Terraform module now fetches
SHA256SUMSat plan time and verifies each feed body'ssha256against the manifest via postcondition. Default on; no-op in localsource_filesmode (customer controls those bytes).What changes
Module (
terraform/main.tf,variables.tf)verify_checksums(bool, defaulttrue)data "http" "checksums"— fetched once when verification is enabled, with retry + 200-status postconditionsha256sumformat (<64-hex> <filename>) into amap[filename]hash. Tolerates blank lines and#commentsdata.http.feed: short-circuits when verify is off, otherwise comparessha256(self.response_body)against the manifest entry.lookup()with empty default makes "file not in manifest" a clean failure instead of a TF map-lookup errorverify_checksums = falseif the source intentionally doesn't publish a manifestTests (
terraform/tests/checksums.tftest.hcl)6 new mock-based runs using
override_data. No network — runs in seconds.verify_passes_when_hash_matchesverify_fails_on_hash_mismatchverify_fails_when_file_missing_from_manifestverify_checksums = false→ checksums data resource not instantiatedverify_disabled_skips_fetchsource_filesmode → checksum fetch silently suppressedverify_silently_skipped_in_local_mode#comments → parsedmanifest_with_blank_and_comment_lines_is_toleratedDocs
terraform/README.md— inputs table includesverify_checksums; debugging table coversSHA256 mismatchandFailed to fetch SHA256SUMSwith explicit fix paths; test coverage table updatedSECURITY.md— "stricter" recommendation now points at the shipped module behaviour; future work list prunedTest plan
terraform fmt -check -recursivepassesterraform validatepassesterraform test15/15 passing locally (was 9/9)python -m pytest39/39 passing (no regression)