GuardRail checks infrastructure during code review
Oct 5, 2026 · 6 min read
The finding that came back
No encryption configuration found.
The Terraform file has an encryption resource in it. GuardRail, the scanner I built, even suggests adding that kind of resource.
This comes from a small S3 test in the repo. I start with a file that passes, move two settings out of the bucket block, and run the same scan again. If this came back on my pull request, I’d open the diff and see the setting right there. Where did GuardRail look?
The PR I had in mind
In my SQS and Lambda post, the infrastructure is in Terraform too. The Lambda execution role and the maximum concurrency setting for the SQS event source are things you can read in a diff. I built GuardRail to catch infrastructure mistakes while the person making the change still had that diff open. Take a security group that allows SSH from 0.0.0.0/0. A reviewer can point to the line and ask who actually needs that access. I wanted the check to point them to the same line. My SQS and Lambda post · GuardRail’s unrestricted SSH example.
Checking infrastructure before deploy is established practice. Checkov scans Terraform source in CI, and HCP Terraform can check a plan against a policy before applying it. For GuardRail, I started with what the source file declares. Checkov · Terraform policy enforcement.
The change that turned the scan red
The original S3 example declares encryption and access logging inside aws_s3_bucket.logs. The public access block already lives in a resource of its own. The first scan produces four passes across three rule IDs. The public access rule runs on both the bucket and its access block. Original Terraform example.
In a copy, I move encryption and logging into their own Terraform resources. Both files declare the same bucket, AES256 encryption, and the same logging destination and prefix. For this test, I only run GuardRail against the source files.
| Finding | Original file | Settings in separate resources |
|---|---|---|
S3 encryption (SOC2-ENC-001) | PASS | FAIL |
S3 access logging (SOC2-LOG-001) | PASS | FAIL |
Public access on the bucket (SOC2-NET-001) | PASS | PASS |
Public access block settings (SOC2-NET-001) | PASS | PASS |
The logging result gives me a clue. GuardRail loses track of the two settings I moved. It still finds the public access block. I want to see the inputs to those rules before changing another line of Terraform.
Where GuardRail looked
I run the scan again with --explain and look at the facts for aws_s3_bucket.logs.
Encryption configured: False
Logging configured: False
Public access block present: True
The code that collects those facts looks inside the bucket block for encryption and logging. For public access it also searches the other resources in the same file. In this example it matches the access block to the bucket using the reference text aws_s3_bucket.logs.id. The two new resources point to that same ID. The code that reads encryption and logging stops at the bucket block. S3 fact collection.
The test I’d add to my own scanner
I’d take the two Terraform files straight into a regression test. Both should pass the same checks. I’d also add a version where the standalone encryption resource points to a different bucket. That one should still fail for logs. A quick fix that looks for any encryption block in the file would pass the wrong bucket too.
The wording of the finding matters. Encryption configured: False means the scanner found no declaration it recognized. S3 already encrypts new uploads with SSE-S3 by default. If a team requires an explicit SSE-KMS setting, the finding ought to say what it expected in Terraform. That’s a change the author can make and verify on the next scan. Amazon S3 default encryption.
Four rule IDs, one RDS check
GuardRail uses one function for RDS encryption across the SOC 2, CIS AWS Foundations, PCI DSS, and HIPAA packs. Terraform calls the setting storage_encrypted. CloudFormation calls it StorageEncrypted. The normalizer gives the rule one value to read from either format. The check looks for storage encryption and a configured KMS key. RDS facts · Local checks.
That gives me one place to fix the rule. It also gives me a way to figure out where to start when a result looks off. I open --explain and check the facts against the file. If the values look right, I read the rule. In the S3 test I can stop at the facts. The answer is in those two False values.
I’d give Bedrock the same S3 test
I also wanted to try writing the policy in prose. With Bedrock enabled for a bound policy, GuardRail sends one normalized resource description at a time through Amazon Bedrock’s ApplyGuardrail API. Bedrock checks claims from that description against a formal policy derived from written rules. In this example the description for the bucket still comes from the normalizer that missed the standalone resources. Bedrock can only work with the description I give it. AWS Automated Reasoning · GuardRail policy setup.
The repo tests the Bedrock client with a stub. For a live test, I’d send the descriptions from both versions and check which claims Bedrock evaluated. I’d also test a response with action NONE and no reasoning findings. GuardRail marks that as PASS today, so I’d want to see what evidence a reviewer gets with that result. Client tests · Result handling.
Try the two scans locally
This uses Python 3.11 or newer and pins the HCL parser to the version in the repo’s lockfile. Both scans run locally with --no-bedrock. Dependency lock.
git clone https://github.com/varad-more/guardrail-compliance-engine
cd guardrail-compliance-engine
git checkout --detach c6e29bae8d6c7cf3231eef5662d81b83a42cf023
python3 -m venv .venv
source .venv/bin/activate
python -m pip install -e . "python-hcl2==7.3.1"
guardrail scan examples/terraform/compliant-s3.tf \
--policy soc2-basic --no-bedrock --explain
cp examples/terraform/compliant-s3.tf split-s3.tf
In split-s3.tf, remove the inline server_side_encryption_configuration and logging blocks. Keep the bucket and its public access block as they are. Add these two resources.
resource "aws_s3_bucket_server_side_encryption_configuration" "logs" {
bucket = aws_s3_bucket.logs.id
rule {
apply_server_side_encryption_by_default {
sse_algorithm = "AES256"
}
}
}
resource "aws_s3_bucket_logging" "logs" {
bucket = aws_s3_bucket.logs.id
target_bucket = "central-log-bucket"
target_prefix = "guardrail/"
}
guardrail scan split-s3.tf --policy soc2-basic --no-bedrock --explain
What I’d turn on in CI
On my machine, guardrail diff --ref main --policy soc2-basic --no-bedrock scans the supported files changed relative to my local main. In GitHub Actions I’d start by reporting findings and upload the SARIF output if the repo uses code scanning. I’d go through unexpected findings in the first few reviews the same way I went through the S3 example. Local CLI · Example GitHub Actions workflow.
With guardrail scan, --fail-on-findings --severity-threshold HIGH made the split S3 file exit with code 1. The encryption finding alone was enough. Make that workflow a required check and someone can follow the scanner’s advice and still be unable to merge. Finding exit logic.
I’d keep the scan advisory while I fix the S3 check. The next run I want to see is both versions of the bucket passing and the version with encryption attached to the wrong bucket still failing.