Kubernetes MutatingAdmissionPolicy with CEL

MutatingAdmissionPolicy lets you set defaults and labels with in-process CEL instead of a mutating webhook. This page covers the design, rollout and removal of that webhook in a cluster you run.

On this page

Kubernetes MutatingAdmissionPolicy with CEL: when to replace a mutating webhook

A platform team often inherits a mutating admission webhook that adds default resource limits, stamps ownership labels or injects a sidecar setting into every new Pod. The logic is usually simple, but the webhook is a separate service that the API server must call during every matching request. If it is slow, unreachable or returns errors, requests can fail across the cluster, and a webhook that matches broad resource sets can take the API server down in practice. MutatingAdmissionPolicy is a declarative, in-process alternative: the mutation is written as CEL expressions inside a Kubernetes object, so the API server evaluates it without making a network call. The Kubernetes documentation states that MutatingAdmissionPolicy is stable since Kubernetes v1.36 and enabled by default. Confirm the minor version of your clusters before you plan the change, because older clusters will not have it available in the same form.

Use a MutatingAdmissionPolicy when the change is deterministic and depends only on the incoming object, its namespace or request metadata, and values you can supply through parameters. Setting a default label, filling an empty field or adding a standard annotation fits well. Keep the webhook when the mutation needs external data such as a lookup in a CMDB, a call to a secrets service, certificate issuance, or complex logic that a CEL expression cannot express clearly. Sidecar injection tools that need templating and per-workload configuration are a common case where a webhook remains the better choice. Before removing anything, list every webhook configuration that matches the same resources, since policies and webhooks both run during admission and their ordering affects the final object.

Plan the migration as a parallel run, not a switch. Write the policy and its binding, apply them to a non-production cluster, and compare the objects produced by the policy against those produced by the webhook for the same test requests. Then remove the webhook configuration only after the outputs match and the webhook has been retired from the matching scope. Ask your platform or tooling vendor whether they depend on the webhook's side effects, such as reading annotations it adds, because removing it can change behavior for other controllers. Record the rollback path, which is re-enabling the webhook configuration, and confirm who has permission to change admission objects in your RBAC model, since these objects can alter every workload the cluster admits.

Which MutatingAdmissionPolicy configuration fits each change

This table compares common mutation needs, from defaulting a field to applying per-namespace values, and names the option that fits each one. Read each row as a first filter, then confirm the constraint against your cluster version and the CEL features your change needs. The main takeaway is that in-process policies cover simple, declarative changes, while logic that calls external systems or needs complex state usually stays with a webhook.

ChangeOption and when it fitsMain constraint to confirm
Default a field on new objectsA MutatingAdmissionPolicy with a CEL expression that sets the field when it is absent, matched to specific resources and operationsConfirm the target cluster runs a version where the policy API is stable and enabled, and test that the expression does not overwrite values users set deliberately
Add a standard label or annotationA MutatingAdmissionPolicy that merges a fixed label into metadata, scoped by a namespace or object selectorConfirm the label must not conflict with labels controllers or Helm charts manage, since reapplied manifests can fight the policy
Apply values from parameters per namespaceA MutatingAdmissionPolicy with a parameter resource and a binding that selects namespaces, so one policy serves many teams with different valuesConfirm who owns parameter objects and that RBAC restricts edits, because a changed parameter alters every bound namespace at once
Set values that depend on external dataA mutating admission webhook, since in-process CEL cannot call external services or read arbitrary cluster stateKeep the webhook's failure policy and availability in view, because it sits in the request path and can block API calls if it is down
Only reject or check a requestA ValidatingAdmissionPolicy, which evaluates rules without changing the object and rolls out with Warn and Audit before DenyConfirm the rule does not depend on a mutation running first, since admission ordering determines what the validator sees
Complex branching, loops or large transformationsA webhook or a controller that writes the object after creation, when the CEL expression becomes hard to review and testMeasure expression readability and test coverage, because a long CEL rule is harder to audit than a small service with unit tests
Replacing an existing mutating webhookA MutatingAdmissionPolicy that reproduces the webhook's behavior, run alongside it in a test cluster before the webhook is removedConfirm every mutation the webhook performs is covered, including ones for resources or subresources the policy does not match

How ordering with validating policies affects the result

A mutating policy changes objects before validation runs, so the order of mutation, validation and Pod Security Admission decides what gets stored. Answer the questions below for each cluster before you remove or replace a webhook.

Does validation see mutated objects

Validating admission policies and validating webhooks evaluate the object after mutating admission has finished, so a mutation can make a previously rejected request pass or cause a valid request to fail. Decide which defaults and labels must exist before validation runs, and test a sample manifest through both stages. Check that your validating rules reference the fields the mutation writes, not the fields the client originally sent.

MutatingAdmissionPolicy docs

Binding scope and match conditions

A MutatingAdmissionPolicy only takes effect where a binding selects it. Decide which namespaces, resources and operations each binding covers, and whether a single policy should apply cluster-wide or be limited to a team's namespaces. Narrow match conditions reduce the chance that a mutation touches system namespaces or objects that controllers manage.

Reinvocation of mutations

Other mutating policies or webhooks may change an object after your mutation has run, and your mutation may then need to run again. Decide whether each mutation is idempotent, so a second pass does not stack labels, duplicate entries or overwrite values set by another controller. Confirm the reinvocation setting for each policy in the version you run.

Interaction with Pod Security Admission

Pod Security Admission enforces Pod Security Standards per namespace and evaluates pod specs, so a mutation that adds or changes security-relevant fields can move a pod into or out of compliance. Decide whether mutations may touch securityContext fields at all. Test each mutation in a namespace set to the Baseline or Restricted level before it reaches production namespaces.

Failure behavior during rollout

Decide what the API server should do when a policy or binding cannot run, and whether a failure should block the request or let it through. Write down the expected outcome for each failure mode, and confirm that the rollout order keeps the cluster usable if a policy is misconfigured. Keep the webhook it replaces running until the policy has passed testing in a non-production cluster.

Audit trail for mutated objects

Operators need to know which mutation changed a stored object, both when investigating incidents and when answering auditors. Decide how you will record that a mutation happened, using audit policy levels for the affected resources and by comparing stored objects with the submitted request. Plan this before rollout so the evidence exists for the first changes made by the new policies.

Migrating from a mutating webhook to MutatingAdmissionPolicy step by step

This sequence moves defaulting and labeling logic from a mutating webhook to in-process CEL policies in a controlled way, so each mutation is proven equivalent before the webhook that performs it is removed. The output is a tested policy set, documented rollback steps and a cluster with no dependency on the old webhook.

  1. Inventory every webhook mutation and its failure policy

    Someone on the platform team lists each MutatingWebhookConfiguration in the cluster, the resources and operations it matches, the namespaces and object selectors it applies to, and the failurePolicy and timeoutSeconds values set on each webhook. For every webhook, record each field it changes, such as defaults, labels, annotations, image references or sidecar injection. Mark which mutations other controllers or workloads depend on. The step is done when the team has a written table mapping each webhook to its mutations and its failure behavior, and the owner of each webhook has confirmed the list. Ask the webhook owner to confirm what it does during updates as well as creates.

  2. Write equivalent CEL mutation policies

    Platform engineers translate each recorded mutation into a MutatingAdmissionPolicy that uses CEL expressions for matching and for the patch applied to the object. Values that vary by environment or team should move into parameters rather than being hardcoded. Sidecar injection and logic that calls external services cannot be reproduced in CEL, so those items stay on the webhook or move to another mechanism, and the team records that decision. The step is done when every in-scope mutation has a policy file in version control and each policy has a short note on the webhook behavior it replaces.

  3. Bind policies with parameters in a test cluster

    In a non-production cluster, the team creates the policies, the parameter resources they reference and the bindings that scope each policy to namespaces or objects. The bindings should start narrow, covering one test namespace. Confirm in the Kubernetes mutating admission policy documentation that your cluster's API version provides the resource types you use, and check that the feature gate or default state matches your version. The step is done when the policies are accepted by the API server without errors and a test object shows the expected patch in its stored form.

  4. Compare results on sample objects

    Testers create a set of representative objects, including edge cases such as missing fields, fields that already hold a value, and objects in excluded namespaces. They submit each object with the webhook active, record the stored result, then repeat with the policies bound and the webhook disabled for that scope. A diff of the two results should show identical output for every case, or the team should document each intended difference. Include update requests and check that mutations do not repeat or conflict on each pass. The step is done when the diff is reviewed and signed off by the webhook owner and the workload owners.

  5. Run policies alongside the webhook in production

    Platform engineers bind the policies in production to a small, low-risk namespace while the webhook remains active, then widen the bindings in stages. Overlap is safe only when the policy and the webhook produce the same result, so the comparison from the previous step is the gate for each stage. Watch API server error rates, admission latency and any workload that fails to create or update. The step is done when every namespace in scope has run with both mechanisms for an agreed period and no unexplained differences appear in the audit or object history. Confirm with your cluster operations team how they will monitor admission behavior during this window.

  6. Validate ordering with validating policies

    Mutations run before validation, so the team checks that each validating policy and validating webhook still receives the object in the expected final shape. Ordering matters where a validating rule checks a label or default that a mutation now sets. Test a deliberate violation in each path to confirm the validator rejects or warns as intended after mutation. The step is done when the ordering behavior is documented and a test case covers each validation that depends on a mutated field.

  7. Remove the webhook configuration and confirm recovery

    Once every namespace runs on the policies alone, an administrator deletes the MutatingWebhookConfiguration and, if the webhook was deployed in the cluster, scales down and removes its service and deployment. Before deletion, the team keeps the previous manifests and records how to reapply them. After removal, they create a test object in each namespace and verify the expected mutations appear. The step is done when the cluster has no remaining reference to the webhook, the test objects match the expected output and the rollback procedure has been tested in the test cluster.

Parameters and bindings across environments

A cluster-wide default is the simplest case: one MutatingAdmissionPolicy applies the same mutation to every matching request, and a single binding with no parameters attaches it to the cluster. This suits values that never vary, such as adding a standard label to every Pod or setting a baseline annotation that your audit tooling expects. Because the policy is evaluated in-process by the API server, there is no external webhook to call for each request, which removes one common cause of API latency and outage.

  • Match rules: Scope the policy's match constraints to specific resources and operations so that it does not touch objects it was never meant to change.
  • Binding without parameters: A binding that omits a parameter reference applies the same fixed expressions everywhere it matches.
  • Label and annotation defaults: Standard metadata, such as an owner or cost-center label, is a common first use because the value is fixed.
  • Failure policy: Decide deliberately whether a failed mutation should fail the request or be ignored, and document that choice.
  • Ordering with validation: Confirm that the mutated object still passes your ValidatingAdmissionPolicy rules, since validation sees the result of mutation.

Before enabling a cluster-wide default, ask your platform team to test it in a non-production cluster and confirm the feature gate and version status for your Kubernetes release in the official documentation.

Security and operational risks when a mutation runs on every write

A MutatingAdmissionPolicy runs in the API server on every matching write, so the people who can create or bind policies effectively control what lands in the cluster. The cards below cover who holds that authority, how a silent mutation can change workloads, how to keep a record of changes, and why removing a stalling webhook is itself a reliability gain.

Who can write policies and bindings

Creating a MutatingAdmissionPolicy or a MutatingAdmissionPolicyBinding is a cluster-level change, so treat both as platform-owned objects. Review which subjects hold create, update, patch and delete permission on these resources through RBAC, and confirm that no application team's role includes them by accident through wildcard rules. Also check who can modify the parameter resources a binding references, because changing a parameter alters every object the policy touches.

Mutating admission policy docs

**Silent changes** to workloads

A mutation that sets a default, adds a label or rewrites a field changes the object before it is stored, so the author of the Deployment may never see the difference. For example, an illustrative policy that injects a resource limit could alter scheduling for every pod in a namespace. Before enabling a policy, compare the object as submitted with the object as stored, and confirm that GitOps tools will not repeatedly fight the mutation.

Audit trail for policy changes

Decide in advance how changes to policies, bindings and their parameters will be recorded and who reviews them. Confirm with your platform team whether your API server audit policy captures these resources at the level you need, and where those events are shipped. Your change records should show who changed a mutation, when, and through which pull request or change ticket.

Reviewing the effect of each mutation

Before a binding goes live, run server-side dry runs against representative manifests and compare the results with the expected output. Keep a set of test objects in version control so that a policy change triggers the same checks as an application change. Record which namespaces each binding selects so reviewers can see the blast radius of a single edit.

Removing a webhook that stalls requests

A mutating webhook sits in the request path, so an unavailable or slow endpoint can block writes across the cluster, depending on its failure policy and selectors. Replacing that webhook with an in-process CEL mutation removes a network dependency from every write. Inventory each existing mutating webhook, note its failure policy and object selectors, and plan the cutover so the new policy is in place before the webhook is deleted.

Separating duties between platform and teams

Keep policy authorship with the platform group and give application teams a documented way to request exceptions. Use namespace or label selectors in bindings so that exemptions are explicit and reviewable, instead of relying on informal conventions. Confirm which group approves changes to parameters and who holds the emergency procedure for disabling a binding.

How an API request moves through mutating policies, validation and the webhook it replaces

A request starts at the client and passes authentication and authorization before admission begins. Built-in mutating admission runs the MutatingAdmissionPolicy objects first, which apply CEL expressions in process, and any mutating webhooks you have not yet removed run after them. Schema validation and then validating admission follow, so policies that set defaults or labels finish before validation checks the result. Check which webhooks still sit in the mutating chain, and treat the policy author as a trust boundary because a policy can change every matching object.

Request path through mutation, validation and persistence, with the policy author's trust boundary marked.

Limits to confirm in your cluster before you remove a webhook

A mutating webhook can do things a declarative policy cannot, and a policy can behave differently from what your team expects on existing objects. The cards below list what to confirm against your cluster version and the official reference before you delete a webhook.

Supported CEL functions and fields

Confirm which CEL functions, libraries and object fields the mutation expressions can reference in the Kubernetes version you run. Your webhook may read annotations, call helper logic or compute values that a policy expression cannot express. List every field and function the current webhook uses, then check each one against the reference. Any gap means the logic must be redesigned or kept in a webhook.

MutatingAdmissionPolicy docs

Cluster version and feature availability

Confirm the API version and feature gate state on every control plane node before you depend on the policy. The feature is stable and enabled by default starting with Kubernetes v1.36, so clusters on earlier minor versions need a different plan. Check that the API group serves the resource and that your distribution does not disable it. Upgrade order matters here, so tie this check to your upgrade plan.

Behavior on existing objects

Confirm whether a policy applies only to new requests or also changes how existing objects are handled on update, and how reinvocation interacts with other mutations. A policy that sets a label on every update may change objects that controllers manage. Test with a copy of production objects in a non-production cluster and compare the stored result with what the webhook produced.

Webhook-only behavior to preserve

Inventory the cases your webhook handles that a policy cannot, such as calls to external systems, lookups in other APIs, secrets retrieval or logic that depends on state outside the request. Each case needs a replacement, a controller that reconciles the result, or a decision to keep a narrow webhook. Document this list before you remove anything, so the trade-off is visible to security and platform owners.

Failure behavior and ordering

Confirm how the policy and any remaining webhooks are ordered, and how failures surface to clients. Check the failure policy and what happens when a binding matches more resources than intended. Verify ordering with validating policies in a test namespace, since a validating check may run against a value that a mutation changed or against one it did not.

Official reference and vendor notes

Check the current official reference and your distribution's release notes for limits and changes that apply to your version. Ask your distribution vendor or support contact to confirm any behavior that the upstream docs leave open for your build, and record their answer in your change request.

Kubernetes releases

Questions teams ask before hiring help with MutatingAdmissionPolicy

What drives the cost of replacing mutating webhooks with MutatingAdmissionPolicy?

The main drivers are the number of webhook mutations to convert, how many clusters they run in, how deep the testing must go, and how formal your change control is. Each mutation needs a CEL expression, a binding and often a parameter resource, so a short list of simple defaults and labels costs far less than a large set of conditional rewrites that touch many resource kinds. Ask any partner for a written scope that lists each mutation, the clusters covered and the test cases, since a fixed-scope quote follows from that document. DeployOpen does not publish a price list.

How long does a MutatingAdmissionPolicy migration take?

Duration depends on the same factors as cost: the number of webhook mutations, the number of clusters, the testing depth and how quickly your owners can review changes. Inventory and review of each webhook usually take longer than writing the policies themselves, because the behavior of an undocumented webhook has to be confirmed before it can be copied. Ask for a timeline tied to milestones in the written scope, such as inventory complete, policies tested in a non-production cluster and rollout per cluster, rather than a single end date.

What must our internal team provide before the work starts?

Your team needs to provide a complete webhook inventory and a named owner for each webhook. For every entry, the owner should describe the resources it matches, the fields it sets, the conditions under which it acts, the failure policy and any namespace or object selectors. Access to non-production clusters, a change window, and someone who can approve the final rollout are also required. Without these, the work stalls on questions that only your teams can answer.

Can our platform team do the MutatingAdmissionPolicy work alone?

A capable platform team can do it alone if it has time to inventory every webhook, read the Kubernetes documentation for the feature, and test each policy against realistic resource manifests. The risk is in the testing and the ordering with validating rules, not in the YAML itself. Teams with many webhook owners or limited cluster access often find an outside review useful for the test plan and rollout sequence. Decide this from your inventory size and staff capacity, then confirm the split of work in writing.

Can we safely remove a mutating webhook once policies replace it?

You can retire a webhook safely only after the replacement produces the same object changes across the resource kinds, namespaces and operations the webhook covered, and after you have confirmed that no other team depends on the webhook's side effects. Keep the webhook configuration in place while you compare results in non-production, then remove it in a controlled change. Removing a webhook that is unavailable or misconfigured is a common source of outages in the API server path, so plan a rollback step and record who approved the removal.

Does the feature cover every mutation a webhook performs?

Not necessarily. MutatingAdmissionPolicy is stable since Kubernetes v1.36 and enabled by default, and it is a declarative, in-process alternative to mutating admission webhooks. Logic that calls external systems, uses state outside the request, or needs complex code will not map cleanly to CEL. Confirm each webhook's behavior against the Kubernetes mutating admission policy documentation and keep any mutation that cannot be expressed declaratively on a webhook you still operate.

How does ordering with validating policies affect the design?

Mutations run before validation during admission, so a validating rule sees the object after defaults and labels have been applied. Design each mutation so that the object it produces passes the validations that depend on it, and test that combination rather than each rule alone. Teams that already use ValidatingAdmissionPolicy should review both sets together, because a change in one can alter what the other sees. Confirm the exact ordering behavior for your Kubernetes version in the official documentation before you write the test plan.

How DeployOpen scopes and delivers a MutatingAdmissionPolicy migration

DeployOpen scopes a MutatingAdmissionPolicy migration as a fixed-scope engagement, with the scope, deliverables and timeline agreed in writing before any work starts. The written scope starts with a webhook inventory: every MutatingWebhookConfiguration, the rules it matches, its failurePolicy, timeoutSeconds, the namespaces and objects it selects, and the owner of the service behind it. Each mutation is then classified by what it does (defaults, labels, injected sidecars, or logic that needs an external call). Only the first two classes are usually good candidates for CEL-based policies, so the inventory decides how much of the webhook estate can move. Ask for this inventory as a named deliverable, because it sets the rest of the quote.

The second part of the scope covers policy design, test evidence, rollout and removal. Policy design defines each MutatingAdmissionPolicy, its MutatingAdmissionPolicyBinding, any parameter resource, and the ordering against existing ValidatingAdmissionPolicy objects. Test evidence shows that the policies produce the same object changes as the webhook on representative requests, including the failure paths. Rollout should be staged in a non-production cluster first, and removal of the webhook should happen only after the policies have run cleanly in the target environment. The hand-over includes the policy manifests, bindings, parameter objects, test suites, a rollback procedure and a runbook for the platform team. Confirm with us which Kubernetes version your clusters run, since the feature is stable and enabled by default from v1.36 according to the Kubernetes documentation.

Ongoing support for policy changes, Kubernetes upgrades and periodic review of new webhooks is available as a retainer, which you can scope separately from the migration. A quote follows from the written scope, so the factors that move it are the number of webhooks, how many mutations depend on external services, the number of clusters and environments, and whether your team or DeployOpen performs the production rollout. Ask for each of these to be listed as separate line items with their assumptions, so you can see what is one-time work and what recurs.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.