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
Azure Governance and Management Blog articles
Azure Governance and Management Blog articles

Azure Governance and Management Blog articles

Share post:

Related posts

Coding at the Speed of Innovation: AI and more with Azure SQL Database

The Azure SQL Database team is all set to unveil new product announcements as Build 2024 approaches. Innovation is the prominent theme this ti...

1 day ago

Generate insights from audio and video data using Speech analytics in Azure AI Studio

In this video, we explore the power of speech analytics in Azure AI Studio to extract insights from audio and video data. This technology help...

1 day ago

Azure Custom Policy- PostgreSQL Product - Compliance Report not Available- New Feature Request

If you're attempting to create custom policies for Azure Cosmos DB for PostgreSQL at the subscription level and are running into issues where ...

1 day ago

Microsoft Causes Fuss Around Azure MFA Announcement

Microsoft's recent announcement regarding the requirement of Azure MFA for connections to services starting in July 2024 has caused quite a st...

1 day ago

PostgreSQL for your AI app's backend | Azure Database for PostgreSQL Flexible Server

If you want to use Postgres as a managed service on Azure and build generative AI apps, then the Azure Database for Postgres Flexible Server i...

1 day ago

Storage migration: Combine Azure Storage Mover and Azure Data Box

If you are looking to migrate your data from on-premises to Azure Storage, it can be challenging, but with Microsoft's solutions, you can make...

1 day ago

Loop DDoS Attacks: Understanding the Threat and Azure's Defense

This article provides a comprehensive overview of Loop DDoS attacks, a sophisticated and evolving cybersecurity threat that exploits applicati...

2 days ago

Azure Communication Services at Microsoft Build 2024

Join us for Microsoft Build 2024, either in-person in Seattle or virtually, to learn about the latest updates from Azure Communication Service...

2 days ago

Azure Developer CLI (azd) – May 2024 Release

The Azure Developer CLI (`azd`) has received a May 2024 update, version 1.9.0, making it simpler for developers to create, manage, and deploy ...

2 days ago

Join us at Build 2024: Get the latest on Azure Cosmos DB in Seattle or online!

Join Microsoft Build 2024 to get a sneak peek into the future of AI and data innovation. Taking place in Seattle and online from May 21 to 23,...

2 days ago
Stay up to date with latest Microsoft Dynamics 365 and Power Platform news!
* Yes, I agree to the privacy policy