All Policies

Check Environment Variables

Environment variables control many aspects of a container's execution and are often the source of many different configuration settings. Being able to ensure that the value of a specific environment variable either is or is not set to a specific string is useful to maintain such controls. This policy checks every container to ensure that if the `DISABLE_OPA` environment variable is defined, it must not be set to a value of `"true"`.

Policy Definition

/other/check-env-vars/check-env-vars.yaml

 1apiVersion: kyverno.io/v1
 2kind: ClusterPolicy
 3metadata:
 4  name: check-env-vars
 5  annotations:
 6    policies.kyverno.io/severity: medium
 7    policies.kyverno.io/title: Check Environment Variables
 8    policies.kyverno.io/category: Other
 9    policies.kyverno.io/subject: Pod
10    kyverno.io/kubernetes-version: "1.24"
11    kyverno.io/kyverno-version: 1.8.2
12    policies.kyverno.io/description: >-
13      Environment variables control many aspects of a container's execution and are
14      often the source of many different configuration settings. Being able to ensure that
15      the value of a specific environment variable either is or is not set to a specific string
16      is useful to maintain such controls. This policy checks every container to ensure that if the
17      `DISABLE_OPA` environment variable is defined, it must not be set to a value of `"true"`.
18spec:
19  background: true
20  validationFailureAction: Audit
21  rules:
22    - name: check-disable-opa
23      match:
24        any:
25          - resources:
26              kinds:
27                - Pod
28      validate:
29        message: "DISABLE_OPA must not be set to true."
30        pattern:
31          spec:
32            containers:
33              - name: "*"
34                =(env):
35                  - (name): DISABLE_OPA
36                    value: "!true"