Checking Infrastructure Compliance
Overview
Audit infrastructure configurations against compliance frameworks (CIS Benchmarks, SOC 2, HIPAA, PCI-DSS, GDPR) using policy-as-code tools like Open Policy Agent (OPA), Checkov, and tfsec. Generate compliance reports, identify violations, and produce remediation plans for Terraform, Kubernetes, and cloud provider configurations.
Prerequisites
- Policy-as-code tool installed:
checkov, tfsec, opa, or kube-bench
- Infrastructure-as-code files (Terraform, CloudFormation, Kubernetes manifests) in the project
- Cloud provider CLI authenticated with read access to resources
- Compliance framework requirements documented (CIS, SOC 2, HIPAA, PCI-DSS)
jq for parsing JSON policy outputs
Instructions
- Identify the applicable compliance framework(s) based on industry and data classification
- Scan Terraform files with
checkov -d . or tfsec . to detect misconfigurations
- Scan Kubernetes manifests for security issues: missing resource limits, privileged containers, missing network policies
- Validate IAM policies for least-privilege violations using cloud-native tools (
aws iam access-analyzer)
- Check encryption at rest and in transit: verify S3 bucket encryption, database TLS, and EBS volume encryption
- Audit logging configurations: confirm CloudTrail/Cloud Audit Logs are enabled and sent to immutable storage
- Generate a compliance report mapping each finding to the relevant control (e.g., CIS AWS 2.1.1)
- Produce remediation Terraform/YAML patches for each violation with severity ranking (Critical, High, Medium, Low)
- Set up CI/CD integration so compliance checks block merges on Critical/High violations
Output
- Compliance scan results in JSON/SARIF format for CI integration
- Markdown compliance report with control mappings and pass/fail status
- Remediation code patches (Terraform diffs, Kubernetes manifest updates)
- OPA/Rego policy files for custom organizational rules
- CI/CD pipeline step configuration for automated compliance gating
Error Handling
| Error |
Cause |
Solution |
checkov: no Terraform files found |
Scanner run from wrong directory |
Specify path explicitly with -d path/to/terraform/ |
tfsec: failed to parse HCL |
Syntax error in Terraform files |
Run terraform validate first to fix HCL syntax before compliance scan |
False positive on compliance check |
Rule too broad for the specific use case |
Add inline skip comments (#checkov:skip=CKV_AWS_18:Reason) or create a .checkov.yml skip list |
OPA policy evaluation error |
Rego syntax error or missing input data |
Test policies with opa eval -d policy.rego -i input.json and validate Rego syntax |
Scan timeout on large codebase |
Too many files or complex module references |
Use --compact mode, scan directories individually, or increase timeout limits |
Examples
- "Run a CIS Benchmark compliance check against all Terraform files and generate a report with remediation steps for Critical findings."
- "Create OPA policies that enforce: all S3 buckets must have encryption, all EC2 instances must have IMDSv2, and all security groups must not allow 0.0.0.0/0 ingress."
- "Scan Kubernetes manifests for PCI-DSS compliance: verify no privileged containers, all pods have resource limits, and network policies exist for every namespace."
Resources
1---
2name: checking-infrastructure-compliance
3description: 'Execute use when you need to work with compliance checking.
4
5 This skill provides compliance monitoring and validation with comprehensive guidance
6 and automation.
7
8 Trigger with phrases like "check compliance", "validate policies",
9
10 or "audit compliance".
11
12 '
13allowed-tools: Read, Write, Edit, Grep, Glob, Bash(cmd:*)
14version: 1.0.0
15author: Jeremy Longshore <jeremy@intentsolutions.io>
16license: MIT
17tags:
18- devops
19- monitoring
20- compliance
21- audit
22compatibility: Designed for Claude Code, also compatible with Codex and OpenClaw
23metadata:
24 source: https://skillmd.com/skills/aibot88/checking-infrastructure-compliance
25---
26
27# Checking Infrastructure Compliance
28
29## Overview
30
31Audit infrastructure configurations against compliance frameworks (CIS Benchmarks, SOC 2, HIPAA, PCI-DSS, GDPR) using policy-as-code tools like Open Policy Agent (OPA), Checkov, and tfsec. Generate compliance reports, identify violations, and produce remediation plans for Terraform, Kubernetes, and cloud provider configurations.
32
33## Prerequisites
34
35- Policy-as-code tool installed: `checkov`, `tfsec`, `opa`, or `kube-bench`
36- Infrastructure-as-code files (Terraform, CloudFormation, Kubernetes manifests) in the project
37- Cloud provider CLI authenticated with read access to resources
38- Compliance framework requirements documented (CIS, SOC 2, HIPAA, PCI-DSS)
39- `jq` for parsing JSON policy outputs
40
41## Instructions
42
431. Identify the applicable compliance framework(s) based on industry and data classification
442. Scan Terraform files with `checkov -d .` or `tfsec .` to detect misconfigurations
453. Scan Kubernetes manifests for security issues: missing resource limits, privileged containers, missing network policies
464. Validate IAM policies for least-privilege violations using cloud-native tools (`aws iam access-analyzer`)
475. Check encryption at rest and in transit: verify S3 bucket encryption, database TLS, and EBS volume encryption
486. Audit logging configurations: confirm CloudTrail/Cloud Audit Logs are enabled and sent to immutable storage
497. Generate a compliance report mapping each finding to the relevant control (e.g., CIS AWS 2.1.1)
508. Produce remediation Terraform/YAML patches for each violation with severity ranking (Critical, High, Medium, Low)
519. Set up CI/CD integration so compliance checks block merges on Critical/High violations
52
53## Output
54
55- Compliance scan results in JSON/SARIF format for CI integration
56- Markdown compliance report with control mappings and pass/fail status
57- Remediation code patches (Terraform diffs, Kubernetes manifest updates)
58- OPA/Rego policy files for custom organizational rules
59- CI/CD pipeline step configuration for automated compliance gating
60
61## Error Handling
62
63| Error | Cause | Solution |
64|-------|-------|---------|
65| `checkov: no Terraform files found` | Scanner run from wrong directory | Specify path explicitly with `-d path/to/terraform/` |
66| `tfsec: failed to parse HCL` | Syntax error in Terraform files | Run `terraform validate` first to fix HCL syntax before compliance scan |
67| `False positive on compliance check` | Rule too broad for the specific use case | Add inline skip comments (`#checkov:skip=CKV_AWS_18:Reason`) or create a `.checkov.yml` skip list |
68| `OPA policy evaluation error` | Rego syntax error or missing input data | Test policies with `opa eval -d policy.rego -i input.json` and validate Rego syntax |
69| `Scan timeout on large codebase` | Too many files or complex module references | Use `--compact` mode, scan directories individually, or increase timeout limits |
70
71## Examples
72
73- "Run a CIS Benchmark compliance check against all Terraform files and generate a report with remediation steps for Critical findings."
74- "Create OPA policies that enforce: all S3 buckets must have encryption, all EC2 instances must have IMDSv2, and all security groups must not allow 0.0.0.0/0 ingress."
75- "Scan Kubernetes manifests for PCI-DSS compliance: verify no privileged containers, all pods have resource limits, and network policies exist for every namespace."
76
77## Resources
78
79- Checkov: https://www.checkov.io/
80- tfsec: https://aquasecurity.github.io/tfsec/
81- Open Policy Agent: https://www.openpolicyagent.org/docs/latest/
82- CIS Benchmarks: https://www.cisecurity.org/cis-benchmarks
83- kube-bench (CIS for Kubernetes): https://github.com/aquasecurity/kube-bench