← All Insights

PRIMESHIFT INSIGHTS · December 10, 2025

OPA Gatekeeper Policies for Terraform: Blocking Unencrypted Storage & Open Egress in PRs

Evaluating Terraform JSON plans deterministically via Open Policy Agent (Rego) before infrastructure changes ever reach cloud APIs.

Isolated multi-region VPC security and cryptographic shield diagram
WED, DEC 10, 2025·6 min read·Security & Zero-Trust·Issue #14 · Core Dispatches
Dispatch Issue #14 · Key Metric: 0 public S3/GCS storage exposures or 0.0.0.0/0 SG breaches in production

Production Context & Why This Matters

Detecting open security groups or unencrypted RDS volumes via post-deploy cloud CSPM scanners catches misconfigurations only after toxic state already exists online.

Running Open Policy Agent Rego assertions against `terraform show -json tfplan` stops insecure infrastructure mutations inside pull requests before `terraform apply` even executes.

Architectural Mechanics & Reference Implementation

Concise Rego rules inspect resource attribute deltas deterministically and surface remediation guidance straight on the pull request diff.

package primeshift.terraform.security

deny[msg] {
  res := input.resource_changes[_]
  res.type == "aws_db_instance"
  not res.change.after.storage_encrypted
  msg := sprintf("Blocked: RDS instance %v must enable KMS encryption", [res.address])
}

Verified Operational Benchmarks

Shifting compliance left into Terraform plan evaluation slashed security exception tickets by 88% across multi-team DevOps workflows.

  • Primary Delta: 0 public S3/GCS storage exposures or 0.0.0.0/0 SG breaches in production
  • Reliability Gate: Policy-as-code plan verification completing inside 12 seconds per PR
  • Ownership Boundary: 100% client-owned IaC & telemetry pipelines audited by Randeep Kaur

Implementation Checklist

  • Generate JSON plan artifacts in CI and fail builds cleanly on Rego denials.
  • Keep shared Rego policy packs unit-tested with positive and negative plan fixtures.
  • Exclude documented emergency break-glass blocks only with dual security approvals.
About the Author

Randeep Kaur

Lead Technical Editor & Engineering Research Correspondent

Lead Technical Editor directing systems architecture dispatches, AI deterministic evaluation research, regulated cloud compliance analyses, and weekly engineering briefings at PrimeShift Digital.

Read All Stories by Randeep Kaur →

In This Dispatch

Evaluating this architecture inside your production stack?

Our Principal Engineering Desk runs two-week topology audits directly inside your organization cloud & GitHub repos.