Skip to content

Commit e96d2c1

Browse files
Merge pull request #108623 from DCtheGeek/dmc-policy-akschanges
Changes for OPA and AKS Engine
2 parents 9c81892 + 087f537 commit e96d2c1

File tree

3 files changed

+103
-87
lines changed

3 files changed

+103
-87
lines changed

articles/governance/policy/concepts/effects.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Understand how effects work
33
description: Azure Policy definitions have various effects that determine how compliance is managed and reported.
4-
ms.date: 11/04/2019
4+
ms.date: 03/23/2020
55
ms.topic: conceptual
66
---
77
# Understand Azure Policy effects
@@ -532,17 +532,16 @@ not, then a deployment to enable is executed.
532532
This effect is used with a policy definition *mode* of `Microsoft.Kubernetes.Data`. It's used to
533533
pass Gatekeeper v3 admission control rules defined with
534534
[OPA Constraint Framework](https://github.com/open-policy-agent/frameworks/tree/master/constraint#opa-constraint-framework)
535-
to [Open Policy Agent](https://www.openpolicyagent.org/) (OPA) to self-managed Kubernetes clusters
536-
on Azure.
535+
to [Open Policy Agent](https://www.openpolicyagent.org/) (OPA) to Kubernetes clusters on Azure.
537536

538537
> [!NOTE]
539-
> [Azure Policy for AKS Engine](aks-engine.md) is in Public Preview and only supports built-in
540-
> policy definitions.
538+
> [Azure Policy for Kubernetes](aks-engine.md) is in Preview and only supports built-in policy
539+
> definitions.
541540
542541
### EnforceOPAConstraint evaluation
543542

544543
The Open Policy Agent admission controller evaluates any new request on the cluster in real time.
545-
Every 5 minutes, a full scan of the cluster is completed and the results reported to Azure Policy.
544+
Every 15 minutes, a full scan of the cluster is completed and the results reported to Azure Policy.
546545

547546
### EnforceOPAConstraint properties
548547

@@ -561,10 +560,10 @@ Gatekeeper v3 admission control rule.
561560
- Defines any parameters and values to pass to the Constraint. Each value must exist in the
562561
Constraint template CRD.
563562

564-
### EnforceRegoPolicy example
563+
### EnforceOPAConstraint example
565564

566-
Example: Gatekeeper v3 admission control rule to set container CPU and memory resource limits in AKS
567-
Engine.
565+
Example: Gatekeeper v3 admission control rule to set container CPU and memory resource limits in
566+
Kubernetes.
568567

569568
```json
570569
"if": {
@@ -603,9 +602,11 @@ to pass Gatekeeper v2 admission control rules defined with
603602
[Open Policy Agent](https://www.openpolicyagent.org/) (OPA) on
604603
[Azure Kubernetes Service](../../../aks/intro-kubernetes.md).
605604

606-
> [!NOTE]
607-
> [Azure Policy for AKS](rego-for-aks.md) is in Limited Preview and only supports built-in policy
608-
> definitions
605+
> [!IMPORTANT]
606+
> [Azure Policy for Kubernetes](rego-for-aks.md) is in Preview and only supports built-in policy
607+
> definitions. Built-in policies are in the **Kubernetes** category. The **EnforceRegoPolicy**
608+
> effect and related **Kubernetes Service** category policies are being _deprecated_. Instead, use
609+
> the updated [EnforceOPAConstraint](#enforceopaconstraint) effect.
609610
610611
### EnforceRegoPolicy evaluation
611612

articles/governance/policy/concepts/rego-for-aks.md

Lines changed: 89 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
---
22
title: Learn Azure Policy for Azure Kubernetes Service
3-
description: Learn how Azure Policy uses Rego and Open Policy Agent to manage clusters on Azure Kubernetes Service.
4-
ms.date: 03/18/2020
3+
description: Learn how Azure Policy uses Rego and Open Policy Agent to manage clusters on Azure Kubernetes Service.
4+
ms.date: 03/23/2020
55
ms.topic: conceptual
66
---
77
# Understand Azure Policy for Azure Kubernetes Service
88

99
Azure Policy integrates with the [Azure Kubernetes Service](../../../aks/intro-kubernetes.md) (AKS)
1010
to apply at-scale enforcements and safeguards on your clusters in a centralized, consistent manner.
11-
By extending use of
12-
[Gatekeeper](https://github.com/open-policy-agent/gatekeeper/tree/master/deprecated) v2, an
13-
_admission controller webhook_ for [Open Policy Agent](https://www.openpolicyagent.org/) (OPA),
14-
Azure Policy makes it possible to manage and report on the compliance state of your Azure resources
15-
and AKS clusters from one place.
11+
By extending use of [Gatekeeper](https://github.com/open-policy-agent/gatekeeper) v3, an _admission
12+
controller webhook_ for [Open Policy Agent](https://www.openpolicyagent.org/) (OPA), Azure Policy
13+
makes it possible to manage and report on the compliance state of your Azure resources and AKS
14+
clusters from one place.
1615

17-
> [!NOTE]
18-
> Azure Policy for AKS is in Limited Preview and only supports built-in policy definitions.
16+
> [!IMPORTANT]
17+
> [Azure Policy for AKS](rego-for-aks.md) is in Preview and only supports built-in policy
18+
> definitions. Built-in policies are in the **Kubernetes** category. The **EnforceRegoPolicy**
19+
> effect and related **Kubernetes Service** category policies are being _deprecated_. Instead, use
20+
> the updated [EnforceOPAConstraint](./effects.md#enforceopaconstraint) effect.
1921
2022
## Overview
2123

@@ -28,9 +30,9 @@ To enable and use Azure Policy for AKS with your AKS cluster, take the following
2830

2931
## Opt-in for preview
3032

31-
Before installing the Azure Policy Add-on or enabling any of the service features, your subscription
32-
must enable the **Microsoft.ContainerService** resource provider and the
33-
**Microsoft.PolicyInsights** resource provider, then be approved to join the preview. To join the
33+
Before you install the Azure Policy Add-on or enabling any of the service features, your
34+
subscription must enable the **Microsoft.ContainerService** resource provider and the
35+
**Microsoft.PolicyInsights** resource provider, then get approved to join the preview. To join the
3436
preview, follow these steps in either the Azure portal or with Azure CLI:
3537

3638
- Azure portal:
@@ -57,7 +59,7 @@ preview, follow these steps in either the Azure portal or with Azure CLI:
5759
```azurecli-interactive
5860
# Log in first with az login if you're not using Cloud Shell
5961
60-
# Provider register: Register the Azure Kubernetes Services provider
62+
# Provider register: Register the Azure Kubernetes Service provider
6163
az provider register --namespace Microsoft.ContainerService
6264
6365
# Provider register: Register the Azure Policy provider
@@ -72,27 +74,19 @@ preview, follow these steps in either the Azure portal or with Azure CLI:
7274
# Once the above shows 'Registered' run the following to propagate the update
7375
az provider register -n Microsoft.ContainerService
7476
75-
# Feature register: enables the add-on to call the Azure Policy resource provider
76-
az feature register --namespace Microsoft.PolicyInsights --name AKS-DataPlaneAutoApprove
77-
78-
# Use the following to confirm the feature has registered
79-
az feature list -o table --query "[?contains(name, 'Microsoft.PolicyInsights/AKS-DataPlaneAutoApprove')].{Name:name,State:properties.state}"
80-
81-
# Once the above shows 'Registered' run the following to propagate the update
82-
az provider register -n Microsoft.PolicyInsights
83-
8477
```
8578

8679
## Azure Policy Add-on
8780

8881
The _Azure Policy Add-on_ for Kubernetes connects the Azure Policy service to the Gatekeeper
89-
admission controller. The add-on, which is installed into the _azure-policy_ namespace, enacts the
82+
admission controller. The add-on, which is installed into the _kube-system_ namespace, enacts the
9083
following functions:
9184

92-
- Checks with Azure Policy for assignments to the AKS cluster
93-
- Downloads and caches policy details, including the _rego_ policy definition, as **configmaps**
94-
- Runs a full scan compliance check on the AKS cluster
95-
- Reports auditing and compliance details back to Azure Policy
85+
- Checks with Azure Policy service for assignments to the cluster.
86+
- Deploys policies in the cluster as
87+
[constraint template](https://github.com/open-policy-agent/gatekeeper#constraint-templates) and
88+
[constraint](https://github.com/open-policy-agent/gatekeeper#constraints) custom resources.
89+
- Reports auditing and compliance details back to Azure Policy service.
9690

9791
### Installing the add-on
9892

@@ -101,10 +95,13 @@ following functions:
10195
Before you install the add-on in your AKS cluster, the preview extension must be installed. This
10296
step is done with Azure CLI:
10397

98+
1. If Gatekeeper v2 policies were installed, remove the add-on with the **Disable** button on your
99+
AKS cluster under the **Policies (preview)** page.
100+
104101
1. You need the Azure CLI version 2.0.62 or later installed and configured. Run `az --version` to
105102
find the version. If you need to install or upgrade, see [Install the Azure CLI](/cli/azure/install-azure-cli).
106103

107-
1. The AKS cluster must be version _1.10_ or higher. Use the following script to validate your AKS
104+
1. The AKS cluster must be version _1.14_ or higher. Use the following script to validate your AKS
108105
cluster version:
109106

110107
```azurecli-interactive
@@ -152,7 +149,8 @@ manage.
152149

153150
> [!NOTE]
154151
> If the **Enable add-on** button is grayed out, the subscription has not yet been added to the
155-
> preview. See [Opt-in for preview](#opt-in-for-preview) for the required steps.
152+
> preview. See [Opt-in for preview](#opt-in-for-preview) for the required steps. If a
153+
> **Disable** button is available, Gatekeeper v2 is still installed and must be removed.
156154
157155
- Azure CLI
158156

@@ -164,81 +162,98 @@ manage.
164162

165163
### Validation and reporting frequency
166164

167-
The add-on checks in with Azure Policy for changes in policy assignments every 5 minutes. During
168-
this refresh cycle, the add-on removes all _configmaps_ in the _azure-policy_ namespace then
169-
recreates the _configmaps_ for Gatekeeper use.
165+
The add-on checks in with Azure Policy service for changes in policy assignments every 15 minutes.
166+
During this refresh cycle, the add-on checks for changes. These changes trigger creates, updates, or
167+
deletes of the constraint templates and constraints.
170168

171169
> [!NOTE]
172-
> While a _cluster admin_ may have permission to the _azure-policy_ namespace, it's not recommended
173-
> or supported to make changes to the namespace. Any manual changes made are lost during the
174-
> refresh cycle.
170+
> While a cluster admin may have permission to create and update constraint templates and
171+
> constraints resources, these are not supported scenarios as manual updates will be overwritten.
175172
176-
Every 5 minutes, the add-on calls for a full scan of the cluster. After gathering details of the
173+
Every 15 minutes, the add-on calls for a full scan of the cluster. After gathering details of the
177174
full scan and any real-time evaluations by Gatekeeper of attempted changes to the cluster, the
178-
add-on reports the results back to Azure Policy for inclusion in
179-
[compliance details](../how-to/get-compliance-data.md) like any Azure Policy assignment. Only
180-
results for active policy assignments are returned during the audit cycle.
175+
add-on reports the results back to Azure Policy service for inclusion in
176+
[compliance details](../how-to/get-compliance-data.md#portal) like any Azure Policy assignment. Only
177+
results for active policy assignments are returned during the audit cycle. Audit results can also be
178+
seen as [violations](https://github.com/open-policy-agent/gatekeeper#audit) listed in the status
179+
field of the failed constraint.
181180

182181
## Policy language
183182

184-
The Azure Policy language structure for managing AKS follows that of existing policies. The effect
185-
_EnforceRegoPolicy_ is used to manage your AKS clusters and takes _details_ properties specific to
186-
working with OPA and Gatekeeper v2. For details and examples, see the
187-
[EnforceRegoPolicy](effects.md#enforceregopolicy) effect.
188-
189-
As part of the _details.policy_ property in the policy definition, Azure Policy passes the URI of a
190-
rego policy to the add-on. Rego is the language that OPA and Gatekeeper support to validate or
191-
mutate a request to the Kubernetes cluster. By supporting an existing standard for Kubernetes
192-
management, Azure Policy makes it possible to reuse existing rules and pair them with Azure Policy
193-
for a unified cloud compliance reporting experience. For more information, see
183+
The Azure Policy language structure for managing Kubernetes follows that of existing policies. The
184+
effect _EnforceOPAConstraint_ is used to manage your Kubernetes clusters and takes details
185+
properties specific to working with
186+
[OPA Constraint Framework](https://github.com/open-policy-agent/frameworks/tree/master/constraint)
187+
and Gatekeeper v3. For details and examples, see the
188+
[EnforceOPAConstraint](./effects.md#enforceopaconstraint) effect.
189+
190+
As part of the _details.constraintTemplate_ and _details.constraint_ properties in the policy
191+
definition, Azure Policy passes the URIs of these
192+
[CustomResourceDefinitions](https://github.com/open-policy-agent/gatekeeper#constraint-templates)
193+
(CRD) to the add-on. Rego is the language that OPA and Gatekeeper support to validate a request to
194+
the Kubernetes cluster. By supporting an existing standard for Kubernetes management, Azure Policy
195+
makes it possible to reuse existing rules and pair them with Azure Policy for a unified cloud
196+
compliance reporting experience. For more information, see
194197
[What is Rego?](https://www.openpolicyagent.org/docs/latest/policy-language/#what-is-rego).
195198

196199
## Built-in policies
197200

198-
To find the built-in policies for managing AKS using the Azure portal, follow these steps:
201+
To find the built-in policies for managing your cluster using the Azure portal, follow these steps:
199202

200-
1. Start the Azure Policy service in the Azure portal. Select **All services** in the left pane and
201-
then search for and select **Policy**.
203+
1. Start the Azure Policy service in the Azure portal. Select All services in the left pane and then
204+
search for and select **Policy**.
202205

203206
1. In the left pane of the Azure Policy page, select **Definitions**.
204207

205-
1. From the Category drop-down list box, use **Select all** to clear the filter and then select
206-
**Kubernetes service**.
208+
1. From the Category drop-down list box, use Select all to clear the filter and then select
209+
**Kubernetes**.
207210

208211
1. Select the policy definition, then select the **Assign** button.
209212

210-
> [!NOTE]
211-
> When assigning the Azure Policy for AKS definition, the **Scope** must include the AKS cluster
212-
> resource.
213+
1. Set the **Scope** to the management group, subscription, or resource group of the Kubernetes
214+
cluster where the policy assignment will apply.
215+
216+
> [!NOTE]
217+
> When assigning the Azure Policy for AKS definition, the **Scope** must include the AKS cluster
218+
> resource.
219+
220+
1. Give the policy assignment a **Name** and **Description** that you can use to identify it easily.
221+
222+
1. Set the [Policy enforcement](./assignment-structure.md#enforcement-mode) to one of the values
223+
below.
224+
225+
- **Enabled** - Enforce the policy on the cluster. Kubernetes admission requests with violations
226+
are denied.
227+
228+
- **Disabled** - Don't enforce the policy on the cluster. Kubernetes admission requests with
229+
violations aren't denied. Compliance assessment results are still available. When rolling out
230+
new policies to running clusters, _Disabled_ option is helpful for testing the policies as
231+
admission requests with violations aren't denied.
232+
233+
1. Select **Next**.
234+
235+
1. Set **parameter values**
236+
237+
- To exclude Kubernetes namespaces from policy evaluation, specify the list of namespaces in
238+
parameter **Namespace exclusions**. It's recommended to exclude: _kube-system_
239+
240+
1. Select **Review + create**.
213241

214242
Alternately, use the [Assign a policy - Portal](../assign-policy-portal.md) quickstart to find and
215243
assign an AKS policy. Search for a Kubernetes policy definition instead of the sample 'audit vms'.
216244

217245
> [!IMPORTANT]
218-
> Built-in policies in category **Kubernetes service** are only for use with AKS.
246+
> Built-in policies in category **Kubernetes** are only for use with AKS. For a list of built-in
247+
> policies, see [../samples/built-in-policies.md#kubernetes]
219248
220249
## Logging
221250

222251
### Azure Policy Add-on logs
223252

224-
As a Kubernetes controller/container, the Azure Policy Add-on keeps logs in the AKS cluster. The
225-
logs are exposed in the **Insights** page of the AKS cluster. For more information, see
253+
As a Kubernetes controller/container, both Azure Policy Add-on and Gatekeeper keep logs in the AKS
254+
cluster. The logs are exposed in the **Insights** page of the AKS cluster. For more information, see
226255
[Understand AKS cluster performance with Azure Monitor for containers](../../../azure-monitor/insights/container-insights-analyze.md).
227256

228-
### Gatekeeper logs
229-
230-
To enable Gatekeeper logs for new resource requests, follow the steps in [Enable and review Kubernetes master node logs in AKS](../../../aks/view-master-logs.md).
231-
Here is an example query to view denied events on new resource requests:
232-
233-
```kusto
234-
| where Category == "kube-audit"
235-
| where log_s contains "admission webhook"
236-
| limit 100
237-
```
238-
239-
To view logs from Gatekeeper containers, follow the steps in [Enable and review Kubernetes master node logs in AKS](../../../aks/view-master-logs.md)
240-
and check the _kube-apiserver_ option in the **Diagnostic settings** pane.
241-
242257
## Remove the add-on
243258

244259
To remove the Azure Policy Add-on from your AKS cluster, use either the Azure portal or Azure CLI:

articles/governance/policy/toc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
- name: Azure Policy for Kubernetes
8282
items:
8383
- name: Policy for AKS
84-
displayName: aks, rego, k8s, opa, open policy agent, gatekeeper, v2
84+
displayName: aks, rego, k8s, opa, open policy agent, gatekeeper, v3, crd, constraints
8585
href: ./concepts/rego-for-aks.md
8686
- name: Policy for AKS Engine
8787
displayName: aks, k8s, opa, open policy agent, gatekeeper, v3, crd, constraints

0 commit comments

Comments
 (0)