Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: clarify that variables are not allowed in imageReferences field #1472

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions content/en/docs/writing-policies/verify-images/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,69 @@ The `imageRegistryCredentials.secrets` specifies a list of secrets that are prov

For additional details please reference a section below for the solution used to sign the images and attestations:

## Limitations

### Variables in `imageReferences`
The `imageReferences` field does **not** support variable interpolation (e.g., `{{ }}` syntax). Only **static strings** or predefined lists should be used.

#### Incorrect Usage (Using Variables – Not Allowed)
```yaml
verifyImages:
- imageReferences: ["{{ parse_yaml(allowedregistryprefixes.data.allowedregistryprefixes) }}"]
```
This will result in a validation error because variables are **not allowed** in `imageReferences`.

#### Correct Usage (Using Static Values – Allowed)
```yaml
verifyImages:
- imageReferences:
- "myregistry.com/app-image:v1"
- "myregistry.com/app-image:v2"
```
Here, only **explicit, static image references** are used, which is allowed.


### **Other Fields Where Variables Are Not Allowed**
In addition to `imageReferences`, the following fields **do not support variable interpolation** and must be defined with static values:

- `match.resources.kinds`
- `exclude.resources.kinds`
- `preconditions.all`
- `preconditions.any`
Comment on lines +78 to +79
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs to double-check preconditions.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

preconditions supports variables, have you not been able to verify it?


#### Incorrect Usage (Using Variables – Not Allowed)
```yaml
rules:
- name: restrict-deployment-kinds
match:
resources:
kinds:
- "{{ request.object.kind }}"
```
**Why is this incorrect?**
- `match.resources.kinds` must contain **static** resource kinds (e.g., `Pod`, `Deployment`).
- Dynamic interpolation using `{{ request.object.kind }}` is **not supported**.

#### Correct Usage (Using Static Values – Allowed)
```yaml
rules:
- name: restrict-deployment-kinds
match:
resources:
kinds:
- Deployment
- StatefulSet
```
**Why is this correct?**
- Only predefined, static resource kinds (`Deployment`, `StatefulSet`) are used.



### **Why Are Variables Not Allowed in These Fields?**
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.



### Cache

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.
Expand Down