OLIVE Kyverno Policies
This page lists the Kyverno policies OLIVE defines, what each one is for, and the policy itself in a form you can copy, apply and adapt.
You do not need the kyverno-infra chart to use them. The chart renders these policies from values; the YAML below is what it renders. If you run your own Kyverno and manage policies yourself, take the manifests and apply them.
Every policy exists twice — once for audit and once for enforce. The two are identical except for the label value they select and what they do on failure. That is what lets a namespace be moved from observation to blocking by changing one word in that namespace's label, with no policy change.
Both can be installed at once. A namespace carrying neither label value is not evaluated by either.
These use ImageValidatingPolicy and ValidatingPolicy from policies.kyverno.io/v1 — not the older ClusterPolicy from kyverno.io. Kyverno 1.19 deprecated the legacy types and stopped installing their CRDs; removal lands in 1.20.
If you adapt an older example and get clusterpolicies.kyverno.io not found from the admission controller's startup check, that is what happened.
The enrolment mechanism
Every policy selects namespaces by label. Nothing else opts a namespace in.
| Policy | Label | Values | Kind |
|---|---|---|---|
| Require signed OLIVE images | olive/image-verification | audit / enforce | ImageValidatingPolicy |
| Allowed image registries | olive/image-registry | audit / enforce | ValidatingPolicy |
| Restrict pod privileges | olive/pod-privileges | audit / enforce | ValidatingPolicy |
In an OLIVE deployment, tenant-setup writes these labels from tenant-setup.imageVerification.mode, tenant-setup.imageRegistry.mode and tenant-setup.podPrivileges.mode. If you manage namespaces yourself, apply the label directly:
kubectl label namespace <ns> olive/image-verification=audit
The three labels are deliberately separate, because the controls cost different amounts to comply with. Pod privileges needs only a pod spec that stops asking for host access; the registry allow-list needs no rebuild; signatures need a signing pipeline for everything the namespace pulls. Tying them to one label would hold the cheap controls hostage to the expensive one.
1. Require signed OLIVE images
What it does
Refuses (or reports) any pod whose OLIVE images do not carry a keyless cosign signature issued to the OLIVE GitLab signing pipeline.
Why it exists
Digest pinning proves the image running is the image the manifest named. It does not prove the image the manifest named is the image OLIVE built — if an attacker can write to the registry and to the GitOps repository, digest pinning faithfully pins the attacker's artefact. Signature verification at admission closes that gap: the cluster refuses anything not produced by the identity that is supposed to produce it.
Pinning subject and issuer is the entire security property. Verifying "a valid Sigstore signature" without them accepts anything anyone has ever signed.
The policy
apiVersion: policies.kyverno.io/v1
kind: ImageValidatingPolicy
metadata:
name: require-signed-olive-images-audit
annotations:
policies.kyverno.io/title: 'Require signed Olive images (audit)'
policies.kyverno.io/category: 'Supply Chain Security'
policies.kyverno.io/severity: 'high'
policies.kyverno.io/description: >-
Images pulled from the Olive container registry must carry a keyless
cosign signature issued to the GitLab signing pipeline. Applies to
namespaces labelled olive/image-verification=audit.
labels:
olive/policy-mode: 'audit'
spec:
# Audit -> report only. Deny -> reject the pod.
validationActions:
- Audit
# What happens when Kyverno itself is unreachable.
# Ignore admits unverified; Fail rejects.
failurePolicy: 'Ignore'
evaluation:
# Verification needs registry credentials and outbound network. Evaluating
# already-admitted pods produces findings nobody can act on without
# recreating the pod anyway.
background:
enabled: false
webhookConfiguration:
# Registry lookup, Rekor lookup and a possible Fulcio TUF refresh all happen
# inside the admission call. The 10s default is not enough, and a timeout
# under failurePolicy Fail is a rejected pod.
timeoutSeconds: 30
matchConstraints:
resourceRules:
- apiGroups: ['']
apiVersions: ['v1']
resources: ['pods']
operations: ['CREATE', 'UPDATE']
namespaceSelector:
matchExpressions:
- key: olive/image-verification
operator: In
values:
- 'audit'
- key: kubernetes.io/metadata.name
operator: NotIn
values:
- 'kube-system'
- 'kube-public'
- 'kube-node-lease'
- 'argocd'
- 'oli-kyverno'
# Scoped deliberately narrowly.
matchImageReferences:
- glob: 'registry.gitlab.com/olive6224315/docker-images/*'
attestors:
- name: gitlab
cosign:
keyless:
identities:
- issuer: 'https://gitlab.com'
subject: 'https://gitlab.com/olive6224315/docker-images//.gitlab-ci.yml@refs/heads/main'
ctlog:
url: 'https://rekor.sigstore.dev'
validations:
- expression: >-
images.containers.map(image,
verifyImageSignatures(image, [attestors['gitlab']])
).all(e, e > 0)
message: >-
Image is not signed by the Olive GitLab signing pipeline.
validationConfigurations:
# Rewrite the reference to the digest that was actually verified, so the
# kubelet cannot pull something else through a mutable tag a moment later.
mutateDigest: true
verifyDigest: true
required: true
credentials:
# Read from KYVERNO's namespace, not the tenant's.
secrets:
- 'olive-regcred'
For the enforce variant, change three things:
metadata:
name: require-signed-olive-images-enforce
spec:
validationActions:
- Deny
failurePolicy: 'Fail'
matchConstraints:
namespaceSelector:
matchExpressions:
- key: olive/image-verification
operator: In
values:
- 'enforce'
Adapting it
| Change | What to edit |
|---|---|
| Your own registry | matchImageReferences[].glob |
| Your own signing pipeline | attestors[].cosign.keyless.identities |
| A private Rekor / Sigstore deployment | ctlog.url |
| Different pull credentials | credentials.secrets — in Kyverno's namespace |
| Additional excluded namespaces | the kubernetes.io/metadata.name NotIn list |
matchImageReferences to match any registryA pattern like * also matches the hashicorp/vault agent sidecar and the istio/proxyv2 proxy that admission webhooks inject into tenant namespaces. Nothing in the platform signs those, so the first namespace switched to enforce would be one where no pod can be created at all.
failurePolicy: Fail and a single admission-controller replicaFail is what enforcement has to mean — but with one replica, any restart of the admission controller stops pod creation in every enrolled namespace. Run at least two.
2. Allowed image registries
What it does
Refuses (or reports) any container image whose reference does not start with an approved prefix.
Why it exists
It complements the signature policy rather than overlapping it. That one proves the OLIVE images are ours; this one bounds where everything else may come from. They answer different questions — is this ours? and did it come from where our things come from? — and running both is the defence-in-depth position: a validly signed image from an unexpected source is still refused.
It is also the cheaper of the two to adopt. It needs no registry call and no network, so it can evaluate pods that are already running: enrolling a namespace produces a full inventory within a minute, without restarting anything.
The policy
apiVersion: policies.kyverno.io/v1
kind: ValidatingPolicy
metadata:
name: allowed-image-registries-audit
annotations:
policies.kyverno.io/title: 'Allowed image registries (audit)'
policies.kyverno.io/category: 'Supply Chain Security'
policies.kyverno.io/severity: 'high'
policies.kyverno.io/subject: 'Pod'
policies.kyverno.io/description: >-
Container images must come from an approved registry or repository.
Applies to namespaces labelled olive/image-registry=audit.
labels:
olive/policy-mode: 'audit'
spec:
validationActions:
- Audit
failurePolicy: 'Ignore'
evaluation:
admission:
enabled: true
# No registry call and no network, so this can evaluate what is ALREADY
# running. Enrolling a namespace produces a full inventory immediately.
background:
enabled: true
mode: Kubernetes
webhookConfiguration:
timeoutSeconds: 10
matchConstraints:
resourceRules:
- apiGroups: ['']
apiVersions: ['v1']
operations: ['CREATE', 'UPDATE']
resources: ['pods']
namespaceSelector:
matchExpressions:
- key: olive/image-registry
operator: In
values:
- 'audit'
- key: kubernetes.io/metadata.name
operator: NotIn
values:
- 'kube-system'
- 'kube-public'
- 'kube-node-lease'
- 'argocd'
- 'oli-kyverno'
variables:
# Every equivalent spelling of every allowed entry, as the chart's own
# values render it today. A bare Docker Hub name has five: the short form,
# library/<name>, and the docker.io and index.docker.io variants of both.
- name: allowedPrefixes
expression: >-
['alpine', 'alpine/curl', 'alpine/k8s', 'busybox',
'chrislusf/seaweedfs', 'couchdb',
'docker.io/alpine', 'docker.io/alpine/curl', 'docker.io/alpine/k8s',
'docker.io/busybox', 'docker.io/chrislusf/seaweedfs',
'docker.io/couchdb', 'docker.io/hashicorp/vault',
'docker.io/hashicorp/vault-k8s',
'docker.io/hashicorp/vault-secrets-operator',
'docker.io/istio/proxyv2', 'docker.io/library/alpine',
'docker.io/library/busybox', 'docker.io/library/couchdb',
'docker.io/library/node', 'docker.io/library/redis',
'docker.io/node', 'docker.io/redis',
'docker.io/temporalio/admin-tools', 'docker.io/temporalio/server',
'docker.io/temporalio/ui',
'gcr.io/distroless/nodejs24-debian13',
'gcr.io/distroless/python3-debian13',
'hashicorp/vault', 'hashicorp/vault-k8s',
'hashicorp/vault-secrets-operator',
'index.docker.io/alpine/curl', 'index.docker.io/alpine/k8s',
'index.docker.io/chrislusf/seaweedfs',
'index.docker.io/hashicorp/vault',
'index.docker.io/hashicorp/vault-k8s',
'index.docker.io/hashicorp/vault-secrets-operator',
'index.docker.io/istio/proxyv2', 'index.docker.io/library/alpine',
'index.docker.io/library/busybox', 'index.docker.io/library/couchdb',
'index.docker.io/library/node', 'index.docker.io/library/redis',
'index.docker.io/temporalio/admin-tools',
'index.docker.io/temporalio/server', 'index.docker.io/temporalio/ui',
'istio/proxyv2', 'library/alpine', 'library/busybox',
'library/couchdb', 'library/node', 'library/redis', 'node',
'quay.io/keycloak/keycloak', 'quay.io/oauth2-proxy/oauth2-proxy',
'redis', 'registry.gitlab.com/olive6224315/docker-images',
'temporalio/admin-tools', 'temporalio/server', 'temporalio/ui']
# Registry paths whose SUB-REPOSITORIES are all allowed. Only
# host-qualified entries get this: a bare Docker Hub name must not open up
# an organisation of the same name.
- name: allowedTrees
expression: >-
['docker.io/busybox/', 'docker.io/istio/proxyv2/',
'gcr.io/distroless/nodejs24-debian13/',
'gcr.io/distroless/python3-debian13/',
'quay.io/keycloak/keycloak/',
'quay.io/oauth2-proxy/oauth2-proxy/',
'registry.gitlab.com/olive6224315/docker-images/']
# initContainers and ephemeralContainers are included deliberately. An
# unreviewed init container is a better hiding place than an app container:
# it runs first, with the same volumes, and nobody looks at it.
- name: allImages
expression: >-
object.spec.containers.map(c, c.image) +
(has(object.spec.initContainers) ? object.spec.initContainers.map(c, c.image) : []) +
(has(object.spec.ephemeralContainers) ? object.spec.ephemeralContainers.map(c, c.image) : [])
# An entry matches only up to the tag or digest boundary, so "redis" does
# not also allow "redis-exporter-backdoor".
- name: deniedImages
expression: >-
variables.allImages.filter(i,
!variables.allowedPrefixes.exists(p,
i == p || i.startsWith(p + ":") || i.startsWith(p + "@")) &&
!variables.allowedTrees.exists(p, i.startsWith(p)))
validations:
- expression: 'variables.deniedImages.size() == 0'
message: >-
Container images must come from an approved registry.
messageExpression: >-
"Image(s) not on the approved registry list: " +
variables.deniedImages.join(", ") +
". Add the repository to the allow-list, or use an approved base image."
autogen:
# Report at the controller level too, so a finding names the Deployment or
# CronJob you have to change rather than a pod hash that is gone by the
# time you read it.
podControllers:
controllers:
- deployments
- statefulsets
- daemonsets
- jobs
- cronjobs
The enforce variant changes the same things as above: the name, validationActions: [Deny], failurePolicy: 'Fail', and the label value it selects.
Adapting it
The list in allowedPrefixes is the part you will change. Two rules about how matching works:
Matching is by prefix, up to the :tag or @sha256: boundary. That boundary is what stops a redis entry from also allowing redis-exporter-backdoor. A bare startsWith would not.
A Docker Hub short name has five equivalent spellings. redis, library/redis, docker.io/redis, docker.io/library/redis and index.docker.io/library/redis all refer to the same image, and a pod can be written with any of them. List all five, or the policy is trivially bypassed by choosing a different spelling. The kyverno-infra chart expands short names automatically; if you maintain the policy by hand, expand them yourself.
An entry like job-secrets-image also matches docker.io/library/job-secrets-image — an image anyone on the internet can publish under that name. That is precisely the substitution this policy exists to prevent.
Add your own images under their fully qualified registry prefix.
The allowedTrees variable is what lets one entry cover a whole registry path — useful when your own registry holds dozens of images. Only give host-qualified entries this treatment.
3. Restrict pod privileges
Rendered only when podSecurityRestrictions.enabled is true. It is off by default.
What it does
Refuses (or reports) any pod that asks for privileged mode, explicit privilege escalation, hostPath volumes, or a share of the host's PID, IPC or network namespace. The four checks are individually switchable; at least one has to stay on, because a policy with no validations is accepted by the API server and reports nothing.
Why it exists
Pod Security Admission restricted covers all four rules and costs nothing, so PSA remains the floor — this policy does not replace it. What it adds is what PSA does not give:
- one cluster-wide report instead of a per-namespace setting,
- a finding that names the container and the field,
- and, through
autogen, a finding against the Deployment or CronJob you actually have to edit rather than a pod hash that no longer exists by the time anyone reads it.
It is also the cheapest of the three to adopt: complying needs no rebuild and no signature, only a pod spec that stops asking for host access. For most tenants it is the first label to reach enforce.
initContainers and ephemeralContainers are checked deliberately. An init container is a better hiding place for a privileged escape than an app container — it runs first, with the same volumes and the same host access, and nobody reads it. ephemeralContainers are how kubectl debug attaches one to a pod that has already been admitted.
The policy
apiVersion: policies.kyverno.io/v1
kind: ValidatingPolicy
metadata:
name: restrict-pod-privileges-audit
annotations:
policies.kyverno.io/title: 'Restrict privileged pods (audit)'
policies.kyverno.io/category: 'Pod Security'
policies.kyverno.io/severity: 'high'
policies.kyverno.io/subject: 'Pod'
policies.kyverno.io/description: >-
Blocks privileged mode, privilege escalation, hostPath volumes and host
namespace sharing. Applies to namespaces labelled
olive/pod-privileges=audit.
labels:
olive/policy-mode: 'audit'
spec:
validationActions:
- Audit
failurePolicy: 'Ignore'
evaluation:
admission:
enabled: true
# Pure spec inspection - no registry call, no network - so this evaluates
# what is ALREADY running. Enrolling a namespace produces a complete
# inventory of existing violations without restarting anything, which is
# the only way to know what an enforce switch would break.
background:
enabled: true
mode: Kubernetes
webhookConfiguration:
timeoutSeconds: 10
matchConstraints:
resourceRules:
- apiGroups: ['']
apiVersions: ['v1']
operations: ['CREATE', 'UPDATE']
resources: ['pods']
namespaceSelector:
matchExpressions:
- key: olive/pod-privileges
operator: In
values:
- 'audit'
- key: kubernetes.io/metadata.name
operator: NotIn
values:
- 'kube-system'
- 'kube-public'
- 'kube-node-lease'
- 'argocd'
- 'oli-kyverno'
variables:
# The three container lists are filtered SEPARATELY and only the names are
# concatenated. Container and EphemeralContainer are different CEL types,
# so concatenating the objects first fails type-checking at policy
# admission.
- name: privilegedContainers
expression: >-
object.spec.containers.filter(c,
has(c.securityContext) && has(c.securityContext.privileged) &&
c.securityContext.privileged).map(c, c.name) +
(has(object.spec.initContainers) ? object.spec.initContainers.filter(c,
has(c.securityContext) && has(c.securityContext.privileged) &&
c.securityContext.privileged).map(c, "initContainer/" + c.name) : []) +
(has(object.spec.ephemeralContainers) ? object.spec.ephemeralContainers.filter(c,
has(c.securityContext) && has(c.securityContext.privileged) &&
c.securityContext.privileged).map(c, "ephemeralContainer/" + c.name) : [])
# Flags only an EXPLICIT allowPrivilegeEscalation: true. Unset is not
# flagged, even though the Kubernetes default for a non-privileged
# container is true - closing that gap means requiring the field to be
# explicitly false, which is PSA `restricted`'s job and would reject most
# third-party charts on day one.
- name: escalatingContainers
expression: >-
object.spec.containers.filter(c,
has(c.securityContext) && has(c.securityContext.allowPrivilegeEscalation) &&
c.securityContext.allowPrivilegeEscalation).map(c, c.name) +
(has(object.spec.initContainers) ? object.spec.initContainers.filter(c,
has(c.securityContext) && has(c.securityContext.allowPrivilegeEscalation) &&
c.securityContext.allowPrivilegeEscalation).map(c, "initContainer/" + c.name) : []) +
(has(object.spec.ephemeralContainers) ? object.spec.ephemeralContainers.filter(c,
has(c.securityContext) && has(c.securityContext.allowPrivilegeEscalation) &&
c.securityContext.allowPrivilegeEscalation).map(c, "ephemeralContainer/" + c.name) : [])
- name: sharedHostNamespaces
expression: >-
(has(object.spec.hostPID) && object.spec.hostPID ? ['hostPID'] : []) +
(has(object.spec.hostIPC) && object.spec.hostIPC ? ['hostIPC'] : []) +
(has(object.spec.hostNetwork) && object.spec.hostNetwork ? ['hostNetwork'] : [])
- name: hostPathVolumes
expression: >-
(has(object.spec.volumes) ? object.spec.volumes : []).filter(v,
has(v.hostPath)).map(v, v.name)
validations:
- expression: 'variables.privilegedContainers.size() == 0'
message: >-
Privileged containers are not allowed. Remove
securityContext.privileged, or request an exemption for this namespace.
messageExpression: >-
"Container(s) running in privileged mode: " +
variables.privilegedContainers.join(", ") +
". privileged: true grants root on the node."
- expression: 'variables.escalatingContainers.size() == 0'
message: >-
allowPrivilegeEscalation must not be true. Set it to false, or leave it
unset.
messageExpression: >-
"Container(s) with allowPrivilegeEscalation: true: " +
variables.escalatingContainers.join(", ") +
". A setuid binary in the image can otherwise regain the privileges the container dropped."
- expression: 'variables.sharedHostNamespaces.size() == 0'
message: >-
Sharing the host's PID, IPC or network namespace is not allowed.
messageExpression: >-
"Pod shares host namespace(s): " +
variables.sharedHostNamespaces.join(", ") +
". Host namespaces defeat the isolation the namespace boundary provides."
- expression: 'variables.hostPathVolumes.size() == 0'
message: >-
hostPath volumes are not allowed. Use a PersistentVolumeClaim, an
emptyDir, or a projected volume.
messageExpression: >-
"hostPath volume(s) in this pod: " +
variables.hostPathVolumes.join(", ") +
". A hostPath can reach the kubelet's credentials and the container runtime socket on the node."
autogen:
podControllers:
controllers:
- deployments
- statefulsets
- daemonsets
- jobs
- cronjobs
The enforce variant changes the same things as the others: the name, validationActions: [Deny], failurePolicy: 'Fail', and the label value it selects.
Adapting it
| Change | What to edit |
|---|---|
| Drop one of the four checks | remove its variables entry and its validations entry — podSecurityRestrictions.rules.* in the chart |
Allow hostPath for one workload | exclude that namespace rather than turning the rule off cluster-wide |
| Additional excluded namespaces | the kubernetes.io/metadata.name NotIn list |
hostPath is the rule that needs exemptions, and the one worth keepingA log shipper or a node exporter legitimately wants /var/log or /proc, so this is the check most likely to block something that looks reasonable. Prefer excluding the namespace that runs it over disabling the rule: a hostPath on /var/lib/kubelet reads every other pod's service account token, and the container runtime socket is a privileged container the admission controller never sees.
kube-systemThe CNI, CoreDNS and every CSI driver run privileged, with hostPath and host namespaces. A cluster that enforces this in kube-system cannot recover a node restart.
Adding a policy
If you add a check of your own, follow the same shape so it composes with these:
- Select namespaces by a label, with a separate label key per concern. Do not reuse
olive/image-verificationfor an unrelated check — a namespace should be able to enforce one control while auditing another. - Render it twice, once per mode, differing only in
validationActions,failurePolicyand the label value. - Exclude the system namespaces and Kyverno's own, or an admission failure can become a cluster that cannot schedule anything.
- Use
policies.kyverno.io/v1types, notClusterPolicy. - Set
autogen.podControllerswhere the finding should name the Deployment rather than a pod hash.
Related
- Infrastructure Prerequisites → Kyverno — the label contract and the signer identity
- Cluster Operator → Kyverno (
kyverno-infra) — installing the engine and rendering these policies, and the order in which to reachenforce - Security Configuration → Admission Policies — the per-tenant mode values
- Cluster Operator → Admission Control and Image Integrity