Skip to content
Notifications
Clear all

What's the best way to integrate policy checks into a Helm deployment pipeline?

1 Posts
1 Users
0 Reactions
29 Views
(@infra_switcher)
Reputable Member
Joined: 4 months ago
Posts: 320
Topic starter   [#18242]

Alright, let's cut through the marketing. "Best" is a trap. The "best" way is the one that actually blocks your deployments when they violate policy, not the one that generates a pretty report after the fact. Too many teams bolt on policy as a post-deployment audit, which is useless when you're trying to prevent a misconfigured Service from exposing your database to the internet at 3 AM.

You need to integrate checks at the right points in your pipeline, and the tooling choice depends entirely on what you're trying to enforce. Here's the breakdown from my trenches:

**Phase 1: Before `helm template` (Static Analysis)**
This is your first and cheapest line of defense. Use tools that inspect the raw Helm charts before they touch a cluster.
* **For Security Policies (CIS Benchmarks, Pod Security):** Use `checkov` or `kube-linter` directly on your chart directories. They can catch things like `securityContext` misconfigs.
* **For Custom Best Practices:** `helm-docs` is a must for maintainability, but for actual rules, you'll likely need `conftest` with Open Policy Agent (OPA) Rego policies. You test the rendered YAMLs from `helm template`.

```bash
# Example slice of a CI step
helm template myapp ./chart --values prod-values.yaml > rendered.yaml
conftest test rendered.yaml -p ../policy/kubernetes/
```

**Phase 2: After `helm template` but Before `kubectl apply` (Admission Control Simulation)**
Static analysis can't validate against the live cluster state. This is where you need a policy engine that can simulate Kubernetes Admission Control.
* **Kyverno CLI (`kyverno apply`):** This is powerful. You can run it in CI with your rendered manifests and a set of policies. It validates policies that require cluster context (e.g., "no two Ingresses can have the same host").
* **Datree / Kubescape:** These are commercial but have robust CLI options. They combine static checks with some context-aware policies.

**Phase 3: At Runtime (Cluster Admission Control)**
Your CI pipeline is not enough. You MUST enforce at the cluster level. This is your final, non-negotiable safety net.
* **Gatekeeper / Kyverno:** Deploy these as ValidatingAdmissionWebhooks. Your Helm pipeline should also be deploying and managing the policies themselves. The CI checks (Phase 2) should be running the *exact same policies* that are live in the cluster. This avoids the "it worked in CI, but the cluster blocked it" surprise.

**The Integration Pain Points You're Not Thinking About:**
* **Policy Management:** Where do the policies live? I keep them in a separate Git repo, versioned, and deploy them via Helm *before* any application workloads. The app deployment pipeline pulls in the policy repo as a library for the `conftest`/`kyverno apply` steps.
* **Policy Exceptions:** You **will** need them. Have a formal process (e.g., annotations in the Helm values, reviewed in PR) that your policies can read to allow specific, justified violations.
* **Performance:** Adding 10 complex OPA/Gatekeeper constraints on every resource create/update will add latency. Test under load.

Forget about a single "best" tool. You need a layered approach: **lint in CI, simulate admission in CI, enforce absolutely at the cluster.** My stack is typically `conftest` for custom logic in CI, `kyverno` both in CI (`kyverno apply`) and installed in the cluster, with policies managed via Helm. It's not sexy, but it stops bad config from ever becoming a running pod.

What specific policies are you most concerned with? Security, cost, resilience? The priority changes the tooling focus.

---


Been there, migrated that


   
Quote