Skip to content
Back to skills

Infrastructure Policy As Code

ASecurity

Use when implementing policy as code for infrastructure.

  • 2 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added September 10, 2026
devopspythongodockerkubernetesterraformgitci/cdsecurity

Security analysis

A100/100

Scanned September 10, 2026

npx -y skills add LoopyLuci/Skills --skill infrastructure-policy-as-code --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Infrastructure Policy As Code?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Infrastructure Policy As Code
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/loopyluci-infrastructure-policy-as-code/badge)](https://www.skillsdirectory.com/skills/loopyluci-infrastructure-policy-as-code)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: infrastructure-policy-as-code
description: "Use when implementing policy as code for infrastructure."
version: 1.0.0
author: Hermes Agent
license: MIT
metadata:
  hermes:
    tags: [policy-as-code, OPA, Sentinel, Kyverno, conftest, compliance]
    related_skills: [gitops-argocd-flux, cloud-cost-optimization-finops, terraform-module-patterns, devsecops-shift-left]
---

# Infrastructure Policy as Code

Implementing policy as code — from OPA/Rego and Kyverno through compliance checks in CI/CD, admission controllers, and infrastructure governance.

## When to Use

- Enforcing infrastructure compliance (security, cost, naming)
- Automated policy checking in CI/CD pipelines
- Kubernetes admission control
- Multi-cloud policy governance
- Security and compliance automation

## Policy Engines

```python
POLICY_ENGINES = {
    'opa': 'Open Policy Agent — Rego language, versatile, CI + admission control',
    'kyverno': 'Kubernetes-native, YAML policies, mutate/validate/generate',
    'conftest': 'OPA-based, test configuration files in CI (Terraform, K8s, Docker)',
    'sentinel': 'HashiCorp — Terraform Cloud/Enterprise, policy-as-code for IaC',
}

# OPA/Rego example: enforce required labels
REGO_POLICY = """
package kubernetes.admission

deny[msg] {
    input.request.kind.kind == "Deployment"
    not input.request.object.metadata.labels.owner
    msg := "Deployments must specify 'owner' label"
}

deny[msg] {
    input.request.object.metadata.labels.environment
    env := input.request.object.metadata.labels.environment
    not env in ["dev", "staging", "prod"]
    msg := sprintf("Invalid environment: %v", [env])
}
"""

def check_with_conftest(config_path: str, policy_path: str) -> List[str]:
    import subprocess, json
    result = subprocess.run(
        ['conftest', 'test', config_path, '-p', policy_path, '--output', 'json'],
        capture_output=True, text=True
    )
    output = json.loads(result.stdout)
    return [f['message'] for f in output if not f.get('success', True)]
```

## Verification Checklist

- [ ] Policy engine selected (OPA, Kyverno, Conftest, Sentinel)
- [ ] Policies defined for security (public S3 buckets, privileged containers)
- [ ] Policies defined for cost (instance types, regions, tags)
- [ ] CI/CD integration (conftest in pipeline)
- [ ] Admission controller deployed (Kyverno/OPA Gatekeeper)
- [ ] Policy exceptions handling (break-glass procedure)
- [ ] Policy tests written (conftest test cases)

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.