1
1
---
2
2
title : 为 Pod 或容器配置安全上下文
3
3
content_type : task
4
- weight : 80
4
+ weight : 110
5
5
---
6
6
<!--
7
7
reviewers:
@@ -10,7 +10,7 @@ reviewers:
10
10
- thockin
11
11
title: Configure a Security Context for a Pod or Container
12
12
content_type: task
13
- weight: 80
13
+ weight: 110
14
14
-->
15
15
16
16
<!-- overview -->
@@ -21,41 +21,52 @@ a Pod or Container. Security context settings include, but are not limited to:
21
21
22
22
* Discretionary Access Control: Permission to access an object, like a file, is based on
23
23
[user ID (UID) and group ID (GID)](https://wiki.archlinux.org/index.php/users_and_groups).
24
+
24
25
* [Security Enhanced Linux (SELinux)](https://en.wikipedia.org/wiki/Security-Enhanced_Linux):
25
26
Objects are assigned security labels.
27
+
26
28
* Running as privileged or unprivileged.
27
- * [Linux Capabilities](https://linux-audit.com/linux-capabilities-hardening-linux-binaries-by-removing-setuid/):
29
+
30
+ * [Linux Capabilities](https://linux-audit.com/linux-capabilities-hardening-linux-binaries-by-removing-setuid/):
28
31
Give a process some privileges, but not all the privileges of the root user.
32
+
29
33
-->
30
34
安全上下文(Security Context)定义 Pod 或 Container 的特权与访问控制设置。
31
35
安全上下文包括但不限于:
32
36
33
37
* 自主访问控制(Discretionary Access Control):
34
38
基于[ 用户 ID(UID)和组 ID(GID)] ( https://wiki.archlinux.org/index.php/users_and_groups )
35
39
来判定对对象(例如文件)的访问权限。
40
+
36
41
* [ 安全性增强的 Linux(SELinux)] ( https://zh.wikipedia.org/wiki/%E5%AE%89%E5%85%A8%E5%A2%9E%E5%BC%BA%E5%BC%8FLinux ) :
37
42
为对象赋予安全性标签。
43
+
38
44
* 以特权模式或者非特权模式运行。
45
+
39
46
* [ Linux 权能] ( https://linux-audit.com/linux-capabilities-hardening-linux-binaries-by-removing-setuid/ ) :
40
47
为进程赋予 root 用户的部分特权而非全部特权。
48
+
41
49
<!--
42
50
* [AppArmor](/docs/tutorials/security/apparmor/):
43
51
Use program profiles to restrict the capabilities of individual programs.
52
+
44
53
* [Seccomp](/docs/tutorials/security/seccomp/): Filter a process's system calls.
54
+
45
55
* `allowPrivilegeEscalation`: Controls whether a process can gain more privileges than
46
56
its parent process. This bool directly controls whether the
47
57
[`no_new_privs`](https://www.kernel.org/doc/Documentation/prctl/no_new_privs.txt)
48
58
flag gets set on the container process.
49
- `allowPrivilegeEscalation` is always true
50
- when the container:
59
+ `allowPrivilegeEscalation` is always true when the container:
51
60
52
61
- is run as privileged, or
53
62
- has `CAP_SYS_ADMIN`
54
63
55
- * readOnlyRootFilesystem: Mounts the container's root filesystem as read-only.
64
+ * ` readOnlyRootFilesystem` : Mounts the container's root filesystem as read-only.
56
65
-->
57
66
* [ AppArmor] ( /zh-cn/docs/tutorials/security/apparmor/ ) :使用程序配置来限制个别程序的权能。
67
+
58
68
* [ Seccomp] ( /zh-cn/docs/tutorials/security/seccomp/ ) :过滤进程的系统调用。
69
+
59
70
* ` allowPrivilegeEscalation ` :控制进程是否可以获得超出其父进程的特权。
60
71
此布尔值直接控制是否为容器进程设置
61
72
[ ` no_new_privs ` ] ( https://www.kernel.org/doc/Documentation/prctl/no_new_privs.txt ) 标志。
@@ -64,10 +75,10 @@ a Pod or Container. Security context settings include, but are not limited to:
64
75
- 以特权模式运行,或者
65
76
- 具有 ` CAP_SYS_ADMIN ` 权能
66
77
67
- * readOnlyRootFilesystem:以只读方式加载容器的根文件系统。
78
+ * ` readOnlyRootFilesystem ` :以只读方式加载容器的根文件系统。
68
79
69
80
<!--
70
- The above bullets are not a complete set of security context settings - please see
81
+ The above bullets are not a complete set of security context settings -- please see
71
82
[SecurityContext](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#securitycontext-v1-core)
72
83
for a comprehensive list.
73
84
-->
@@ -702,7 +713,7 @@ To assign SELinux labels, the SELinux security module must be loaded on the host
702
713
{{< feature-state for_k8s_version="v1.25" state="alpha" >}}
703
714
704
715
<!--
705
- By default, the contrainer runtime recursively assigns SELinux label to all
716
+ By default, the container runtime recursively assigns SELinux label to all
706
717
files on all Pod volumes. To speed up this process, Kubernetes can change the
707
718
SELinux label of a volume instantly by using a mount option
708
719
` -o context=<label>` .
@@ -804,15 +815,15 @@ Pod 的安全上下文适用于 Pod 中的容器,也适用于 Pod 所挂载的
804
815
该部分设置的是赋予 Pod 中所有容器及卷的
805
816
[多类别安全性(Multi-Category Security,MCS)](https://selinuxproject.org/page/NB_MLS)标签。
806
817
807
- <!--
808
- After you specify an MCS label for a Pod, all Pods with the same label can
809
- access the Volume. If you need inter-Pod protection, you must assign a unique
810
- MCS label to each Pod.
811
- -->
812
- {{< warning >}}
813
- 在为 Pod 设置 MCS 标签之后,所有带有相同标签的 Pod 可以访问该卷。
814
- 如果你需要跨 Pod 的保护,你必须为每个 Pod 赋予独特的 MCS 标签。
815
- {{< /warning >}}
818
+ <!--
819
+ After you specify an MCS label for a Pod, all Pods with the same label can
820
+ access the Volume. If you need inter-Pod protection, you must assign a unique
821
+ MCS label to each Pod.
822
+ -->
823
+ {{< warning >}}
824
+ 在为 Pod 设置 MCS 标签之后,所有带有相同标签的 Pod 可以访问该卷。
825
+ 如果你需要跨 Pod 的保护,你必须为每个 Pod 赋予独特的 MCS 标签。
826
+ {{< /warning >}}
816
827
817
828
<!--
818
829
# # Clean up
@@ -842,7 +853,8 @@ kubectl delete pod security-context-demo-4
842
853
* [AllowPrivilegeEscalation design
843
854
document](https://git.k8s.io/design-proposals-archive/auth/no-new-privs.md)
844
855
* For more information about security mechanisms in Linux, see
845
- [Overview of Linux Kernel Security Features](https://www.linux.com/learn/overview-linux-kernel-security-features) (Note : Some information is out of date)
856
+ [Overview of Linux Kernel Security Features](https://www.linux.com/learn/overview-linux-kernel-security-features)
857
+ (Note : Some information is out of date)
846
858
-->
847
859
* [PodSecurityContext](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#podsecuritycontext-v1-core) API 定义
848
860
* [SecurityContext](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#securitycontext-v1-core) API 定义
0 commit comments