Skip to content

Commit 6ab0aa9

Browse files
Merge pull request #244505 from schaffererin/aks-image-integrity
AKS Image Integrity doc updates
2 parents dda1cbf + 9ee9d56 commit 6ab0aa9

File tree

3 files changed

+243
-0
lines changed

3 files changed

+243
-0
lines changed

articles/aks/TOC.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,8 @@
343343
href: ../defender-for-cloud/defender-for-containers-enable.md?tabs=aks-deploy-portal%2Ck8s-deploy-asc%2Ck8s-verify-asc%2Ck8s-remove-arc%2Caks-removeprofile-api&pivots=defender-for-container-aks?toc=/azure/aks/toc.json&bc=/azure/aks/breadcrumb/toc.json
344344
- name: Image security
345345
items:
346+
- name: Validate signed images with Image Integrity
347+
href: image-integrity.md
346348
- name: Remove vulnerable images with ImageCleaner
347349
href: image-cleaner.md
348350
- name: Scan images in your CI/CD Workflow

articles/aks/image-integrity.md

Lines changed: 241 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
1+
---
2+
title: Use Image Integrity to validate signed images before deploying them to your Azure Kubernetes Service (AKS) clusters (Preview)
3+
description: Learn how to use Image Integrity to validate signed images before deploying them to your Azure Kubernetes Service (AKS) clusters.
4+
author: schaffererin
5+
ms.author: schaffererin
6+
ms.service: azure-kubernetes-service
7+
ms.topic: article
8+
ms.date: 09/26/2023
9+
---
10+
11+
# Use Image Integrity to validate signed images before deploying them to your Azure Kubernetes Service (AKS) clusters (Preview)
12+
13+
Azure Kubernetes Service (AKS) and its underlying container model provide increased scalability and manageability for cloud native applications. With AKS, you can launch flexible software applications according to the runtime needs of your system. However, this flexibility can introduce new challenges.
14+
15+
In these application environments, using signed container images helps verify that your deployments are built from a trusted entity and that images haven't been tampered with since their creation. Image Integrity is a service that allows you to add an Azure Policy built-in definition to verify that only signed images are deployed to your AKS clusters.
16+
17+
> [!NOTE]
18+
> Image Integrity is a feature based on [Ratify][ratify]. On an AKS cluster, the feature name and property name is `ImageIntegrity`, while the relevant Image Integrity pods' names contain `Ratify`.
19+
20+
[!INCLUDE [preview features callout](includes/preview/preview-callout.md)]
21+
22+
## Prerequisites
23+
24+
* An Azure subscription. If you don't have an Azure subscription, you can create a [free account](https://azure.microsoft.com/free).
25+
* [Azure CLI][azure-cli-install] or [Azure PowerShell][azure-powershell-install].
26+
* `aks-preview` CLI extension version 0.5.96 or later.
27+
* Ensure that the Azure Policy add-on for AKS is enabled on your cluster. If you don't have this add-on installed, see [Install Azure Policy add-on for AKS](../governance/policy/concepts/policy-for-kubernetes.md#install-azure-policy-add-on-for-aks).
28+
* An AKS cluster enabled with OIDC Issuer. To create a new cluster or update an existing cluster, see [Configure an AKS cluster with OIDC Issuer](./use-oidc-issuer.md).
29+
* The `EnableImageIntegrityPreview` and `AKS-AzurePolicyExternalData` feature flags registered on your Azure subscription. Register the feature flags using the following commands:
30+
31+
1. Register the `EnableImageIntegrityPreview` and `AKS-AzurePolicyExternalData` feature flags using the [`az feature register`][az-feature-register] command.
32+
33+
```azurecli-interactive
34+
# Register the EnableImageIntegrityPreview feature flag
35+
az feature register --namespace "Microsoft.ContainerService" --name "EnableImageIntegrityPreview"
36+
37+
# Register the AKS-AzurePolicyExternalData feature flag
38+
az feature register --namespace "Microsoft.ContainerService" --name "AKS-AzurePolicyExternalData"
39+
```
40+
41+
It may take a few minutes for the status to show as *Registered*.
42+
43+
2. Verify the registration status using the [`az feature show`][az-feature-show] command.
44+
45+
```azurecli-interactive
46+
# Verify the EnableImageIntegrityPreview feature flag registration status
47+
az feature show --namespace "Microsoft.ContainerService" --name "EnableImageIntegrityPreview"
48+
49+
# Verify the AKS-AzurePolicyExternalData feature flag registration status
50+
az feature show --namespace "Microsoft.ContainerService" --name "AKS-AzurePolicyExternalData"
51+
```
52+
53+
3. Once the status shows *Registered*, refresh the registration of the `Microsoft.ContainerService` resource provider using the [`az provider register`][az-provider-register] command.
54+
55+
```azurecli-interactive
56+
az provider register --namespace Microsoft.ContainerService
57+
```
58+
59+
## Considerations and limitations
60+
61+
* Your AKS clusters must run Kubernetes version 1.26 or above.
62+
* You shouldn't use this feature for production Azure Container Registry (ACR) registries or workloads.
63+
* Image Integrity supports a maximum of 200 unique signatures concurrently cluster-wide.
64+
* Notation is the only supported verifier.
65+
* Audit is the only supported verification policy effect.
66+
67+
## How Image Integrity works
68+
69+
:::image type="content" source="./media/image-integrity/aks-image-integrity-architecture.png" alt-text="Screenshot showing the basic architecture for Image Integrity." lightbox="./media/image-integrity/aks-image-integrity-architecture.png":::
70+
71+
Image Integrity uses Ratify, Azure Policy, and Gatekeeper to validate signed images before deploying them to your AKS clusters. Enabling Image Integrity on your cluster deploys a `Ratify` pod. This `Ratify` pod performs the following tasks:
72+
73+
1. Reconciles certificates from Azure Key Vault per the configuration you set up through `Ratify` CRDs.
74+
2. Accesses images stored in ACR when validation requests come from [Azure Policy](../governance/policy/concepts/policy-for-kubernetes.md). To enable this experience, Azure Policy extends Gatekeeper, an admission controller webhook for [Open Policy Agent (OPA)](https://www.openpolicyagent.org/).
75+
3. Determines whether the target image is signed with a trusted cert and therefore considered as *trusted*.
76+
4. `AzurePolicy` and `Gatekeeper` consume the validation results as the compliance state to decide whether to allow the deployment request.
77+
78+
## Enable Image Integrity on your AKS cluster
79+
80+
> [!NOTE]
81+
> Image signature verification is a governance-oriented scenario and leverages [Azure Policy](../governance/policy/concepts/policy-for-kubernetes.md) to verify image signatures on AKS clusters at-scale. We recommend using AKS's Image Integrity built-in Azure Policy initiative, which is available in [Azure Policy's built-in definition library](../governance/policy/samples/built-in-policies.md#kubernetes).
82+
83+
### [Azure CLI](#tab/azure-cli)
84+
85+
* Create a policy assignment with the AKS policy initiative *`[Preview]: Use Image Integrity to ensure only trusted images are deployed`* using the [`az policy assignment create`][az-policy-assignment-create] command.
86+
87+
```azurecli-interactive
88+
export SCOPE="/subscriptions/${SUBSCRIPTION}/resourceGroups/${RESOURCE_GROUP}"
89+
export LOCATION=$(az group show -n ${RESOURCE_GROUP} --query location -o tsv)
90+
91+
az policy assignment create --name 'deploy-trustedimages' --policy-set-definition 'af28bf8b-c669-4dd3-9137-1e68fdc61bd6' --display-name 'Audit deployment with unsigned container images' --scope ${SCOPE} --mi-system-assigned --role Contributor --identity-scope ${SCOPE} --location ${LOCATION}
92+
```
93+
94+
The `Ratify` pod deploys after you enable the feature.
95+
96+
> [!NOTE]
97+
> The policy deploys the Image Integrity feature on your cluster when it detects any update operation on the cluster. If you want to enable the feature immediately, you need to create a policy remediation using the [`az policy remediation create`][az-policy-remediation-create] command.
98+
>
99+
> ```azurecli-interactive
100+
> assignment_id=$(az policy assignment show -n 'deploy-trustedimages' --scope ${SCOPE} --query id -o tsv)
101+
> az policy remediation create -a "$assignment_id" --definition-reference-id deployAKSImageIntegrity -n remediation -g ${RESOURCE_GROUP}
102+
> ```
103+
104+
### [Azure portal](#tab/azure-portal)
105+
106+
1. In the Azure portal, navigate to the Azure Policy service named **Policy**.
107+
2. Select **Definitions**.
108+
3. Under **Categories**, select **Kubernetes**.
109+
4. Choose the policy you want to apply. In this case, select **[Preview]: Use Image Integrity to ensure only trusted images are deployed** > **Assign**.
110+
5. Set the **Scope** to the resource group where your AKS cluster is located.
111+
6. Select **Review + create** > **Create** to submit the policy assignment.
112+
113+
---
114+
115+
## Set up verification configurations
116+
117+
For Image Integrity to properly verify the target signed image, you need to set up `Ratify` configurations through K8s [CRDs](https://kubernetes.io/docs/concepts/extend-kubernetes/api-extension/custom-resources/#customresourcedefinitions) using `kubectl`.
118+
119+
In this article, we use a self-signed CA cert from the official Ratify documentation to set up verification configurations. For more examples, see [Ratify CRDs](https://ratify.dev/docs/1.0/ratify-configuration).
120+
121+
1. Create a `VerifyConfig` file named `verify-config.yaml` and copy in the following YAML:
122+
123+
```YAML
124+
apiVersion: config.ratify.deislabs.io/v1beta1
125+
kind: CertificateStore
126+
metadata:
127+
name: certstore-inline
128+
spec:
129+
provider: inline
130+
parameters:
131+
value: |
132+
-----BEGIN CERTIFICATE-----
133+
MIIDQzCCAiugAwIBAgI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gxr5qync
149+
cz8gbXrZmNbzC7W5QK5J7fcx6tlffOpt5cm427f9NiK2tira50HU7gC3HJkbiSTp
150+
Xw10iXXMZzSbQ0/Hj2BF4B40WfAkgRg=
151+
-----END CERTIFICATE-----
152+
---
153+
apiVersion: config.ratify.deislabs.io/v1beta1
154+
kind: Store
155+
metadata:
156+
name: store-oras
157+
spec:
158+
name: oras
159+
---
160+
apiVersion: config.ratify.deislabs.io/v1beta1
161+
kind: Verifier
162+
metadata:
163+
name: verifier-notary-inline
164+
spec:
165+
name: notation
166+
artifactTypes: application/vnd.cncf.notary.signature
167+
parameters:
168+
verificationCertStores: # certificates for validating signatures
169+
certs: # name of the trustStore
170+
- certstore-inline # name of the certificate store CRD to include in this trustStore
171+
trustPolicyDoc: # policy language that indicates which identities are trusted to produce artifacts
172+
version: "1.0"
173+
trustPolicies:
174+
- name: default
175+
registryScopes:
176+
- "*"
177+
signatureVerification:
178+
level: strict
179+
trustStores:
180+
- ca:certs
181+
trustedIdentities:
182+
- "*"
183+
```
184+
185+
2. Apply the `VerifyConfig` to your cluster using the `kubectl apply` command.
186+
187+
```azurecli-interactive
188+
kubectl apply -f verify-config.yaml
189+
```
190+
191+
## Deploy sample images to your AKS cluster
192+
193+
* Deploy a signed image using the `kubectl run demo` command.
194+
195+
```azurecli-interactive
196+
kubectl run demo-signed --image=ghcr.io/deislabs/ratify/notary-image:signed
197+
```
198+
199+
The following example output shows that Image Integrity allows the deployment:
200+
201+
```output
202+
ghcr.io/deislabs/ratify/notary-image:signed
203+
pod/demo-signed created
204+
```
205+
206+
If you want to use your own images, see the [guidance for image signing](../container-registry/container-registry-tutorial-sign-build-push.md).
207+
208+
## Disable Image Integrity
209+
210+
* Disable Image Integrity on your cluster using the [`az aks update`][az-aks-update] command with the `--disable-image-integrity` flag.
211+
212+
```azurecli-interactive
213+
az aks update -g myResourceGroup -n MyManagedCluster --disable-image-integrity
214+
```
215+
216+
### Remove policy initiative
217+
218+
* Remove the policy initiative using the [`az policy assignment delete`][az-policy-assignment-delete] command.
219+
220+
```azurecli-interactive
221+
az policy assignment delete --name 'deploy-trustedimages'
222+
```
223+
224+
## Next steps
225+
226+
In this article, you learned how to use Image Integrity to validate signed images before deploying them to your Azure Kubernetes Service (AKS) clusters. If you want to learn how to sign your own containers, see [Build, sign, and verify container images using Notary and Azure Key Vault (Preview)](../container-registry/container-registry-tutorial-sign-build-push.md).
227+
228+
<!--- Internal links ---->
229+
[az-feature-register]: /cli/azure/feature#az_feature_register
230+
[az-feature-show]: /cli/azure/feature#az_feature_show
231+
[az-provider-register]: /cli/azure/provider#az_provider_register
232+
[az-policy-assignment-create]: /cli/azure/policy/assignment#az_policy_assignment_create
233+
[az-aks-update]: /cli/azure/aks#az_aks_update
234+
[azure-cli-install]: /cli/azure/install-azure-cli
235+
[azure-powershell-install]: /powershell/azure/install-az-ps
236+
[az-policy-assignment-delete]: /cli/azure/policy/assignment#az_policy_assignment_delete
237+
[az-policy-remediation-create]: /cli/azure/policy/remediation#az_policy_remediation_create
238+
239+
<!--- External links ---->
240+
[ratify]: https://github.com/deislabs/ratify
241+
[image-integrity-policy]: https://portal.azure.com/#blade/Microsoft_Azure_Policy/PolicyDetailBlade/definitionId/%2Fproviders%2FMicrosoft.Authorization%2FpolicyDefinitions%2Fcf426bb8-b320-4321-8545-1b784a5df3a4
106 KB
Loading

0 commit comments

Comments
 (0)