snowplow-kyverno-policies
by Snowplow
Snowplow-authored Kyverno policies for Kubernetes clusters running Kyverno
About this chart
snowplow-kyverno-policies
Snowplow-authored Kyverno policies for Kubernetes clusters,
packaged as a single Helm release per cluster. The chart targets Kyverno's
CEL-based policy API (policies.kyverno.io/v1: ValidatingPolicy,
MutatingPolicy, GeneratingPolicy, ...), not the legacy kyverno.io/v1
ClusterPolicy.
Prerequisites
This chart only ships policies and the RBAC they need. It does not install Kyverno or any CRDs. The cluster must already have:
- Kyverno installed with its CRDs (
crds.install=true), and the background controller enabled (it reconcilesGeneratingPolicy). - For
ackAcmDnsValidation: the ACK ACM and Route53 controllers installed.
With default values the chart renders nothing, so installing it on a cluster without these prerequisites is a safe no-op.
How it is organised
Kyverno policies sit on a spectrum from "static logic" to "pure data", and the chart treats those cases differently rather than forcing one model:
| Mechanism | Use for | Where it lives |
|---|---|---|
Curated catalog (policies.*) | Opinionated, logic-heavy policies (lots of CEL). Reviewed and versioned as first-class templates, toggled on/off. | templates/<cloud>/<name>.yaml |
Data-driven families (customPolicies[]) | N parameterised policies of a kind, where the difference between instances is pure data. No template change to add another. | templates/generic/custom-policies.yaml |
Cloud-specific curated policies are gated on both their enabled flag and
global.cloud, so enabling an AWS policy on a non-AWS cluster is a no-op.
Values
| Key | Default | Description |
|---|---|---|
global.cloud | "" | aws / gcp / azure. Gates cloud-specific curated policies. |
labels | {} | Extra labels applied to every rendered object. |
globalExemptionLabel | "" | Opt-in. When set (for example snowplow.io/kyverno-exempt), Pods labelled <key>: "true" are exempt from every Pod policy, on top of each policy's own exemptionLabel, including policies in Deny mode. |
policies.ackAcmDnsValidation.enabled | false | AWS-only. Bridge ACK ACM Certificate validation to ACK Route53 RecordSet. |
policies.ackAcmDnsValidation.hostedZoneAnnotation | snowplow.io/hosted-zone-id | Certificate annotation carrying the target hosted zone ID. |
policies.ackAcmDnsValidation.ttl | 60 | TTL (seconds) for the generated validation RecordSet. |
policies.ackAcmDnsValidation.evaluation.admission | true | Generate the RecordSet on Certificate admission (CREATE/UPDATE). |
policies.ackAcmDnsValidation.evaluation.generateExisting | true | Generate for Certificates that already exist when the policy is installed. |
policies.ackAcmDnsValidation.evaluation.synchronize | true | Re-reconcile the generated RecordSet if it is modified or deleted. |
policies.disableServiceAccountTokenAutomount.mutate.enabled | false | Patch Pods on CREATE to spec.automountServiceAccountToken: false. |
policies.disableServiceAccountTokenAutomount.mutate.failurePolicy | Ignore | Fail blocks every Pod CREATE in the matched namespaces while the Kyverno webhook is unavailable. |
policies.disableServiceAccountTokenAutomount.mutate.removeTokenVolume | false | Also remove the kube-api-access-* token volume and its mounts. Without it the token stays mounted. See Removing the token. |
policies.disableServiceAccountTokenAutomount.validate.enabled | false | Report or block Pods that do not set it to false. |
policies.disableServiceAccountTokenAutomount.validate.validationActions | [Audit] | Audit (PolicyReport only), Warn (admission warning) or Deny (block). |
policies.disableServiceAccountTokenAutomount.validate.failurePolicy | Ignore | Fail makes admission depend on the Kyverno webhook being up. |
policies.disableServiceAccountTokenAutomount.validate.background | true | Background-scan already-running Pods into PolicyReports. |
policies.disableServiceAccountTokenAutomount.validate.checkMountedToken | false | Fail Pods where a container mounts a kube-api-access-* volume, instead of checking the field. Under Deny requires mutate.removeTokenVolume. |
policies.disableServiceAccountTokenAutomount.excludedNamespaces | [kube-system, kyverno] | Namespaces exempt from both modes. Emptying it applies the policy cluster-wide. |
policies.disableServiceAccountTokenAutomount.exemptionLabel | snowplow.io/automount-service-account-token | Pods labelled <key>: "true" are exempt from both modes. "" removes the escape hatch. |
policies.requireResourceLimits.enabled | false | Report or block Pods whose containers do not set resources.limits for every requiredLimits entry. |
policies.requireResourceLimits.requiredLimits | [cpu] | Resource names each container must limit. Add memory to extend. |
policies.podSecurityRestricted.enabled | false | The Pod Security Standards restricted profile, as 15 pss-* ValidatingPolicies. |
policies.requireImageDigest.enabled | false | Report or block Pods with an image not pinned by digest. |
policies.restrictImageRegistries.enabled | false | Report or block Pods with an image from outside allowedRegistries. |
policies.restrictImageRegistries.allowedRegistries | [] | Registry hosts, optionally with a repository path. Required when enabled. |
policies.requireNamespaceNetworkPolicy.enabled | false | Report or block Pods created in a namespace with no NetworkPolicy. Also renders a ClusterRole. |
policies.restrictSecretMounts.enabled | false | Report or block Pods that reference a Secret not in allowedSecrets. |
policies.restrictSecretMounts.allowedSecrets | [] | Exact Secret names Pods may reference. Empty allows none. |
policies.<policy>.validationActions | [Audit] | For each policy above. Audit, Warn or Deny. |
policies.<policy>.failurePolicy | Ignore | For each policy above. Fail makes admission depend on the Kyverno webhook being up. |
policies.<policy>.background | true | For each policy above. Background-scan already-running Pods into PolicyReports. |
policies.<policy>.excludedNamespaces | [kube-system, kyverno] | For each policy above. Emptying it applies the policy cluster-wide. |
policies.<policy>.exemptionLabel | see Exemption labels | For each policy above. Pods labelled <key>: "true" are exempt. "" removes the escape hatch. |
customPolicies | [] | Data-driven policy families. See below. |
ackAcmDnsValidation
On Certificate CREATE/UPDATE, once the ACK ACM controller has populated
status.domainValidations[], this GeneratingPolicy creates the DNS-01
validation CNAME as a Route53 RecordSet in the hosted zone named by the
Certificate's hostedZoneAnnotation. The generated RecordSet carries an
ownerReference back to the Certificate so it cascade-deletes.
The Certificate must be labelled snowplow.io/ack-managed: "true" and annotated
with the hosted zone ID for the policy to act on it.
disableServiceAccountTokenAutomount
Cloud-agnostic. Stops Pods mounting a ServiceAccount token they do not need. The two modes are independent and can be enabled together:
mutaterenders aMutatingPolicythat patches Pods on CREATE tospec.automountServiceAccountToken: false, and withremoveTokenVolumealso removes the token itself (see Removing the token). Controller-created Pods are patched at admission regardless of what the Deployment/StatefulSet template says, so no workload chart needs editing.validaterenders aValidatingPolicythat flags (or withvalidationActions: [Deny], blocks) Pods that do not have it set tofalse, or withcheckMountedToken, Pods that still mount the token, for ongoing compliance.
With both enabled the mutation runs first in the admission chain, so the validation sees the patched Pod and passes.
What this does and does not break
Cloud identity is unaffected. IRSA and Azure Workload Identity inject their
own projected token volumes (aws-iam-token, azure-identity-token) through
separate webhooks; automountServiceAccountToken only governs the default
kube-api-access-* volume, so there is no conflict.
In-cluster Kubernetes API clients are affected. Anything that builds an
in-cluster client — Kyverno itself, cluster-autoscaler, Karpenter, the AWS Load
Balancer Controller, cert-manager, external-dns, ACK controllers, CoreDNS — loses
its credentials and fails to authenticate. This is why the policies are not
cluster-wide by default: exempt those workloads by namespace
(excludedNamespaces) or per Pod (exemptionLabel) before enabling mutate,
and roll out through validate with validationActions: [Audit] first to find
them.
Opting a workload out
There are four ways to keep the token for a workload that needs the Kubernetes
API. Use the narrowest one that fits. Labels can be set by anyone who can create
the Pod; a PolicyException can be restricted to cluster admins.
| Option | Scope | Use it when |
|---|---|---|
excludedNamespaces | Every Pod in the namespace | The whole namespace is cluster infrastructure (controllers, operators). Set in this chart's values. |
exemptionLabel on the Pod | One workload, this policy only | You control the workload's Pod template, for example through its chart's podLabels value. |
globalExemptionLabel on the Pod | One workload, every Pod policy in this chart | Off by default. Only if the cluster sets it and the workload must also skip the other policies. Prefer the per-policy label. |
PolicyException | Workloads selected by a CEL condition | You cannot label the Pods, for example a third-party chart without a podLabels value, Helm hook Jobs, or Jobs created by a CronJob. |
Label. Put the label on the Pod template, not only on the Deployment,
CronJob or other controller. Kyverno checks it both on the Pod and, through
autogen, on the controller's spec.template:
# e.g. a chart's podLabels value, or spec.template.metadata.labels
snowplow.io/automount-service-account-token: "true"
The label is the default exemptionLabel. It exempts the Pod from both
mutate and validate, and it has no effect on clusters without Kyverno, so it
is safe to set unconditionally. If a cluster sets globalExemptionLabel, that
label works the same way but exempts the Pod from every Pod policy.
PolicyException. Kyverno must have PolicyExceptions enabled
(features.policyExceptions.enabled in the Kyverno chart). Restrict them to a
namespace that workload owners cannot write to
(features.policyExceptions.namespace), otherwise anyone who can create Pods
in a namespace can also exempt them. Reference both policies, so an exempted
workload is not rejected once validate moves to Deny, and keep the condition
as narrow as possible:
apiVersion: policies.kyverno.io/v1beta1
kind: PolicyException
metadata:
name: my-namespace-my-release
namespace: kyverno # the namespace set in features.policyExceptions.namespace
spec:
policyRefs:
- name: disable-automount-service-account-token
kind: MutatingPolicy
- name: require-service-account-token-automount-disabled
kind: ValidatingPolicy
matchConditions:
- name: release-workloads
# Guard every field access with has(). An evaluation error counts as a
# policy error, so an unguarded expression can block Pod creation.
expression: >-
request.namespace == 'my-namespace' &&
has(object.metadata.labels) &&
object.metadata.labels['app.kubernetes.io/instance'] == 'my-release'
As with the policies themselves, an exception only affects Pods created after it exists. Recreate the workload's Pods to pick it up.
Removing the token
The ServiceAccount admission plugin runs before any webhook. By the time Kyverno
sees a Pod, the plugin has already added the kube-api-access-<random> projected
volume and mounted it into every container. Setting
automountServiceAccountToken: false at that point changes the field but not
the mount, so with the defaults the token is still there.
mutate.removeTokenVolume: truealso removes that volume, and everyvolumeMountof it fromcontainersandinitContainers. Ephemeral containers cannot be set on Pod CREATE, and one added later throughkubectl debughas no token volume left to mount. Only projected volumes namedkube-api-access-*are removed. IRSA (aws-iam-token), EKS Pod Identity (eks-pod-identity-token) and Azure Workload Identity (azure-identity-token) tokens are left alone, so cloud credentials keep working.validate.checkMountedToken: truemakes the validation check what is actually mounted: it fails a Pod where any container mounts akube-api-access-*volume, and passes one that mounts none, whatever the field says. That also fixes the ServiceAccount-level case in the caveats below.
Both default to false, so upgrading to 0.4.0 does not change behaviour.
Mutating webhooks run before validating ones, so with both on a Pod is
validated after its token is removed and passes. Under Deny,
checkMountedToken without removeTokenVolume would reject every Pod in
scope, so the chart refuses to render that combination.
With both on and Deny, mind the failurePolicy interaction. With the default
Ignore on both webhooks, a Kyverno outage skips both and Pods are admitted
with their token, so nothing is blocked. If only the mutation call fails (it
errors or times out) while the validation call succeeds, the token is still
mounted and that Pod is denied; its controller retries. In other words Deny
fails closed on a failed mutation but still fails open on an ou
Deploy snowplow-kyverno-policies with OpenTenant
Each tenant gets its own release of this chart, with its own namespace, secrets and domain. The builder below already has snowplow-kyverno-policies on a Hetzner server. Change the host, add apps from the marketplace, then copy the generated files. Providers and prices are samples, and nothing here is sent anywhere.
- Pick a serverConnect Hetzner, OVHcloud or AWS. The builder starts on Hetzner, the cheapest sample rate.
- Place the chartsnowplow-kyverno-policies is pinned at v0.4.0 in opentenant.yaml. Drag more apps from the marketplace onto a rack.
- ApplySave opentenant.yaml and main.tf from the console, then run the commands below.
# opentenant.yaml, main.tf and dns.tf come from the builder below opentenant validate opentenant.yaml terraform init && terraform apply