You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 19, 2026. It is now read-only.
`kwctl` can be used to run a policy locally, outside of Kubernetes. This can be used
110
110
to quickly evaluate a policy and find the right settings for it.
111
111
112
112
The evaluation is done against a pre-recorded [`AdmissionReview`](https://kubernetes.io/docs/reference/access-authn-authz/extensible-admission-controllers/#request).
113
113
114
-
Running a policy locally:
114
+
> **Note:** it's possible to scaffodl an `AdmissionReview` object from a Kubernetes resource.
115
+
> Take a look at [this section](#scaffold-kubernetes-custom-resources) for more details.
116
+
117
+
#### Run a local policy
118
+
119
+
To run a local `.wasm` file containing a policy:
115
120
116
121
```console
117
122
kwctl run \
@@ -123,7 +128,33 @@ kwctl run \
123
128
Policy configuration can be passed on the CLI via the `--settings-json` flag
124
129
or can be loaded from the disk via the `--settings-path` flag.
125
130
126
-
#### Scaffold AdmissionReview from a Kubernetes resource
131
+
#### Run a policy defined by a Kubewarden Custom Resource
132
+
133
+
To run a local YAML file containing the definition of any of the Kubewarden Custom
134
+
Resources:
135
+
136
+
```console
137
+
kwctl run \
138
+
-r test_data/ingress.json \
139
+
policy.yaml
140
+
```
141
+
142
+
The YAML file can contain any of the Kubewarden CRDs, including policy groups.
143
+
144
+
**Warning:** kwctl considers only these attributes of the CRD:
145
+
146
+
- policy module to be evaluated
147
+
- policy settings
148
+
- context aware resources
149
+
150
+
All the other fields are ignored. For example, `rules`, `matchConditions`, `objectSelector`,
151
+
`namespaceSelector` and other fields are not taken into account.
152
+
153
+
Moreover, the YAML file could contain multiple declarations of Kubewarden Custom Resources. In this case
154
+
kwctl will evaluate each policy found inside of the YAML file. However, the same request is going to be used
155
+
during each evaluation.
156
+
157
+
### [Scaffold AdmissionReview from a Kubernetes resource](#scaffold-admissionreview-from-a-kubernetes-resource)
127
158
128
159
It's possible to scaffold an `AdmissionReview` object from a Kubernetes resource:
The policy can be specified in the following ways:
85
+
- URI: e.g., `registry://ghcr.io/kubewarden/policies/psp-policy:latest` or `https://example.com/kubewarden/policies/main/psp-policy/psp-policy.wasm`
86
+
- SHA prefix: e.g., `c3b80a10f9c3` (requires the policy to be already pulled)
87
+
- Local WASM file: e.g., `file://home/tux/new-policy/psp-policy.wasm`
88
+
- Local YAML file: e.g., `file://home/tux/cluster-admission-policy.yaml` (contains declarations of Kubewarden Custom Resources like `ClusterAdmissionPolicy`, `AdmissionPolicy`, etc.)
89
+
90
+
Default Behavior:
91
+
If the schema is omitted, `file://` is assumed, rooted in the current directory.
92
+
93
+
Notes on Kubewarden Custom Resources:
94
+
- Flags `--request-path`, `--settings-path`, and `--settings-json` are ignored; settings are read from the Custom Resource definition.
95
+
- The `--execution-mode` flag applies to all policies in the YAML file.
96
+
- The `--raw` flag cannot be used, as Kubewarden's Custom Resources do not support `raw` policies.
97
+
98
+
Only the following attributes of the Custom Resource Definition (CRD) are evaluated:
99
+
- Policy module
100
+
- Policy settings
101
+
- Context-aware resources the policy can access
102
+
103
+
Other fields, such as `rules`, `matchConditions`, `objectSelector`, and `namespaceSelector`, are ignored.
104
+
105
+
A YAML file may contain multiple Custom Resource declarations. In this case, `kwctl` evaluates each policy in the file using the same request during each evaluation.
*`<URI_OR_SHA_PREFIX>` — Policy URI or SHA prefix. Supported schemes: registry://, https://, file://. If schema is omitted, file:// is assumed, rooted on the current directory.
112
+
*`<URI_OR_SHA_PREFIX_OR_YAML_FILE>` — Policy URI, SHA prefix or YAML file containing Kubewarden policy resources. Supported schemes: registry://, https://, file://. If schema is omitted, file:// is assumed, rooted on the current directory.
89
113
90
114
###### **Options:**
91
115
@@ -292,13 +316,37 @@ Removes a Kubewarden policy from the store
292
316
293
317
## `kwctl run`
294
318
295
-
Runs a Kubewarden policy from a given URI
319
+
Run one or more Kubewarden policies locally.
296
320
297
-
**Usage:**`kwctl run [OPTIONS] --request-path <PATH> <uri_or_sha_prefix>`
321
+
The policy can be specified in the following ways:
322
+
- URI: e.g., `registry://ghcr.io/kubewarden/policies/psp-policy:latest` or `https://example.com/kubewarden/policies/main/psp-policy/psp-policy.wasm`
323
+
- SHA prefix: e.g., `c3b80a10f9c3` (requires the policy to be already pulled)
324
+
- Local WASM file: e.g., `file://home/tux/new-policy/psp-policy.wasm`
325
+
- Local YAML file: e.g., `file://home/tux/cluster-admission-policy.yaml` (contains declarations of Kubewarden Custom Resources like `ClusterAdmissionPolicy`, `AdmissionPolicy`, etc.)
326
+
327
+
Default Behavior:
328
+
If the schema is omitted, `file://` is assumed, rooted in the current directory.
329
+
330
+
Notes on Kubewarden Custom Resources:
331
+
- Flags `--request-path`, `--settings-path`, and `--settings-json` are ignored; settings are read from the Custom Resource definition.
332
+
- The `--execution-mode` flag applies to all policies in the YAML file.
333
+
- The `--raw` flag cannot be used, as Kubewarden's Custom Resources do not support `raw` policies.
334
+
335
+
Only the following attributes of the Custom Resource Definition (CRD) are evaluated:
336
+
- Policy module
337
+
- Policy settings
338
+
- Context-aware resources the policy can access
339
+
340
+
Other fields, such as `rules`, `matchConditions`, `objectSelector`, and `namespaceSelector`, are ignored.
341
+
342
+
A YAML file may contain multiple Custom Resource declarations. In this case, `kwctl` evaluates each policy in the file using the same request during each evaluation.
343
+
344
+
345
+
**Usage:**`kwctl run [OPTIONS] --request-path <PATH> <uri_or_sha_prefix_or_yaml_file>`
298
346
299
347
###### **Arguments:**
300
348
301
-
*`<URI_OR_SHA_PREFIX>` — Policy URI or SHA prefix. Supported schemes: registry://, https://, file://. If schema is omitted, file:// is assumed, rooted on the current directory.
349
+
*`<URI_OR_SHA_PREFIX_OR_YAML_FILE>` — Policy URI, SHA prefix or YAML file containing Kubewarden policy resources. Supported schemes: registry://, https://, file://. If schema is omitted, file:// is assumed, rooted on the current directory.
0 commit comments