Compliance-as-Code Governance
Overview
This skill codifies compliance controls as executable policy integrated into CI/CD and runtime admission. It bridges SOC 2 CC8 (change management), CC5 (control activities), HIPAA §164.312 (technical safeguards), and PCI Req 2 (secure configurations) through:
- OPA/Rego policies for Kubernetes, API gateways, and custom resources
- Terraform/IaC scanning (Checkov, tfsec, terraform-compliance)
- Git-pre-merge gates blocking non-compliant infrastructure
- Policy versioning aligned with TSC control matrix
Compliance-as-code is not a substitute for auditor evidence—it generates continuous proof consumed by soc2-ccm-continuous-monitoring and soc2-evidence-collection.
When to Use
Use this skill when:
- Codifying security baselines (encryption, public access, MFA) as OPA/Rego or scan rules
- Adding CI gates for Terraform, Kubernetes manifests, or MCP server configs
- Remediating drift detected by CCM with policy updates
- Standardizing agent deployment guardrails (skills validation, redaction required)
- Mapping policy rules to TSC/PCI/HIPAA control IDs for traceability
- Building exception workflows for time-bound policy waivers with approval
Do not use this skill when:
- Legal BAA negotiation (use
hipaa-baa-vendor-assessment)
- Initial TSC gap analysis without automation intent (use
soc2-trust-services-criteria)
- Payment page script inventory (use
pci-dss-script-audit)
Core Process
Execute steps in order.
Step 1: Policy scope and control mapping
- Import control requirements from TSC matrix, PCI Req 1-2, HIPAA §164.312.
- Select automatable controls (encryption flags, SG rules, IAM policies, public exposure).
- Create traceability matrix:
| Policy ID |
Rego/scan rule |
Control ID |
Severity |
| POL-S3-001 |
deny public S3 ACL |
CC6.1, PCI 1.3 |
CRITICAL |
| POL-IAM-002 |
require MFA for admin |
CC6.1, PCI 8.4 |
HIGH |
| POL-AGENT-003 |
redaction gate in agent.py |
HIPAA §164.312(e) |
CRITICAL |
Artifact: policy-control-matrix-{id}.csv.
Step 2: OPA/Rego policy development
- Organize policies in
policy/ directory with package naming convention:package compliance.soc2.cc6
- Write Rego rules with deny messages citing control ID:
deny[msg] {
input.resource.type == "aws_s3_bucket"
input.resource.public_access == true
msg := "CC6.1/PCI1.3: S3 bucket must not allow public access"
}
- Include unit tests (
*_test.rego) with positive and negative cases.
- Version policies in git; tag releases aligned with baseline promotions.
Step 3: Terraform/IaC scanning
- Configure Checkov or tfsec with custom checks mapped to policy IDs.
- Scan targets: VPC, SG, IAM, RDS, EKS, MCP deployment modules.
- Fail CI on CRITICAL/HIGH unless documented exception ID present in resource tag:
ComplianceException = EX-2025-042
- Export SARIF/JSON for evidence store.
Step 4: CI/CD pipeline integration
- Pipeline stages:
- Lint: Rego compilation, policy tests
- Plan scan: Terraform plan JSON → OPA evaluation
- Apply gate: manual approval for production with policy summary
- Agent-specific gates:
SkillsCapability(validate=True) must remain enabled in agent.py
redactor.redact() must precede compliance_agent.run() (static analysis or AST check)
- New
skills/*/SKILL.md must pass schema validation
- Block merge on policy failure—no
--no-verify bypass without security approval.
Step 5: Runtime admission (optional)
- Deploy OPA as admission controller (Kubernetes) or API gateway plugin.
- Enforce policies on MCP server deployments: resource limits, network policies, secret mounts.
- Log deny decisions to SIEM for CC7 evidence.
Step 6: Exception management
- Exception request requires: control ID, risk analysis, approver, expiry date (max 90 days default).
- Tag affected resources; CCM monitors exception expiry.
- Expired exceptions → auto-FAIL in CCM dashboard.
Step 7: Drift remediation loop
- When CCM detects drift, determine if:
- Policy gap (update Rego)
- Unauthorized change (incident)
- Authorized change (update baseline)
- Link remediation PR to control ID and evidence hash post-merge.
Step 8: Evidence and reporting
- Store CI scan outputs with SHA-256 in evidence bucket.
- Monthly report: policy pass rate, top violations, mean time to remediate.
- Feed
soc2-evidence-collection for CC8 change and CC5 control activity samples.
Common Rationalizations
| Excuse the agent might generate |
Required rebuttal |
| "Policy-as-code replaces SOC 2 audits." |
It automates control testing—auditors still require design/operating effectiveness assessment. |
| "We'll scan Terraform in prod only." |
Policies must run at plan/PR stage—post-deploy scanning is too late for prevention. |
| "OPA is too complex; manual checklist is enough." |
Manual checklists don't scale and fail CC8 consistency—codify repeatable rules. |
| "Exception tags are technical debt we ignore." |
Untracked exceptions are audit findings—require expiry and approval workflow. |
| "Agent redaction can't be policy-checked." |
Static analysis can verify call order in agent.py—implement POL-AGENT-003. |
| "Critical findings can merge with a JIRA link later." |
CRITICAL policy failures must block merge until fixed or formal exception recorded. |
Red Flags
- Terraform apply without plan-time policy scan
- Public cloud resources deployed with
ComplianceException tag and no ticket
- OPA policies without unit tests or version control
- Agent deployment bypasses redaction gate in CI
- Policy matrix missing mapping to control IDs (orphan rules)
- Exception expiry dates passed with no remediation
- Scan results stored only in ephemeral CI logs (no evidence retention)
Verification
1---2name: compliance-as-code-governance3description: Implements policy-as-code and infrastructure compliance scanning—OPA/Rego policies, Terraform static analysis, CI gates, and drift remediation—for SOC 2, HIPAA, and PCI control enforcement. Trigger when codifying security policies, integrating Checkov/tfsec/Sentinel, or automating guardrails for agent/MCP deployments. Do not use for one-time manual audits (use framework-specific skills) or vendor BAA review (use hipaa-baa-vendor-assessment).4---56# Compliance-as-Code Governance78## Overview910This skill codifies compliance controls as **executable policy** integrated into CI/CD and runtime admission. It bridges **SOC 2 CC8** (change management), **CC5** (control activities), **HIPAA §164.312** (technical safeguards), and **PCI Req 2** (secure configurations) through:1112- **OPA/Rego** policies for Kubernetes, API gateways, and custom resources13- **Terraform/IaC scanning** (Checkov, tfsec, terraform-compliance)14- **Git-pre-merge gates** blocking non-compliant infrastructure15- **Policy versioning** aligned with TSC control matrix1617Compliance-as-code is **not** a substitute for auditor evidence—it generates **continuous proof** consumed by `soc2-ccm-continuous-monitoring` and `soc2-evidence-collection`.1819## When to Use2021Use this skill when:2223- **Codifying** security baselines (encryption, public access, MFA) as OPA/Rego or scan rules24- Adding **CI gates** for Terraform, Kubernetes manifests, or MCP server configs25- **Remediating drift** detected by CCM with policy updates26- Standardizing **agent deployment** guardrails (skills validation, redaction required)27- Mapping **policy rules to TSC/PCI/HIPAA** control IDs for traceability28- Building **exception workflows** for time-bound policy waivers with approval2930Do **not** use this skill when:3132- Legal BAA negotiation (use `hipaa-baa-vendor-assessment`)33- Initial TSC gap analysis without automation intent (use `soc2-trust-services-criteria`)34- Payment page script inventory (use `pci-dss-script-audit`)3536## Core Process3738Execute steps **in order**.3940### Step 1: Policy scope and control mapping41421. Import control requirements from TSC matrix, PCI Req 1-2, HIPAA §164.312.432. Select **automatable** controls (encryption flags, SG rules, IAM policies, public exposure).443. Create traceability matrix:4546| Policy ID | Rego/scan rule | Control ID | Severity |47| --- | --- | --- | --- |48| POL-S3-001 | deny public S3 ACL | CC6.1, PCI 1.3 | CRITICAL |49| POL-IAM-002 | require MFA for admin | CC6.1, PCI 8.4 | HIGH |50| POL-AGENT-003 | redaction gate in agent.py | HIPAA §164.312(e) | CRITICAL |5152Artifact: `policy-control-matrix-{id}.csv`.5354### Step 2: OPA/Rego policy development55561. Organize policies in `policy/` directory with package naming convention:57 ```58 package compliance.soc2.cc659 ```602. Write Rego rules with **deny** messages citing control ID:61 ```rego62 deny[msg] {63 input.resource.type == "aws_s3_bucket"64 input.resource.public_access == true65 msg := "CC6.1/PCI1.3: S3 bucket must not allow public access"66 }67 ```683. Include **unit tests** (`*_test.rego`) with positive and negative cases.694. Version policies in git; tag releases aligned with baseline promotions.7071### Step 3: Terraform/IaC scanning72731. Configure Checkov or tfsec with custom checks mapped to policy IDs.742. Scan targets: VPC, SG, IAM, RDS, EKS, MCP deployment modules.753. Fail CI on CRITICAL/HIGH unless documented exception ID present in resource tag:76 `ComplianceException = EX-2025-042`774. Export SARIF/JSON for evidence store.7879### Step 4: CI/CD pipeline integration80811. Pipeline stages:82 - **Lint**: Rego compilation, policy tests83 - **Plan scan**: Terraform plan JSON → OPA evaluation84 - **Apply gate**: manual approval for production with policy summary852. Agent-specific gates:86 - `SkillsCapability(validate=True)` must remain enabled in `agent.py`87 - `redactor.redact()` must precede `compliance_agent.run()` (static analysis or AST check)88 - New `skills/*/SKILL.md` must pass schema validation893. Block merge on policy failure—no `--no-verify` bypass without security approval.9091### Step 5: Runtime admission (optional)92931. Deploy OPA as admission controller (Kubernetes) or API gateway plugin.942. Enforce policies on MCP server deployments: resource limits, network policies, secret mounts.953. Log deny decisions to SIEM for CC7 evidence.9697### Step 6: Exception management98991. Exception request requires: control ID, risk analysis, approver, expiry date (max 90 days default).1002. Tag affected resources; CCM monitors exception expiry.1013. Expired exceptions → auto-FAIL in CCM dashboard.102103### Step 7: Drift remediation loop1041051. When CCM detects drift, determine if:106 - Policy gap (update Rego)107 - Unauthorized change (incident)108 - Authorized change (update baseline)1092. Link remediation PR to control ID and evidence hash post-merge.110111### Step 8: Evidence and reporting1121131. Store CI scan outputs with SHA-256 in evidence bucket.1142. Monthly report: policy pass rate, top violations, mean time to remediate.1153. Feed `soc2-evidence-collection` for CC8 change and CC5 control activity samples.116117## Common Rationalizations118119| Excuse the agent might generate | Required rebuttal |120| --- | --- |121| "Policy-as-code replaces SOC 2 audits." | It **automates control testing**—auditors still require design/operating effectiveness assessment. |122| "We'll scan Terraform in prod only." | Policies must run at **plan/PR stage**—post-deploy scanning is too late for prevention. |123| "OPA is too complex; manual checklist is enough." | Manual checklists don't scale and fail **CC8** consistency—codify repeatable rules. |124| "Exception tags are technical debt we ignore." | Untracked exceptions are **audit findings**—require expiry and approval workflow. |125| "Agent redaction can't be policy-checked." | Static analysis can verify call order in `agent.py`—implement POL-AGENT-003. |126| "Critical findings can merge with a JIRA link later." | CRITICAL policy failures must **block merge** until fixed or formal exception recorded. |127128## Red Flags129130- Terraform apply without plan-time policy scan131- Public cloud resources deployed with `ComplianceException` tag and no ticket132- OPA policies without unit tests or version control133- Agent deployment bypasses redaction gate in CI134- Policy matrix missing mapping to control IDs (orphan rules)135- Exception expiry dates passed with no remediation136- Scan results stored only in ephemeral CI logs (no evidence retention)137138## Verification139140- [ ] Policy-control traceability matrix complete with severity levels141- [ ] OPA/Rego policies written with unit tests and git versioning142- [ ] Terraform/IaC scanning integrated in CI with CRITICAL/HIGH block rules143- [ ] Agent-specific gates verify skills validation and redaction call order144- [ ] Exception workflow documented with max expiry and approver roles145- [ ] Runtime admission deployed (if in scope) with deny logging to SIEM146- [ ] CCM integration feeds drift events into remediation loop147- [ ] Monthly policy compliance report generated with pass rates148- [ ] Scan artifacts retained with SHA-256 for SOC 2 evidence149- [ ] No CRITICAL violations in production without active approved exception