iac.htora.dev · security templates

Home/Templates/Stop risky pods before they start

Stop risky pods before they start

Admission policies refuse privileged pods, host mounts, and unsigned images, and report every refusal.

Argo CD

Why bother

Runtime detection tells you a container escaped. Admission control refuses the pod before it exists, when it asks for privileged mode, host paths, the host's process or network namespace, or an image nobody signed. Policies can run in audit mode first, so you see what would break before anything is blocked.

How you know it worked

Try to create a privileged pod. In Audit mode it runs and a policy report lists it as failing. Once enforced, it is refused.

How it works

1Someone creates a poddirectly, or through a deployment2The admission controller checks itprivileged, host access, image signature3Refused, or allowed and reportedenforce or audit, per policy4The result reaches respondersas a policy report and an event
Step by step, from the thing that happens to the result you want.

Set it up

Pick your platform, then open the level you want. Each level is complete on its own. Read the comments in the files as you go. Anything with a real consequence is explained on the line where it happens.

Argo CD. Kyverno installed by Argo CD, with keyless image signatures from GitHub Actions

What you need first

  • For the quick start, a cluster already running Kyverno 1.13 or later. Standard installs Kyverno 1.19 through Argo CD.
  • For Standard, Argo CD with a project named platform, as the bootstrap template creates, and this folder committed to your repository.
  • For the signature check, images built and signed with cosign in GitHub Actions.

What it creates

  • Three cluster policies in Audit mode: no privileged containers, no host paths, no host namespaces
  • Kyverno from a pinned chart, with three admission replicas (Standard)
  • The same checks enforced everywhere except three named namespaces (Standard)
  • A signature check, and a check for a signed CycloneDX SBOM, on images in prod-* namespaces, in Audit until you switch it (Standard)

See the four alerts this creates

The code

Quick startReadyone file, 90 lines
One file. Three policies in Audit mode, for a cluster that already runs Kyverno.
Run it
  1. kubectl config current-context
    Shows which cluster kubectl is pointed at. Check it first.
  2. kubectl apply -f policies.yaml
    Hands the Application to Argo CD.
  3. kubectl -n argocd get applications
    Lists applications with their sync and health status.
Download policies.yaml
Checks

Kubernetes schema passed

Last run 2026-10-02.

outcomes/k8s-admission-control/kubernetes/t0
policies.yaml
Open policies.yaml as plain text
StandardReadyfour files, 187 lines
Adds Kyverno from a pinned chart with three replicas, the policies synced from Git after it, enforcement outside three named namespaces, and signature and SBOM checks on production images.
Change these first
  • repoURL: https://github.com/your-org/your-cluster-config.git kyverno.yaml, line 54
Run it
  1. kubectl config current-context
    Shows which cluster kubectl is pointed at. Check it first.
  2. kubectl apply -k .
    Applies everything the kustomization lists, in order.
  3. kubectl -n argocd get applications
    Lists applications with their sync and health status.
Download all four files as a zip
Checks

Kubernetes schema passedBuilds passed

Last run 2026-10-02.

outcomes/k8s-admission-control/kubernetes/t1
kustomization.yaml
Open kustomization.yaml as plain text
kyverno.yaml
Open kyverno.yaml as plain text
policies/pod-security.yaml
Open pod-security.yaml as plain text
policies/verify-images.yaml
Open verify-images.yaml as plain text
HardenedReadyone file, 15 lines
Standard's manifests, unchanged. Rules refuse a missing application or policy, unpinned charts, sync without prune or self-heal, and fewer than three admission replicas. They also refuse pod rules out of Enforce, broader exclusions, other signers, and a dropped SBOM check. A daily diff against the cluster reports drift.
Run it
  1. kubectl config current-context
    Shows which cluster kubectl is pointed at. Check it first.
  2. kubectl apply -k .
    Applies everything the kustomization lists, in order.
  3. kubectl -n argocd get applications
    Lists applications with their sync and health status.
Download kustomization.yaml
Checks

Builds passed

Last run 2026-10-02.

outcomes/k8s-admission-control/kubernetes/t2
kustomization.yaml
Open kustomization.yaml as plain text

How to check it worked

Create a privileged test pod. In Audit mode it runs, and kubectl get policyreport -A lists it as failing. Once enforced, the create is refused with the policy's message.

What catches people

Kyverno skips kube-system and its own namespace by default, and the Standard policy excludes three namespaces. Anyone who can create pods there bypasses every check, so treat that list like a firewall rule.

Admission policies apply when a pod is created. Pods already running keep running until they are replaced, so read the background policy reports for them.

Kyverno's resource definitions are too large for a normal apply, so the Standard Application uses server-side apply. Without it the sync fails on an annotation size limit.

When Kyverno cannot answer, pod creation fails across the cluster, because its policies refuse by default when they cannot check. Three replicas keep it answering.

The SBOM check looks for a CycloneDX attestation signed by the same workflow identity as the image. The CI/CD signals template's supply-chain.yml attaches one. Images built elsewhere show in the policy report until their pipeline does the same.

How to undo it

Delete the Applications, or run kubectl delete -f policies.yaml. Pods already admitted keep running.

What it costs

Kyverno runs as pods in the cluster, so the cost is their CPU and memory.

Good to know

  • Start in Audit mode and read the policy reports before enforcing. Every failing pod in a report is a workload that would stop deploying.
  • A signature proves where an image came from. The Standard check accepts only signatures made by your organisation's GitHub Actions workflows, so an image pushed by hand fails it.

Registry 0.23.0. Built 2026-11-17.

Made by Habibullah Tora. Source on GitHub. Code under the MIT licence, writing under CC BY 4.0.