cloud-platform-skills / skills
Cursor rule1 starsChanged 3 months agoMITView on GitHub
Policy as code for Kubernetes and infrastructure: authoring Kyverno ClusterPolicy rules, OPA Rego in a Gatekeeper ConstraintTemplate, and Conftest checks, plus Pod Security Standards enforcement, policy unit testing, and an owned exception register with expiry dates. Use when privileged containers or pods without resource limits must be rejected at admission rather than reported, when admission policies need tests so a rule cannot silently stop matching, or when choosing between Kyverno and OPA Gatekeeper.
Where files are headingNew Cursor rule files have more rules about planning and tracking tasks, and fewer about code style.
Of the Cursor rule files we read, the 1,527 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository167 other files it gives its agents.
- AGENTS.mdAGENTS.md
- .agents/rules/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- .github/copilot-instructions.mdCopilot instructions
- .cursor/rules/00-index.mdcCursor rule
- .cursor/rules/skills/ai-agent-security-llm-threats.mdcCursor rule
- .cursor/rules/skills/api-gateway-service-mesh.mdcCursor rule
- .cursor/rules/skills/aws-cloud-migration-strategies.mdcCursor rule
- .cursor/rules/skills/aws-eks-enterprise-patterns.mdcCursor rule
- .cursor/rules/skills/aws-iam-zero-trust-policies.mdcCursor rule
- .cursor/rules/skills/azure-aks-enterprise-landing-zones.mdcCursor rule
- .cursor/rules/skills/azure-cloud-engineering-patterns.mdcCursor rule
- .cursor/rules/skills/backup-and-disaster-recovery.mdcCursor rule
- .cursor/rules/skills/chaos-engineering-resilience-testing.mdcCursor rule
- .cursor/rules/skills/cicd-pipeline-design.mdcCursor rule
- .cursor/rules/skills/cloud-native-microservices-patterns.mdcCursor rule
- .cursor/rules/skills/cloud-security-posture-cspm-cis.mdcCursor rule
- .cursor/rules/skills/configuration-management-ansible.mdcCursor rule
- .cursor/rules/skills/container-runtime-security-falco.mdcCursor rule
- .cursor/rules/skills/database-devops-lifecycle.mdcCursor rule
- .cursor/rules/skills/detection-engineering-threat-hunting.mdcCursor rule
- .cursor/rules/skills/devops-metrics-dora-kpis.mdcCursor rule
- .cursor/rules/skills/docker-containerization-basics.mdcCursor rule
- .cursor/rules/skills/enterprise-iac-governance-terragrunt.mdcCursor rule
- .cursor/rules/skills/finops-framework-inform-optimize-operate.mdcCursor rule
- .cursor/rules/skills/gcp-cloud-engineering-patterns.mdcCursor rule
- .cursor/rules/skills/gcp-gke-autopilot-multi-tenant.mdcCursor rule
- .cursor/rules/skills/git-branching-merge-strategies.mdcCursor rule
- .cursor/rules/skills/gitops-multi-cluster-argo-flux.mdcCursor rule
- .cursor/rules/skills/helm-kubernetes-deployment.mdcCursor rule
- .cursor/rules/skills/incident-management-and-postmortem.mdcCursor rule
- .cursor/rules/skills/infrastructure-host-monitoring.mdcCursor rule
- .cursor/rules/skills/internal-developer-portal-backstage.mdcCursor rule
- .cursor/rules/skills/linux-sysadmin-troubleshooting.mdcCursor rule
- .cursor/rules/skills/performance-load-testing.mdcCursor rule
- .cursor/rules/skills/prometheus-grafana-otel-tracing.mdcCursor rule
- .cursor/rules/skills/scalability-high-availability-patterns.mdcCursor rule
- .cursor/rules/skills/scripting-and-automation.mdcCursor rule
- .cursor/rules/skills/secops-incident-triage-forensics.mdcCursor rule
- .cursor/rules/skills/secrets-management-vault-kms.mdcCursor rule
- .cursor/rules/skills/serverless-event-driven-architecture.mdcCursor rule
- .cursor/rules/skills/shift-left-security-sast-sca.mdcCursor rule
- .cursor/rules/skills/sli-slo-error-budget-design.mdcCursor rule
- .cursor/rules/skills/supply-chain-security-slsa-sigstore.mdcCursor rule
- .cursor/rules/skills/terraform-iac-modules.mdcCursor rule
- .cursor/rules/skills/write-a-skill.mdcCursor rule
- .cursor/rules/skills/zero-downtime-release-strategies.mdcCursor rule
- ai-agent-security-llm-threatsSkill
- api-gateway-service-meshSkill
- aws-cloud-migration-strategiesSkill
- aws-eks-enterprise-patternsSkill
- aws-iam-zero-trust-policiesSkill
- azure-aks-enterprise-landing-zonesSkill
- azure-cloud-engineering-patternsSkill
- backup-and-disaster-recoverySkill
- chaos-engineering-resilience-testingSkill
- cicd-pipeline-designSkill
- cloud-native-microservices-patternsSkill
- cloud-security-posture-cspm-cisSkill
- configuration-management-ansibleSkill
- The first 60 shown.
The file
We split this policy-as-code-opa-kyverno.mdc into the rules it gives an agent
3 rules. About 0 are common, 3 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 116
Do not run both engines for overlapping concerns.
- Distinctive: line 144
Test the policies themselves — a guardrail with no test is a guardrail that silently stops matching.
- Distinctive: line 172
Every exception needs an owner, an expiry, and a reason.
≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
---
description: "Policy as code for Kubernetes and infrastructure: authoring Kyverno ClusterPolicy rules, OPA Rego in a Gatekeeper ConstraintTemplate, and Conftest checks, plus Pod Security Standards enforcement, policy unit testing, and an owned exception register with expiry dates. Use when privileged containers or pods without resource limits must be rejected at admission rather than reported, when admission policies need tests so a rule cannot silently stop matching, or when choosing between Kyverno and OPA Gatekeeper."
globs:
alwaysApply: false
---
# Policy as Code: Kyverno, OPA/Gatekeeper, and Conftest
## When to Use This Skill
**Triggers — load this skill when:**
- Privileged containers, missing limits, or untagged resources must be blocked, not reported
- Admission policies need unit tests, because an untested rule silently stops matching
- Kubernetes needs Pod Security Standards enforced with real exceptions for real workloads
- Kyverno versus OPA/Gatekeeper has to be decided for a platform
**Route elsewhere when:**
- Verifying image signatures and provenance specifically -> `supply-chain-security-slsa-sigstore`
- Cloud account posture scanning after the fact -> `cloud-security-posture-cspm-cis`
- Terraform repository layout and module structure -> `terraform-iac-modules`
- Multi-account IaC governance and CI gating at scale -> `enterprise-iac-governance-terragrunt`
- Runtime behaviour detection rather than admission -> `container-runtime-security-falco`
## 1. Start with Pod Security Standards, then add policy for what they miss
Pod Security Admission is built in, costs nothing, and covers most container-hardening rules. Use it
as the baseline and reserve a policy engine for what PSA cannot express.
```yaml
apiVersion: v1
kind: Namespace
metadata:
name: production
labels:
pod-security.kubernetes.io/enforce: restricted
pod-security.kubernetes.io/enforce-version: v1.34
pod-security.kubernetes.io/warn: restricted # surfaces future tightening before it blocks
```
PSA cannot do cross-object rules, mutation, image-registry allowlists, or anything referencing
another resource's state. That is what Kyverno and Gatekeeper are for.
## 2. Kyverno: validate, mutate, and generate in YAML
```yaml
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: require-resources-and-probes
annotations:
policies.kyverno.io/severity: medium
spec:
validationFailureAction: Audit # Audit -> measure -> Enforce. Never Enforce first.
background: true # also evaluate existing resources, to size the blast radius
rules:
- name: require-limits
match:
any:
- resources:
kinds: [Pod]
namespaces: [production, staging]
exclude:
any:
- resources:
namespaces: [kube-system] # cluster components predate your policy
validate:
message: >-
Every container needs cpu/memory requests and a memory limit.
Unbounded pods are the usual cause of node-level OOM cascades.
pattern:
spec:
containers:
- resources:
requests:
cpu: "?*"
memory: "?*"
limits:
memory: "?*"
```
Kyverno's advantage is that policy is Kubernetes YAML, so the whole team can read it. Its `mutate`
rules (`patchStrategicMerge`, e.g. forcing `automountServiceAccountToken: false`) and `generate`
rules also fix problems rather than only rejecting them.
## 3. OPA/Gatekeeper: Rego when the logic is genuinely conditional
```rego
package k8srequiredlabels
import future.keywords.in
violation[{"msg": msg}] {
# Only production workloads need a cost-allocation owner
input.review.object.metadata.namespace == "production"
required := {"owner", "cost-center"}
provided := {k | some k, _ in input.review.object.metadata.labels}
missing := required - provided
count(missing) > 0
msg := sprintf("production workloads must carry labels: %v", [missing])
}
```
That Rego is delivered as a Gatekeeper `ConstraintTemplate` (which defines a `K8sRequiredLabels` CRD),
then instantiated per scope by a `Constraint` — the two-object split is what lets one policy be
enforced with different parameters per namespace.
**Choosing between them:**
| Need | Choose |
| --- | --- |
| Policy the team reads and writes without learning a language; mutation, generation, image verification | Kyverno |
| Conditional logic and set arithmetic; one language shared across Kubernetes, Terraform and API authorization | OPA/Gatekeeper |
Do not run both engines for overlapping concerns. Two admission webhooks with different verdicts is
a debugging problem nobody wants at 03:00.
## 4. Shift the same rules left: Conftest on the Terraform plan
Blocking at admission is too late for infrastructure: by then the bucket exists. Gate the plan.
```rego
# policy/terraform/s3.rego
package main
deny[msg] {
r := input.resource_changes[_]
r.type == "aws_s3_bucket"
not r.change.after.tags.owner
msg := sprintf("%s: missing required tag 'owner'", [r.address])
}
```
Inspect `r.change.actions` the same way to block _removals_ — a rule that only checks the final
state will happily allow encryption to be deleted.
```bash
terraform plan -out=tfplan
terraform show -json tfplan > tfplan.json
conftest test --policy policy/terraform tfplan.json # non-zero exit fails the pipeline
```
Test the policies themselves — a guardrail with no test is a guardrail that silently stops matching.
`conftest verify --policy policy/terraform` runs `test_*` rules from `*_test.rego`, and
`kyverno test ./policies` asserts expected results per resource fixture. Both belong in CI.
## 5. Exceptions are the part everyone gets wrong
A policy with no exception mechanism gets disabled the first time it blocks something urgent. Give
exceptions a structure that expires.
```yaml
apiVersion: kyverno.io/v2
kind: PolicyException
metadata:
name: legacy-batch-privileged
namespace: batch
annotations:
owner: "@platform-team"
expires: "2026-11-30" # a gate in CI fails the build once this date passes
reason: "Vendor agent requires CAP_SYS_ADMIN. Replacement tracked in PLAT-1841."
spec:
exceptions:
- policyName: disallow-privileged-containers
ruleNames: ["privileged-containers"]
match:
any:
- resources: { kinds: [Pod], namespaces: [batch], names: ["legacy-agent-*"] }
```
Every exception needs an **owner**, an **expiry**, and a **reason**. Enforce that with a CI check
over the exception directory — an expired exception is a build failure, not a stale file nobody
reviews.
## 6. Best practices and anti-patterns
**Do:**
- **Roll out in three stages:** `Audit` with `background: true` to find existing violations, fix or
except them, then `Enforce`.
- **Scope policies to namespaces and exclude cluster components.** A cluster-wide `Enforce` policy
that matches `kube-system` can prevent the cluster from recovering after a reboot.
- **Set `failurePolicy: Ignore` while piloting**, and only move to `Fail` once the webhook's
availability and latency are proven. A `Fail` webhook that is down blocks every deployment.
- **Write the message for the developer who will hit it** — say what to change, not which rule fired.
- **Version and test policies like code**, with `conftest verify` and `kyverno test` in CI.
**Do not:**
- **Enforce on day one.** The first policy is always broader than you think.
- **Duplicate the same rule in two engines.** Pick one enforcement point per concern.
- **Write policy that reaches the network.** Admission is on the request path; an external lookup
turns a policy engine into a latency and availability dependency for every deploy.
- **Grant blanket namespace exclusions** as a shortcut. `production` excluded "temporarily" is how a
guardrail quietly stops covering the thing it existed for.
- **Rely on admission alone.** It only sees create and update, so a policy added later leaves
existing violations running — that is what `background: true` and a periodic report are for.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

