Loading...

Remediate your Azure Kubernetes Service clusters at scale using Azure Policy’s mutation support!

Remediate your Azure Kubernetes Service clusters at scale using Azure Policy’s mutation support!

We are thrilled to announce Azure Policy for Kubernetes Public Preview support for Mutation, available for Azure Kubernetes Service clusters! This release is brought to you in collaboration with Azure Kubernetes Service and Azure Container Compute Upstream.

 

Gatekeeper's mutation capability enables users to change Kubernetes resources at create/update time based on different criteria defined in mutation templates. By embedding mutation templates in your Azure Policy custom definitions, Azure Policy extends Gatekeeper’s mutation feature to programmatically modify components within your Kubernetes clusters at-scale across your subscriptions and management groups, with the help of various Azure Policy features, like selectors and overrides. For an overview of Azure Policy capabilities for Kubernetes, go to Azure Policy for Kubernetes.

 

When using mutation, you can do things like:

  • Ensure all pods in a given scope have imagePullPolicy set
  • Setting security context of containers in a selected scope to be non-privileged
  • Adding a sidecar to a Pod

 

Get started

 

Here’s an example of a simple Gatekeeper mutation template, pulled from Gatekeeper documentation. It is annotated to highlight a few things:

MutationTemplateAnnotated.jpg

Note: Azure Policy for Kubernetes does not currently support Gatekeeper’s ‘AssignImage’ mutator

 

You can choose to author your own mutation templates to embed in Azure Policy definitions, or you can use a sample from an existing repository, such as the Gatekeeper library.

 

Note: you will need to register the mutation feature on subscription(s) that you’d like to assign mutation policies within. The mutation feature’s resource ID is: Microsoft.Features/providers/Microsoft.ContainerService/features/AKS-AzurePolicyMutation

For more information, go to: Set up preview features in Azure subscription - Azure Resource Manager | Microsoft Learn.

 

When crafting a mutation policy definition, use the ‘mutationInfo’ property to embed your mutation template in your JSON definition. To learn more, go to: Understand how effects work - Azure Policy | Microsoft Learn. You can apply mutation policies similarly to how you apply other Azure Policies today (such as via API, Portal and PowerShell). This example will walk you through applying a mutation definition through the Azure Portal.

 

Azure Portal

 

  1. Go to Azure Policy’s Portal view by searching ‘Policy’. Next, click the ‘Definitions’ tab to create a new definition.

PolicyPortal1.jpg

  1. Create your Azure custom policy with a mutation template embedded. Ensure that you are using mode = “Microsoft.Kubernetes.Data”. Note that the “mutate” effect only works with mutation templates, not constraint templates.
  2. Assign your policy definition to the scope of your choice (such as your management group, subscription or resource group)

 

MutationPolicyPortal3.jpg

 

This definition will then apply to all clusters in that scope! You can choose to leverage Azure Policy's exclusions or exemptions if certain clusters should not be mutated by this policy assignment.

 

Your work is done! You can navigate to the ‘Compliance’ view to see all the clusters in scope for this mutation policy assignment.

 

If you run into issues, feel free to navigate to our troubleshooting tools in ‘Related Resources’. Try it out, and we would love to hear what you think in the comments below!

 

For related resources, go to:

 

Published on:

Learn more
Need help with this product?

We can help you with Remediate your Azure Kubernetes Service clusters at scale using Azure Policy’s mutation support!

If you want help implementing, troubleshooting, or improving this product, contact us and we’ll point you in the right direction.

Azure Governance and Management Blog articles
Azure Governance and Management Blog articles

Azure Governance and Management Blog articles

Share post:

Related posts

Azure Landing Zones - Policy Refresh Q1 FY25

ALZ - Policy Refresh Q1 FY25 is here! As you may be aware, the ALZ team release cadence is now on quarterly basis to help customers and partne...

1 year ago

Custom Policy- Reusable Logs Templates

Reusable Templates for Sending Logs to Log Analytics Workspace   Challenge:   When it comes to developing custom policies for sendin...

1 year ago

Enhancements to Azure Monitor Baseline Alerts for Azure Landing Zones

Introduction   Welcome to our latest blog post where we dive into a number of exciting new key updates, highlight the new portal accelera...

1 year ago

Introducing the Azure Policy Community Repo

Introducing the Azure Policy Community Repo   What is the Azure Policy Community Repo? The Azure Policy Community Repo is a collaborativ...

2 years ago

General Availability: Vaulted backups for Azure Blob Storage

We are excited to announce the general availability of vaulted backups for Azure Blob Storage. Vaulted backups can help you achieve complete p...

2 years ago

Azure Update Manager to support CIS hardened images among other images

What’s coming in by end of July 2024: Azure Update Manager will add support for 35 CIS hardened images. This is the first time that Update Man...

2 years ago

Mastering your cloud journey: Essentials to Innovating, Migrating and Modernizing, on Azure

We are living during a time of rapid growth in AI technologies and seeing cloud complexity increase as a result of those advanced workloads, w...

2 years ago

Public Preview Announcement: Azure Policy Built-in Versioning

Welcome to a new era of policy management, where policy definitions are more agile, adaptable, and accessible than ever before! We are thrille...

2 years ago

Announcing Azure Monitoring Agent support in Azure Landing Zones

Introduction   Hello and welcome to another blog post about Azure Landing Zones, the best practice framework for accelerating your cloud...

2 years ago

Announcing the General Availability of Change Actor

Change Analysis  Identifying who made a change to your Azure resources and how the change was made just became easier! With Change Analys...

2 years ago

Newsletter

Get the latest Dynamics 365 and Power Platform content in your inbox

A curated digest of community blogs, product news, videos, and podcasts — delivered without the noise.

Weekly updates Unsubscribe anytime Fresh community picks
We use your email only for the newsletter and you can unsubscribe at any time.
By subscribing, you agree to the privacy policy.