11---
2- title : 为 Pod 配置用户名字空间
2+ title : 为 Pod 配置 user 名字空间
33reviewers :
44content_type : task
55weight : 210
@@ -15,14 +15,14 @@ min-kubernetes-server-version: v1.25
1515-->
1616
1717<!-- overview -->
18- {{< feature-state for_k8s_version="v1.25" state="alpha " >}}
18+ {{< feature-state for_k8s_version="v1.25" state="beta " >}}
1919
2020<!--
2121This page shows how to configure a user namespace for stateless pods. This
2222allows to isolate the user running inside the container from the one in the
2323host.
2424-->
25- 本页展示如何为无状态 Pod 配置用户名字空间 。可以将容器内的用户与主机上的用户隔离开来。
25+ 本页展示如何为无状态 Pod 配置 user 名字空间 。可以将容器内的用户与主机上的用户隔离开来。
2626
2727<!--
2828A process running as root in a container can run as a different (non-root) user
@@ -31,7 +31,7 @@ inside the user namespace, but is unprivileged for operations outside the
3131namespace.
3232-->
3333在容器中以 root 用户运行的进程可以以不同的(非 root)用户在宿主机上运行;换句话说,
34- 进程在用户名字空间内部拥有执行操作的全部特权,但在用户名字空间外部并没有执行操作的特权 。
34+ 进程在 user 名字空间内部拥有执行操作的全部特权,但在 user 名字空间外部并没有执行操作的特权 。
3535
3636<!--
3737You can use this feature to reduce the damage a compromised container can do to
@@ -41,18 +41,18 @@ exploitable when user namespaces is active. It is expected user namespace will
4141mitigate some future vulnerabilities too.
4242-->
4343你可以使用这个特性来减少有害的容器对同一宿主机上其他容器的影响。
44- [ 有些安全脆弱性问题] [ KEP-vulns ] 被评为 ** HIGH** or ** CRITICAL** ,但当用户名字空间被启用时 ,
45- 它们是无法被利用的。相信用户名字空间也能减轻一些未来的漏洞的影响 。
44+ [ 有些安全脆弱性问题] [ KEP-vulns ] 被评为 ** HIGH** 或 ** CRITICAL** ,但当 user 名字空间被启用时 ,
45+ 它们是无法被利用的。相信 user 名字空间也能减轻一些未来的漏洞影响 。
4646
4747<!--
4848Without using a user namespace a container running as root, in the case of a
4949container breakout, has root privileges on the node. And if some capability were
5050granted to the container, the capabilities are valid on the host too. None of
5151this is true when user namespaces are used.
5252-->
53- 在不使用用户名字空间的情况下 ,对于以 root 用户运行的容器而言,发生容器逃逸时,
53+ 在不使用 user 名字空间的情况下 ,对于以 root 用户运行的容器而言,发生容器逃逸时,
5454容器将拥有在宿主机上的 root 特权。如果容器被赋予了某些权限,则这些权限在宿主机上同样有效。
55- 当使用用户名字空间时这些都不可能发生 。
55+ 当使用 user 名字空间时这些都不可能发生 。
5656
5757[ KEP-vulns ] : https://github.com/kubernetes/enhancements/tree/217d790720c5aef09b8bd4d6ca96284a0affe6c2/keps/sig-node/127-user-namespaces#motivation
5858
@@ -70,18 +70,18 @@ this is true when user namespaces are used.
7070* You need to enable the `UserNamespacesSupport`
7171 [feature gate](/docs/reference/command-line-tools-reference/feature-gates/)
7272-->
73- * 节点上的操作系统必须为 Linux
73+ * 节点的操作系统必须为 Linux
7474* 你需要在宿主机上执行命令
7575* 你需要能够通过 exec 操作进入 Pod
76- * 你需要启用 ` UserNamespacesSupport ` [ 特性门控] ( /zh-cn/docs/reference/command-line-tools-reference/feature-gates/ ) 。
76+ * 你需要启用 ` UserNamespacesSupport ` [ 特性门控] ( /zh-cn/docs/reference/command-line-tools-reference/feature-gates/ )
7777
7878{{< note >}}
7979<!--
8080The feature gate to enable user namespaces was previously named
8181`UserNamespacesStatelessPodsSupport`, when only stateless pods were supported.
8282Only Kubernetes v1.25 through to v1.27 recognise `UserNamespacesStatelessPodsSupport`.
8383-->
84- 在用户名字空间原来仅支持无状态的 Pod 时,启用用户名字空间的特性门控先前被命名为 ` UserNamespacesStatelessPodsSupport ` 。
84+ 在 user 名字空间原来仅支持无状态的 Pod 时,启用 user 名字空间的特性门控先前被命名为 ` UserNamespacesStatelessPodsSupport ` 。
8585只有 Kubernetes v1.25 到 v1.27 才能识别 ` UserNamespacesStatelessPodsSupport ` 。
8686{{</ note >}}
8787
@@ -92,39 +92,29 @@ for using user namespaces with Pods.
9292-->
9393你所使用的集群** 必须** 包括至少一个符合
9494[ 要求] ( /zh-cn/docs/concepts/workloads/pods/user-namespaces/#before-you-begin )
95- 的节点,以便为 Pod 配置用户名字空间 。
95+ 的节点,以便为 Pod 配置 user 名字空间 。
9696
9797<!--
9898If you have a mixture of nodes and only some of the nodes provide user namespace support for
9999Pods, you also need to ensure that the user namespace Pods are
100100[scheduled](/docs/concepts/scheduling-eviction/assign-pod-node/) to suitable nodes.
101101-->
102- 如果你有混合节点,并且只有部分节点支持为 Pod 配置用户名字空间 ,
103- 你还需要确保配置了用户名字空间的 Pod
102+ 如果你有混合节点,并且只有部分节点支持为 Pod 配置 user 名字空间 ,
103+ 你还需要确保配置了 user 名字空间的 Pod
104104被[ 调度] ( /zh-cn/docs/concepts/scheduling-eviction/assign-pod-node/ ) 到合适的节点。
105105
106- * CRI-O: v1.25 支持用户名字空间。
107-
108- <!--
109- Please note that **if your container runtime doesn't support user namespaces, the
110- `hostUsers` field in the pod spec will be silently ignored and the pod will be
111- created without user namespaces.**
112- -->
113- 请注意 ** 如果你的容器运行时环境不支持用户名字空间,那么 Pod 规约中的 ` hostUsers ` 字段将被静默忽略,
114- 并且系统会在没有用户名字空间的环境中创建 Pod。**
115-
116106<!-- steps -->
117107
118108<!--
119109## Run a Pod that uses a user namespace {#create-pod}
120110-->
121- ## 运行一个使用用户名字空间的 Pod {#create-pod}
111+ ## 运行一个使用 user 名字空间的 Pod {#create-pod}
122112
123113<!--
124114A user namespace for a pod is enabled setting the `hostUsers` field of `.spec`
125115to `false`. For example:
126116-->
127- 为一个 Pod 启用用户名字空间需要设置 ` .spec ` 的 ` hostUsers ` 字段为 ` false ` . 例如:
117+ 为一个 Pod 启用 user 名字空间需要设置 ` .spec ` 的 ` hostUsers ` 字段为 ` false ` 。例如:
128118
129119{{% code_sample file="pods/user-namespaces-stateless.yaml" %}}
130120
@@ -147,15 +137,39 @@ to `false`. For example:
147137 ```
148138
149139<!--
150- And run the command. The output is similar to this :
140+ Run this command:
151141-->
152- 执行命令的输出类似于 :
142+ 运行这个命令 :
153143
154- ``` none
144+ ``` shell
155145readlink /proc/self/ns/user
146+ ```
147+
148+ <!--
149+ The output is similar to:
150+ -->
151+ 输出类似于:
152+
153+ ``` shell
156154user:[4026531837]
155+ ```
156+
157+ <!--
158+ Also run:
159+ -->
160+ 还运行:
161+
162+ ``` shell
157163cat /proc/self/uid_map
158- 0 0 4294967295
164+ ```
165+
166+ <!--
167+ The output is similar to:
168+ -->
169+ 输出类似于:
170+
171+ ``` shell
172+ 0 833617920 65536
159173```
160174
161175<!--
@@ -164,30 +178,29 @@ Then, open a shell in the host and run the same command.
164178然后,在主机中打开一个 Shell 并运行相同的命令。
165179
166180<!--
167- The output must be different. This means the host and the pod are using a
168- different user namespace. When user namespaces are not enabled, the host and the
169- pod use the same user namespace.
181+ The `readlink` command shows the user namespace the process is running in. It
182+ should be different when it is run on the host and inside the container.
170183-->
171- 输出一定是不同的。这意味着主机和 Pod 使用不同的用户名字空间。当未启用用户名字空间时,
172- 宿主机和 Pod 使用相同的用户名字空间。
184+ ` readlink ` 命令显示进程运行所在的用户命名空间。在主机上和容器内运行时应该有所不同。
185+
186+ <!--
187+ The last number of the `uid_map` file inside the container must be 65536, on the
188+ host it must be a bigger number.
189+ -->
190+ 容器内 ` uid_map ` 文件的最后一个数字必须是 65536,在主机上它必须是更大的数字。
173191
174192<!--
175193If you are running the kubelet inside a user namespace, you need to compare the
176194output from running the command in the pod to the output of running in the host:
177195-->
178- 如果你在用户名字空间中运行 kubelet,则需要将在 Pod 中运行命令的输出与在主机中运行的输出进行比较:
196+ 如果你在 user 名字空间中运行 kubelet,则需要将在 Pod 中运行命令的输出与在主机中运行的输出进行比较:
179197
180- <!--
181- ```none
198+ ``` shell
182199readlink /proc/$pid /ns/user
183- user:[4026534732]
184200```
185201
202+ <!--
186203replacing `$pid` with the kubelet PID.
187204-->
188- ``` none
189- readlink /proc/$pid/ns/user
190- user:[4026534732]
191- ```
192205
193- 使用 kubelet 的进程号代替 ` $pid `
206+ 使用 kubelet 的进程号代替 ` $pid ` 。
0 commit comments