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: docs/en/developer/building_application/namespace/security_policies.mdx
+71-5Lines changed: 71 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,13 +2,17 @@
2
2
weight: 50
3
3
---
4
4
5
-
# Pod Security Admission
5
+
# Pod Security Policies
6
+
7
+
ACP supports Kubernetes Pod Security Admission (PSA) and Kyverno Policy to help enforce security standards for Pods running in your clusters.
8
+
9
+
## Pod Security Admission
6
10
7
11
Refer to the official Kubernetes documentation: [Pod Security Admission](https://kubernetes.io/docs/concepts/security/pod-security-admission/)
8
12
9
13
Pod Security Admission (PSA) is a Kubernetes admission controller that enforces security policies at the namespace level by validating Pod specifications against predefined standards.
10
14
11
-
## Security Modes
15
+
###Security Modes
12
16
13
17
PSA defines three modes to control how policy violations are handled:
14
18
@@ -23,7 +27,7 @@ PSA defines three modes to control how policy violations are handled:
23
27
-**Enforce** acts on Pods only (e.g., rejects Pods but allows non-Pod resources like Deployments).
24
28
-**Audit** and **Warn** apply to both Pods and their controllers (e.g., Deployments).
25
29
26
-
## Security Standards
30
+
###Security Standards
27
31
28
32
PSA defines three security standards to restrict Pod privileges:
29
33
@@ -33,9 +37,9 @@ PSA defines three security standards to restrict Pod privileges:
33
37
|**Baseline**| Minimal restrictions to prevent known privilege escalations. | Blocks `hostNetwork`, `hostPID`, privileged containers, and unrestricted `hostPath` volumes. |
34
38
|**Restricted**| Strictest policy enforcing security best practices. | Requires: <br/>- `runAsNonRoot: true` <br/>- `seccompProfile.type: RuntimeDefault` <br/>- Dropped Linux capabilities. |
35
39
36
-
## Configuration
40
+
###Configuration
37
41
38
-
### Namespace Labels
42
+
####Namespace Labels
39
43
40
44
Apply labels to namespaces to define PSA policies.
41
45
@@ -79,3 +83,65 @@ exemptions:
79
83
runtimeClasses: ['nvidia']
80
84
namespaces: ['kube-system']
81
85
```
86
+
87
+
## Kyverno Policy
88
+
89
+
ACP provides several samples to create the Kyverno policies for Pod security. The samples includes:
90
+
- **Restricted**: Restricted denies access to all host features and requires pods to be run with a UID, and SELinux context that are allocated to the namespace.
91
+
- **Restricted-v2**: Restricted-v2 denies access to all host features and requires pods to be run with a UID, and SELinux context that are allocated to the namespace. This is the most restrictive policy and it is used by default for authenticated users. On top of the legacy 'restricted', it also requires to drop ALL capabilities and does not allow privilege escalation binaries. It will also default the seccomp profile to runtime/default if unset, otherwise this seccomp profile is required.
92
+
- **Anyuid**: Anyuid provides all features of the restricted policy but allows users to run with any UID and any GID.
93
+
- **Hostaccess**: Hostaccess allows access to all host namespaces but still requires pods to be run with a UID and SELinux context that are allocated to the namespace. WARNING: this policy allows host access to namespaces, file systems, and PIDS. It should only be used by trusted pods. Grant with caution.
94
+
- **Hostmount-anyuid**: Hostmount-anyuid provides all the features of the restricted policy but allows host mounts and any UID by a pod. This is primarily used by the persistent volume recycler. WARNING: this policy allows host file system access as any UID, including UID 0. Grant with caution.
95
+
- **Hostnetwork**: Hostnetwork allows using host networking and host ports but still requires pods to be run with a UID and SELinux context that are allocated to the namespace.
96
+
- **Hostnetwork-v2**: Hostnetwork-v2 allows using host networking and host ports but still requires pods to be run with a UID and SELinux context that are allocated to the namespace. On top of the legacy 'hostnetwork' policy, it also requires to drop ALL capabilities and does not allow privilege escalation binaries. It will also default the seccomp profile to runtime/default if unset, otherwise this seccomp profile is required.
97
+
- **Node-exporter**: Node-exporter policy is used for the Prometheus node exporter.
98
+
- **Nonroot**: Nonroot provides all features of the restricted policy but allows users to run with any non-root UID. The user must specify the UID or it must be specified on the by the manifest of the container runtime.
99
+
- **Nonroot-v2**: Nonroot-v2 provides all features of the restricted policy but allows users to run with any non-root UID. The user must specify the UID or it must be specified on the by the manifest of the container runtime. On top of the legacy 'nonroot' policy, it also requires to drop ALL capabilities and does not allow privilege escalation binaries. It will also default the seccomp profile to runtime/default if unset, otherwise this seccomp profile is required.
100
+
- **Privileged**: Privileged allows access to all privileged and host features and the ability to run as any user, any group, any fsGroup, and with any SELinux context. WARNING: this is the most relaxed and should be used only for cluster administration. Grant with caution.
101
+
102
+
<Directive type="note" title="NOTICE">
103
+
The **Restricted** policy is not equal to the Kubernetes Pod Security Admission 'restricted' standard.
104
+
You may need to change your pod security configuration if you want to use the kyverno **Restricted** policy instead of Kubernetes Pod Security Admission 'restricted' standard.
105
+
</Directive>
106
+
107
+
### Prerequisites
108
+
109
+
- Install Alauda Container Platform Compliance for Kyverno, refer to the [document](../../../security/security_and_compliance/compliance/install.mdx).
110
+
- Enable feature gate `namespace-resource-manage` in ACP featuregate settings.
111
+
112
+
### Apply Kyverno Policies
113
+
114
+
### Web Console
115
+
116
+
1. In the ACP console, navigate to **Container Platform**, choose the namespace where you want to apply the security policy.
117
+
2. Go to **Advanced** > **Resources**.
118
+
3. Search the resource type with name **Policy** for resource **Policy** of group **kyverno.io**.
119
+
4. Select the version "v2beta1", Click **Create** to create a new Kyverno Policy.
120
+
5. In the **Create Resource** dialog, select the **Samples** tab.
121
+
6. Choose the desired Pod security policy sample (e.g., `Restricted`), then click **Try**.
122
+
7. Review and modify the policy YAML as needed, then click **Update** to apply the policy.
123
+
124
+
### CLI
125
+
126
+
1. Log in to the kubernetes cluster where you want to apply the security policy.
127
+
2. Run the following command to create a Kyverno Policy from a sample resource:
128
+
129
+
```shell
130
+
$ kubectl get consoleyamlsamples.console.alauda.io restricted-policy -otemplate --template={{.spec.yaml}}|kubectl apply -f -
0 commit comments