You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/aks/use-psa.md
+78-64Lines changed: 78 additions & 64 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,16 +1,16 @@
1
1
---
2
2
title: Use Pod Security Admission in Azure Kubernetes Service (AKS)
3
3
description: Learn how to enable and use Pod Security Admission with Azure Kubernetes Service (AKS).
4
+
ms.custom: azure-kubernetes-service
4
5
ms.topic: article
5
-
ms.date: 08/08/2022
6
-
6
+
ms.date: 09/12/2023
7
7
---
8
8
9
9
# Use Pod Security Admission in Azure Kubernetes Service (AKS)
10
10
11
-
Pod Security Admission enforces Pod Security Standards policies on pods running in a namespace. Pod Security Admission is enabled by default in AKS and is controlled by adding labels to a namespace. For more information about Pod Security Admission, see [Enforce Pod Security Standards with Namespace Labels][kubernetes-psa]. For more information about the Pod Security Standards used by Pod Security Admission, see[Pod Security Standards][kubernetes-pss].
11
+
Pod Security Admission (PSA) uses labels to enforce Pod Security Standards policies on pods running in a namespace. AKS enables Pod Security Admission is enabled by default. For more information about Pod Security Admission and Pod Security Standards, see [Enforce Pod Security Standards with namespace labels][kubernetes-psa] and[Pod Security Standards][kubernetes-pss].
12
12
13
-
Pod Security Admission is a built-in policy solution for single cluster implementations. If you are looking for enterprise-grade policy, then [Azure policy](use-azure-policy.md) is a better choice.
13
+
Pod Security Admission is a built-in policy solution for single cluster implementations. If you want to use an enterprise-grade policy, we recommend you use [Azure policy](use-azure-policy.md).
14
14
15
15
## Before you begin
16
16
@@ -20,90 +20,104 @@ Pod Security Admission is a built-in policy solution for single cluster implemen
20
20
21
21
## Enable Pod Security Admission for a namespace in your cluster
22
22
23
-
To enable PSA for a namespace in your cluster, set the `pod-security.kubernetes.io/enforce` label with the policy value you want to enforce. For example:
23
+
### Enable PSA for a single namespace
24
+
25
+
- Enable PSA for a single namespace in your cluster using the `kubectl label` command and set the `pod-security.kubernetes.io/enforce` label with the policy value you want to enforce. The following example enables the `restricted` policy for the *NAMESPACE* namespace.
- Enable PSA for all namespaces in your cluster using the `kubectl label` command and set the `pod-security.kubernetes.io/warn` label with the policy value you want to enforce. The following example enables the `baseline` policy for all namespaces in your cluster. This policy generates a user-facing warning if any pods are deployed to a namespace that doesn't meet the *baseline* policy.
## Example of enforcing a Pod Security Admission policy with a deployment
55
+
This configures the `test-restricted` and `test-privileged` namespaces to block running pods and generate a user-facing warning if any pods that don't meet the configured policy attempt to run.
40
56
41
-
Create two namespaces, one with the `restricted`policy and one with the `baseline` policy.
57
+
1. Attempt to deploy pods to the `test-restricted` namespace using the `kubectl apply` command. This command results in an error because the `test-restricted` namespace is configured to block pods that don't meet the `restricted` policy.
Both the `test-restricted` and `test-privileged` namespaces will block running pods as well as generate a user-facing warning if any pods attempt to run that do not meet the configured policy.
63
+
The following example output shows a warning stating the pods violate the configured policy:
51
64
52
-
Attempt to deploy pods to the `test-restricted` namespace.
65
+
```output
66
+
...
67
+
Warning: would violate PodSecurity "restricted:latest": allowPrivilegeEscalation != false (container "azure-vote-back" must set securityContext.allowPrivilegeEscalation=false), unrestricted capabilities (container "azure-vote-back" must set securityContext.capabilities.drop=["ALL"]), runAsNonRoot != true (pod or container "azure-vote-back" must set securityContext.runAsNonRoot=true), seccompProfile (pod or container "azure-vote-back" must set securityContext.seccompProfile.type to "RuntimeDefault" or "Localhost")
68
+
deployment.apps/azure-vote-back created
69
+
service/azure-vote-back created
70
+
Warning: would violate PodSecurity "restricted:latest": allowPrivilegeEscalation != false (container "azure-vote-front" must set securityContext.allowPrivilegeEscalation=false), unrestricted capabilities (container "azure-vote-front" must set securityContext.capabilities.drop=["ALL"]), runAsNonRoot != true (pod or container "azure-vote-front" must set securityContext.runAsNonRoot=true), seccompProfile (pod or container "azure-vote-front" must set securityContext.seccompProfile.type to "RuntimeDefault" or "Localhost")
1. Confirm there are no pods running in the `test-restricted` namespace using the `kubectl get pods` command.
57
76
58
-
Notice you get a warning that the pods violate the configured policy.
77
+
```azurecli-interactive
78
+
kubectl get pods --namespace test-restricted
79
+
```
59
80
60
-
```output
61
-
...
62
-
Warning: would violate PodSecurity "restricted:latest": allowPrivilegeEscalation != false (container "azure-vote-back" must set securityContext.allowPrivilegeEscalation=false), unrestricted capabilities (container "azure-vote-back" must set securityContext.capabilities.drop=["ALL"]), runAsNonRoot != true (pod or container "azure-vote-back" must set securityContext.runAsNonRoot=true), seccompProfile (pod or container "azure-vote-back" must set securityContext.seccompProfile.type to "RuntimeDefault" or "Localhost")
63
-
deployment.apps/azure-vote-back created
64
-
service/azure-vote-back created
65
-
Warning: would violate PodSecurity "restricted:latest": allowPrivilegeEscalation != false (container "azure-vote-front" must set securityContext.allowPrivilegeEscalation=false), unrestricted capabilities (container "azure-vote-front" must set securityContext.capabilities.drop=["ALL"]), runAsNonRoot != true (pod or container "azure-vote-front" must set securityContext.runAsNonRoot=true), seccompProfile (pod or container "azure-vote-front" must set securityContext.seccompProfile.type to "RuntimeDefault" or "Localhost")
66
-
deployment.apps/azure-vote-front created
67
-
service/azure-vote-front created
68
-
```
81
+
The following example output shows no pods running in the `test-restricted` namespace:
69
82
70
-
Confirm there are no pods running in the `test-restricted` namespace.
83
+
```output
84
+
No resources found in test-restricted namespace.
85
+
```
71
86
72
-
```azurecli-interactive
73
-
kubectl get pods --namespace test-restricted
74
-
```
87
+
1. Attempt to deploy pods to the `test-privileged` namespace using the `kubectl apply` command. This time, the pods should deploy successfully because the `test-privileged` namespace is configured to allow pods that violate the `privileged` policy.
0 commit comments