Articles

Testing cloud security guardrails before deployment

Using deliberate Terraform fixtures to test public-access controls, SSH exposure, encryption and logging before connecting the checks to CI.

TerraformConftestPolicy testing
In this article

Why test the guardrail itself?

An infrastructure check is only useful when it rejects the configuration it is meant to catch and accepts an appropriate alternative. A green result on one example does not show that the policy can distinguish the two.

In this lab, I used fictional Terraform configurations to make that distinction explicit. The checks ran locally, before any AWS deployment. The aim was to validate a small set of security requirements and preserve their output as evidence.

Four deliberate configuration changes

Each area had an insecure fixture and a corrected counterpart. Conftest evaluated the policies against both, so the recorded result could be checked against the intended behavior.

  • S3 public access: require the public-access block settings to be explicitly enabled.
  • SSH exposure: reject a security-group example that exposes SSH to 0.0.0.0/0.
  • EBS encryption: require encryption to be explicitly enabled in the volume example.
  • CloudTrail logging: reject the example in which logging is disabled.

What the saved evidence shows

The insecure S3 fixture produced four failed policy assertions. The insecure SSH, EBS and CloudTrail fixtures each produced a failure matching the intended requirement. Their corrected counterparts had no reported failures. The saved policy unit-test output also recorded ten passing tests.

These counts belong to the supplied fixtures and recorded local runs. Test totals vary between fixtures, so they are not a comparable security score. I have not treated the output as a live cloud assessment or rerun it as part of preparing this write-up.

A useful boundary for automation

The broader Cloud Security Quality Gate project brings these Terraform checks together with Parliament for IAM-policy analysis and Gitleaks for secret detection. They inspect different kinds of evidence and should retain separate findings and limitations.

The public project records local experimental validation as complete, with GitHub Actions integration testing still in progress. Until the workflow itself is exercised, local policy results should not be presented as proof that a pull request will be blocked correctly.

What I would validate next

I would add malformed and incomplete inputs, more legitimate configurations, and regression cases for every policy change. Then I would test the CI workflow with both passing and deliberately failing changes, checking its exit status, report preservation and behavior when a tool fails to run.

The useful outcome is a set of small, explainable checks whose behavior can be reproduced. It is evidence about configured requirements, not a claim that the infrastructure is completely secure.