Common Tasks

This page lists a set of tasks that can be performed after you install Kubewarden in your Kubernetes cluster.

Each task can be done separately; however, if you're not familiar with Kubewarden, or Kubernetes policies in general, we recommend that you follow the tasks below in sequential order.

Test Policies

Kubewarden has two main tools to help you find policies and test them locally:

Kubewarden Policy Hub

The Kubewarden Policy Hub hosts policies contributed by the community. For example, you can find substitutes to the deprecated Kubernetes Pod Security Policies, created by the Kubewarden developers.

As shown in the picture below, once you find the policy to be tested, you can copy the registry path1 or download2 the Wasm binary containing the policy and additional metadata:

Kubewarden Policy Hub

Once you have the policy Wasm binary or the registry path, you can test it with kwctl.

kwctl CLI tool

kwctl is a Command Line Interface (CLI) tool that will allow both the policy authors and the cluster administrators to test policies before they are applied to the Kubernetes cluster.

The user experience (UX) of this tool is intended to be easy and intuitive like the docker CLI tool.

Use cases

Depending on your role, kwctl will help you in the following non-exhaustive scenarios:

As a policy author

  • End-to-end testing of your policy: Test your policy against crafted Kubernetes requests and ensure your policy behaves as you expect. You can even test context-aware policies that require access to a running cluster.
  • Embed metadata in your Wasm module: the binary contains annotations of the permissions it needs to be executed
  • Publish policies to OCI registries: The binary is a fully compliant OCI object and can be stored in OCI registries.

As a cluster administrator

  • Inspect remote policies: Given a policy in an OCI registry or in an HTTP server, show all static information about the policy.
  • Dry-run of a policy in your cluster: Test the policy against crafted Kubernetes requests and ensure the policy behaves as you expect given the input data you provide. You can even test context-aware policies that require access to a running cluster, also in a dry-run mode.
  • Generate initial ClusterAdmissionPolicy scaffolding for your policy: Generate a YAML file with all the required settings, which can be applied to your Kubernetes cluster using kubectl.


kwctl binaries for the stable releases are directly available from the GitHub repository.

NOTE: If you want to build kwctl from the development branch, you need to install Rust. And for building kwctl, please refer to the Build kwctl from source section in the GitHub repo.


As stated above, kwctl will allow you to perform an end-to-end testing of the policies.

You can list all the kwctl options and subcommands by running the following command:

$ kwctl --help
kwctl 0.2.4
Flavio Castelli <>:Rafael Fernández López <>
Tool to manage Kubewarden policies

    kwctl [FLAGS] <SUBCOMMAND>

    -h, --help       Prints help information
    -V, --version    Prints version information
    -v               Increase verbosity

    annotate       Adds Kubewarden metadata to a WebAssembly module
    completions    Generates shell completions
    help           Prints this message or the help of the given subcommand(s)
    inspect        Inspects Kubewarden policy
    manifest       Scaffolds a Kubernetes resource
    policies       Lists all downloaded policies
    pull           Pulls a Kubewarden policy from a given URI
    push           Pushes a Kubewarden policy to an OCI registry
    rm             Removes a Kubewarden policy from the store
    run            Runs a Kubewarden policy from a given URI
    verify         Verifies a Kubewarden policy from a given URI using Sigstore

Here are a few examples of the commands you should run, depending on the task you want to perform:

  • List the policies: lists all the policies stored in the local kwctl registry

    • Command: kwctl policies
  • Obtain the policy: download and store the policy inside the local kwctl store

    • Command: kwctl pull <policy URI>
    • Example:
    $ kwctl pull registry://
    $ kwctl policies
    | Policy                                                       | Mutating | Context aware | SHA-256      | Size     |
    | registry:// | no       | no            | 59e34f482b40 | 21.86 kB |
  • Understand how the policy works: inspect the policy metadata

    • Command: kwctl inspect <policy URI>
    • Example:
      $ kwctl inspect registry://
      title:              pod-privileged
      description:        Limit the ability to create privileged containers
      author:             Flavio Castelli
      license:            Apache-2.0
      mutating:           false
      context aware:      false
      execution mode:     kubewarden-wapc
      protocol version:   1
      io.kubewarden.kwctl 0.1.9
      - apiGroups:
          - ""
          - v1
          - pods
          - CREATE
      This policy doesn't have a configuration. Once enforced, it will reject
      the creation of Pods that have at least a privileged container defined.
  • Evaluate the policy: Assess the policy and, if available, find the right configuration values to match your requirements.

    NOTE: Familiarity with Kubernetes REST APIs is a prerequisite.

    • Command: kwctl run -r <"Kubernetes Admission request" file path> -s <"JSON document" file path> <policy URI>

    • Scenario 1:

      • Request to be evaluated: Create a pod with no 'privileged' container

      • Example:

        $ kwctl run registry:// -r unprivileged-pod-request.json
        • Equivalent command with the policy binary downloaded:

          `$ kwctl run file://$PWD/pod-privileged-policy.wasm -r unprivileged-pod-request.json
      • Result: The policy allows the request

    • Scenario 2:

      • Request to be evaluated: Create a pod with at least one 'privileged' container

      • Command:

        kwctl run registry:// -r privileged-pod-request.json
        • Equivalent command with the policy binary downloaded: kwctl run file://$PWD/pod-privileged-policy.wasm -r privileged-pod-request.json
      • Output:

        {"uid":"8EE6AF8C-C8C8-45B0-9A86-CB52A70EC50D","allowed":false,"status":{"message":"User 'kubernetes-admin' cannot schedule privileged containers"}}
      • Result: The policy denies the request

      NOTE: If you want to see a more complex example, you can read the Kubewarden blog post Introducing kwctl to Kubernetes Administrators.

Enforce Policies

As described in the Quick Start, you can enforce a policy by defining a ClusterAdmissionPolicy and then deploy it to your cluster using kubectl.

kwctl will help to generate a ClusterAdmissionPolicy from the policy you want to enforce.

After you have generated the ClusterAdmissionPolicy and applied it to your Kubernetes cluster, you can follow the steps described in the Quick Start below:

  • Generate the ClusterAdmissionPolicy from the policy manifest and save it to a file

    • Command: kwctl manifest -t ClusterAdmissionPolicy <policy URI> > <"policy name".yaml>
    • Example:
    $ kwctl manifest -t ClusterAdmissionPolicy registry://
    kind: ClusterAdmissionPolicy
      name: privileged-pods
      module: "registry://"
      settings: {}
        - apiGroups:
            - ""
            - v1
            - pods
            - CREATE
      mutating: false

    TIP: By default, the name value is set to generated-policy. You might want to edit it before you deploy the ClusterAdmissionPolicy.

    NOTE: To avoid confusion, the value above has been set to privileged-pods.

  • Deploy the ClusterAdmissionPolicy to your Kubernetes cluster

    • Command: kubectl apply -f <"policy name".yaml>
    • Example:
    $ kubectl apply -f pod-privileged-policy.yaml created

Once the ClusterAdmissionPolicy is deployed, the requests sent to your Kubernetes cluster will be evaluated by the policy if they're within the policy scope.

Next steps

Write Policies

The Writing Policies section explains how to write policies in different languages and how to export them into Webassembly so that they can be interpreted by Kubewarden.

Distribute Policies

The Distributing Policies section explains how to publish policies to OCI registries.