|
This is unreleased documentation for Runtime Enforcer 0.11-dev. |
Draft a policy from one image
This page is for a platform operator who wants to run a third-party image
under a WorkloadPolicy from the first day. There is no workload file yet,
or the workload file is not under your control. wpgen image scans one image
and writes a draft policy with one container.
wpgen or the learn
phase explains when a draft is a better start than the learn phase.
Before you start, install wpgen.
The examples use docker.io/library/caddy:2.9. The output was recorded on
2026-11-02. A tag can move to a new image, and then the counts and the paths
change.
Draft the policy
-
Find the name of the container that will run the image. The policy applies its rules by container name. If the name in the policy differs from the name in the pod, the rules do not apply to the container.
-
Run
wpgen imagewith the container name, the policy name, and the namespace:wpgen image docker.io/library/caddy:2.9 \ --container-name caddy --name caddy --namespace web \ --image-src registry > policy.yaml Loading image "docker.io/library/caddy:2.9"... Loaded image "docker.io/library/caddy:2.9" from source "registry" (linux/amd64) ┌───────────┬─────────────────────────────┬─────────────┬───────────────────┬───────────────┐ │ CONTAINER │ IMAGE │ EXECUTABLES │ SKIPPED LIBRARIES │ SKIPPED OTHER │ ├───────────┼─────────────────────────────┼─────────────┼───────────────────┼───────────────┤ │ caddy │ docker.io/library/caddy:2.9 │ 21 │ 10 │ 0 │ └───────────┴─────────────────────────────┴─────────────┴───────────────────┴───────────────┘ Use --include-libraries to keep the skipped shared libraries. Add this label to the pod template of the workload that runs this image: runtimeenforcer.kubewarden.io/policy: caddy -
Read the policy:
apiVersion: runtimeenforcer.kubewarden.io/v1alpha1 kind: WorkloadPolicy metadata: name: caddy namespace: web spec: mode: monitor rulesByContainer: caddy: executables: allowed: - /bin/busybox - /etc/ca-certificates/update.d/certhash - /etc/network/if-up.d/dad - /sbin/apk - /sbin/ldconfig - /usr/bin/c_rehash - /usr/bin/caddy - /usr/bin/getconf - /usr/bin/getent - /usr/bin/iconv - /usr/bin/ldd - /usr/bin/scanelf - /usr/bin/ssl_client - /usr/lib/libcap.so.2.70 - /usr/lib/libpsx.so.2.70 - /usr/sbin/capsh - /usr/sbin/getcap - /usr/sbin/getpcaps - /usr/sbin/setcap - /usr/sbin/update-ca-certificates - /usr/share/udhcpc/default.script -
Apply the policy. Then add the
runtimeenforcer.kubewarden.io/policylabel with the valuecaddyto the pod template of the workload.
| This policy is a draft. It allows every executable of the image, and it misses the executables that are not in the image. Keep it in monitor mode until you trim it and test it. See The output is a draft. |
The three flags are optional:
-
Without
--container-name, the container ismain. The summary then reminds you to use the same name in the pod. -
Without
--name, the policy name is the last part of the image repository,caddyin this example. For an archive or a directory, the repository comes from the tag stored in the image. Whenwpgencannot find a name, for example for an OCI layout directory without tags, it usestodoand prints a warning. Replace this name before you apply the policy. -
Without
--namespace, the policy goes to thedefaultnamespace.
This is the warning for an OCI layout directory made with
crane pull --format oci docker.io/library/caddy:2.9 caddy-oci:
wpgen image ./caddy-oci --image-src file > policy.yaml
Loading image "./caddy-oci"...
Loaded image "./caddy-oci" from source "file" (linux/amd64)
┌───────────┬─────────────┬─────────────┬───────────────────┬───────────────┐
│ CONTAINER │ IMAGE │ EXECUTABLES │ SKIPPED LIBRARIES │ SKIPPED OTHER │
├───────────┼─────────────┼─────────────┼───────────────────┼───────────────┤
│ main │ ./caddy-oci │ 21 │ 10 │ 0 │
└───────────┴─────────────┴─────────────┴───────────────────┴───────────────┘
Use --include-libraries to keep the skipped shared libraries.
WARNING: cannot derive the policy name from "./caddy-oci": the image has no tags.
The policy name is "todo". Use --name, or edit metadata.name.
Add this label to the pod template of the workload that runs this image:
runtimeenforcer.kubewarden.io/policy: todo
Make sure that the container is named "main" in the pod, or use --container-name.
Next steps
-
The draft allows every program and script of the image. For a large base image,
wpgenprints a warning. Trim the policy before you switch to protect mode. See Large base images and Trim the policy. -
To set
protectmode, to write the policy as JSON, or to apply it without a file, see Output options. -
After an image update, make sure that the policy still matches the image. See Check a policy against its images.
-
When you have the workload file,
wpgen workloaddrafts one policy with all the containers of the pod. See Draft policies from a workload file.