Skip to content

Commit ad2320c

Browse files
committed
docs(index.md): clarify variable restrictions in imageReferences
Signed-off-by: kushal9897 <kushalag2580@gmail.com>
1 parent 3d1db6d commit ad2320c

File tree

1 file changed

+59
-0
lines changed
  • content/en/docs/writing-policies/verify-images

1 file changed

+59
-0
lines changed

content/en/docs/writing-policies/verify-images/_index.md

+59
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,71 @@ For additional details please reference a section below for the solution used to
5353
### Variables in `imageReferences`
5454
The `imageReferences` field does **not** support variable interpolation (e.g., `{{ }}` syntax). Only **static strings** or predefined lists should be used.
5555

56+
#### ** Incorrect Usage (Using Variables – Not Allowed)**
57+
```yaml
58+
verifyImages:
59+
- imageReferences: ["{{ parse_yaml(allowedregistryprefixes.data.allowedregistryprefixes) }}"]
60+
```
61+
This will result in a validation error because variables are **not allowed** in `imageReferences`.
62+
63+
#### ** Correct Usage (Using Static Values – Allowed)**
64+
```yaml
65+
verifyImages:
66+
- imageReferences:
67+
- "myregistry.com/app-image:v1"
68+
- "myregistry.com/app-image:v2"
69+
```
70+
Here, only **explicit, static image references** are used, which is allowed.
71+
72+
73+
### **Other Fields Where Variables Are Not Allowed**
74+
In addition to `imageReferences`, the following fields **do not support variable interpolation** and must be defined with static values:
75+
76+
- `match.resources.kinds`
77+
- `exclude.resources.kinds`
78+
- `preconditions.all`
79+
- `preconditions.any`
80+
81+
#### ** Incorrect Usage (Using Variables – Not Allowed)**
82+
```yaml
83+
rules:
84+
- name: restrict-deployment-kinds
85+
match:
86+
resources:
87+
kinds:
88+
- "{{ request.object.kind }}"
89+
```
90+
**Why is this incorrect?**
91+
- `match.resources.kinds` must contain **static** resource kinds (e.g., `Pod`, `Deployment`).
92+
- Dynamic interpolation using `{{ request.object.kind }}` is **not supported**.
93+
94+
#### ** Correct Usage (Using Static Values – Allowed)**
95+
```yaml
96+
rules:
97+
- name: restrict-deployment-kinds
98+
match:
99+
resources:
100+
kinds:
101+
- Deployment
102+
- StatefulSet
103+
```
104+
**Why is this correct?**
105+
- Only predefined, static resource kinds (`Deployment`, `StatefulSet`) are used.
106+
107+
---
108+
109+
### **Why Are Variables Not Allowed in These Fields?**
110+
Kyverno requires these fields to be **static** to ensure policy validation and enforcement remain deterministic and efficient. Allowing variables in these fields could introduce unexpected behavior, making policy evaluation unreliable.
111+
112+
---
113+
56114
#### **Incorrect Usage**
57115
```yaml
58116
verifyImages:
59117
- imageReferences: ["{{ parse_yaml(allowedregistryprefixes.data.allowedregistryprefixes) }}"]
60118
61119
120+
62121
### Cache
63122
64123
Image verification requires multiple network calls and can be time consuming. Kyverno has a TTL based cache for image verification which caches successful outcomes of image verification. When cache is enabled, an image once verified by a policy will be considered to be verified until TTL duration expires or there is a change in policy.

0 commit comments

Comments
 (0)