Skip to content

Commit f7d026e

Browse files
authored
Merge pull request #36459 from Michelle951/michelle05
[zh] sync security-context.md
2 parents 749cab3 + 9c0431c commit f7d026e

File tree

1 file changed

+89
-12
lines changed

1 file changed

+89
-12
lines changed

content/zh-cn/docs/tasks/configure-pod-container/security-context.md

Lines changed: 89 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ The output shows that the processes are running as user 1000, which is the value
154154
-->
155155
输出显示进程以用户 1000 运行,即 `runAsUser` 所设置的值:
156156

157-
```shell
157+
```none
158158
PID USER TIME COMMAND
159159
1 1000 0:00 sleep 1h
160160
6 1000 0:00 sh
@@ -177,7 +177,7 @@ the value of `fsGroup`.
177177
-->
178178
输出显示 `/data/demo` 目录的组 ID 为 2000,即 `fsGroup` 的设置值:
179179

180-
```shell
180+
```none
181181
drwxrwsrwx 2 root 2000 4096 Jun 6 20:08 demo
182182
```
183183

@@ -205,7 +205,7 @@ The output shows that `testfile` has group ID 2000, which is the value of `fsGro
205205
-->
206206
输出显示 `testfile` 的组 ID 为 2000,也就是 `fsGroup` 所设置的值:
207207

208-
```shell
208+
```none
209209
-rw-r--r-- 1 1000 2000 6 Jun 6 20:08 testfile
210210
```
211211

@@ -498,7 +498,7 @@ The output shows the process IDs (PIDs) for the Container:
498498
-->
499499
输出显示容器中进程 ID(PIDs):
500500

501-
```shell
501+
```
502502
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
503503
root 1 0.0 0.0 4336 796 ? Ss 18:17 0:00 /bin/sh -c node server.js
504504
root 5 0.1 0.5 772124 22700 ? Sl 18:17 0:00 node server.js
@@ -582,7 +582,7 @@ The output shows capabilities bitmap for the process:
582582
-->
583583
输出显示的是进程的权能位图:
584584

585-
```shell
585+
```
586586
...
587587
CapPrm: 00000000aa0435fb
588588
CapEff: 00000000aa0435fb
@@ -612,12 +612,12 @@ for definitions of the capability constants.
612612

613613
<!--
614614
Linux capability constants have the form `CAP_XXX`.
615-
But when you list capabilities in your Container manifest, you must
615+
But when you list capabilities in your container manifest, you must
616616
omit the `CAP_` portion of the constant.
617617
For example, to add `CAP_SYS_TIME`, include `SYS_TIME` in your list of capabilities.
618618
-->
619619
{{< note >}}
620-
Linux 权能常数定义的形式为 `CAP_XXX`。但是你在 Container 清单中列举权能时,
620+
Linux 权能常数定义的形式为 `CAP_XXX`。但是你在 container 清单中列举权能时,
621621
要将权能名称中的 `CAP_` 部分去掉。例如,要添加 `CAP_SYS_TIME`
622622
可在权能列表中添加 `SYS_TIME`
623623
{{< /note >}}
@@ -633,7 +633,7 @@ in the `securityContext` section of your Pod or Container manifest. The
633633
Valid options for `type` include `RuntimeDefault`, `Unconfined`, and
634634
`Localhost`. `localhostProfile` must only be set if `type: Localhost`. It
635635
indicates the path of the pre-configured profile on the node, relative to the
636-
kubelet's configured Seccomp profile location (configured with the `-root-dir`
636+
kubelet's configured Seccomp profile location (configured with the `--root-dir`
637637
flag).
638638
639639
Here is an example that sets the Seccomp profile to the node's container runtime
@@ -706,6 +706,83 @@ To assign SELinux labels, the SELinux security module must be loaded on the host
706706
要指定 SELinux,需要在宿主操作系统中装载 SELinux 安全性模块。
707707
{{< /note >}}
708708

709+
<!--
710+
### Efficient SELinux volume relabeling
711+
-->
712+
### 高效重打 SELinux 卷标签
713+
714+
{{< feature-state for_k8s_version="v1.25" state="alpha" >}}
715+
716+
<!--
717+
By default, the contrainer runtime recursively assigns SELinux label to all
718+
files on all Pod volumes. To speed up this process, Kubernetes can change the
719+
SELinux label of a volume instantly by using a mount option
720+
`-o context=<label>`.
721+
-->
722+
默认情况下,容器运行时递归地将 SELinux 标签赋予所有 Pod 卷上的所有文件。
723+
为了加快该过程,Kubernetes 使用挂载可选项 `-o context=<label>` 可以立即改变卷的 SELinux 标签。
724+
725+
<!--
726+
To benefit from this speedup, all these conditions must be met:
727+
-->
728+
要使用这项加速功能,必须满足下列条件:
729+
730+
<!--
731+
* Alpha feature gates `ReadWriteOncePod` and `SELinuxMountReadWriteOncePod` must
732+
be enabled.
733+
-->
734+
* 必须启用 Alpha 特性门控 `ReadWriteOncePod` 和 `SELinuxMountReadWriteOncePod`。
735+
736+
<!--
737+
* Pod must use PersistentVolumeClaim with `accessModes: ["ReadWriteOncePod"]`.
738+
-->
739+
* Pod 必须以 `accessModes: ["ReadWriteOncePod"]` 模式使用 PersistentVolumeClaim。
740+
741+
<!--
742+
* Pod (or all its Containers that use the PersistentVolumeClaim) must
743+
have `seLinuxOptions` set.
744+
-->
745+
* Pod(或其中使用 PersistentVolumeClaim 的所有容器)必须设置 `seLinuxOptions`。
746+
747+
<!--
748+
* The corresponding PersistentVolume must be either a volume that uses a
749+
{{< glossary_tooltip text="CSI" term_id="csi" >}} driver, or a volume that uses the
750+
legacy `iscsi` volume type.
751+
* If you use a volume backed by a CSI driver, that CSI driver must announce that it
752+
supports mounting with `-o context` by setting `spec.seLinuxMount: true` in
753+
its CSIDriver instance.
754+
-->
755+
* 对应的 PersistentVolume 必须是使用 {< glossary_tooltip text="CSI" term_id="csi" >}}
756+
驱动程序的卷,或者是传统的 `iscsi` 卷类型的卷。
757+
* 如果使用基于 CSI 驱动程序的卷,CSI 驱动程序必须能够通过在 CSIDriver
758+
实例中设置 `spec.seLinuxMount: true` 以支持 `-o context` 挂载。
759+
760+
<!--
761+
For any other volume types, SELinux relabelling happens another way: the container
762+
runtime recursively changes the SELinux label for all inodes (files and directories)
763+
in the volume.
764+
The more files and directories in the volume, the longer that relabelling takes.
765+
-->
766+
对于所有其他卷类型,重打 SELinux 标签的方式有所不同:
767+
容器运行时为卷中的所有节点(文件和目录)递归地修改 SELinux 标签。
768+
卷中的文件和目录越多,重打标签需要耗费的时间就越长。
769+
770+
{{< note >}}
771+
<!--
772+
In Kubernetes 1.25, the kubelet loses track of volume labels after restart. In
773+
other words, then kubelet may refuse to start Pods with errors similar to "conflicting
774+
SELinux labels of volume", while there are no conflicting labels in Pods. Make sure
775+
nodes are
776+
[fully drained](https://kubernetes.io/docs/tasks/administer-cluster/safely-drain-node/)
777+
before restarting kubelet.
778+
-->
779+
在 Kubernetes 1.25 中,kubelet 在重启后会丢失对卷标签的追踪记录。
780+
换言之,kubelet 可能会拒绝启动 Pod,原因类似于 “conflicting
781+
SELinux labels of volume”,
782+
但实际上 Pod 中并没有冲突的标签。在重启 kubelet
783+
之前确保节点已被[完全腾空](/zh-cn/docs/tasks/administer-cluster/safely-drain-node/)。
784+
{{< /note >}}
785+
709786
<!--
710787
## Discussion
711788

@@ -773,19 +850,19 @@ kubectl delete pod security-context-demo-4
773850
* [Tuning Docker with the newest security enhancements](https://github.com/containerd/containerd/blob/main/docs/cri/config.md)
774851
* [Security Contexts design document](https://git.k8s.io/design-proposals-archive/auth/security_context.md)
775852
* [Ownership Management design document](https://git.k8s.io/design-proposals-archive/storage/volume-ownership-management.md)
776-
* [Pod Security Policies](/docs/concepts/security/pod-security-policy/)
853+
* [PodSecurity Admission](/docs/concepts/security/pod-security-admission/)
777854
* [AllowPrivilegeEscalation design
778855
document](https://git.k8s.io/design-proposals-archive/auth/no-new-privs.md)
779856
* For more information about security mechanisms in Linux, see
780-
[Overview of Linux Kernel Security Features](https://www.linux.com/learn/overview-linux-kernel-security-features)
857+
[Overview of Linux Kernel Security Features](https://www.linux.com/learn/overview-linux-kernel-security-features) (Note: Some information is out of date)
781858
-->
782859
* [PodSecurityContext](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#podsecuritycontext-v1-core) API 定义
783860
* [SecurityContext](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#securitycontext-v1-core) API 定义
784861
* [使用最新的安全性增强来调优 Docker(英文)](https://github.com/containerd/containerd/blob/main/docs/cri/config.md)
785862
* [安全上下文的设计文档(英文)](https://github.com/kubernetes/design-proposals-archive/blob/main/auth/security_context.md)
786863
* [属主管理的设计文档(英文)](https://github.com/kubernetes/design-proposals-archive/blob/main/storage/volume-ownership-management.md)
787-
* [Pod 安全策略](/zh-cn/docs/concepts/security/pod-security-policy/)
864+
* [Pod 安全性准入](zh-cn/docs/concepts/security/pod-security-admission/)
788865
* [AllowPrivilegeEscalation 的设计文档(英文)](https://github.com/kubernetes/design-proposals-archive/blob/main/auth/no-new-privs.md)
789866
* 关于在 Linux 系统中的安全机制的更多信息,可参阅
790-
[Linux 内核安全性能力概述](https://www.linux.com/learn/overview-linux-kernel-security-features)。
867+
[Linux 内核安全性能力概述](https://www.linux.com/learn/overview-linux-kernel-security-features)(注意:部分信息已过时)
791868

0 commit comments

Comments
 (0)