Skip to content

Commit d33006c

Browse files
committed
[zh-cn] sync user-namespaces.md
Signed-off-by: xin.li <xin.li@daocloud.io>
1 parent e652213 commit d33006c

File tree

1 file changed

+145
-22
lines changed

1 file changed

+145
-22
lines changed

Diff for: content/zh-cn/docs/concepts/workloads/pods/user-namespaces.md

+145-22
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ min-kubernetes-server-version: v1.25
1313
-->
1414

1515
<!-- overview -->
16-
{{< feature-state for_k8s_version="v1.25" state="alpha" >}}
16+
{{< feature-state for_k8s_version="v1.30" state="beta" >}}
1717
<!--
1818
This page explains how user namespaces are used in Kubernetes pods. A user
1919
namespace isolates the user running inside the container from the one
@@ -81,13 +81,49 @@ Linux 6.3 中支持 idmap 挂载的一些比较流行的文件系统是:btrfs
8181
tmpfs、overlayfs。
8282

8383
<!--
84-
In addition, support is needed in the
85-
{{< glossary_tooltip text="container runtime" term_id="container-runtime" >}}
86-
to use this feature with Kubernetes pods:
84+
In addition, the container runtime and its underlying OCI runtime must support
85+
user namespaces. The following OCI runtimes offer support:
8786
88-
* CRI-O: version 1.25 (and later) supports user namespaces for containers.
87+
* [crun](https://github.com/containers/crun) version 1.9 or greater (it's recommend version 1.13+).
8988
-->
9089

90+
此外,容器运行时及其底层 OCI 运行时必须支持用户命名空间。以下 OCI 运行时提供支持:
91+
92+
* [crun](https://github.com/containers/crun) 1.9 或更高版本(推荐 1.13+ 版本)。
93+
94+
<!-- ideally, update this if a newer minor release of runc comes out, whether or not it includes the idmap support -->
95+
96+
{{< note >}}
97+
<!--
98+
Many OCI runtimes do not include the support needed for using user namespaces in
99+
Linux pods. If you use a managed Kubernetes, or have downloaded it from packages
100+
and set it up, it's likely that nodes in your cluster use a runtime that doesn't
101+
include this support. For example, the most widely used OCI runtime is `runc`,
102+
and version `1.1.z` of runc doesn't support all the features needed by the
103+
Kubernetes implementation of user namespaces.
104+
-->
105+
许多 OCI 运行时不包含在 Linux Pod 中使用用户命名空间所需的支持。
106+
如果你使用托管 Kubernetes,或者使用软件包下载并安装 Kubernetes 集群,
107+
则集群中的节点可能使用不包含支持此特性的运行时。
108+
例如,最广泛使用的 OCI 运行时是 `runc`,而 runc 的 `1.1.z`
109+
版本不支持 Kubernetes 实现用户命名空间所需的所有特性。
110+
111+
<!--
112+
If there is a newer release of runc than 1.1 available for use, check its
113+
documentation and release notes for compatibility (look for idmap mounts support
114+
in particular, because that is the missing feature).
115+
-->
116+
如果有比 1.1 更新的 runc 版本可供使用,请检查其文档和发行说明以了解兼容性
117+
(特别寻找 idmap 挂载支持,因为这一特性是缺失的)。
118+
{{< /note >}}
119+
120+
<!--
121+
To use user namespaces with Kubernetes, you also need to use a CRI
122+
{{< glossary_tooltip text="container runtime" term_id="container-runtime" >}}
123+
to use this feature with Kubernetes pods:
124+
125+
* CRI-O: version 1.25 (and later) supports user namespaces for containers.
126+
-->
91127
此外,需要在{{< glossary_tooltip text="容器运行时" term_id="container-runtime" >}}提供支持,
92128
才能在 Kubernetes Pod 中使用这一功能:
93129

@@ -254,30 +290,117 @@ use, see `man 7 user_namespaces`.
254290
## 设置一个节点以支持用户命名空间 {#set-up-a-node-to-support-user-namespaces}
255291

256292
<!--
257-
It is recommended that the host's files and host's processes use UIDs/GIDs in
258-
the range of 0-65535.
293+
By default, the kubelet assigns pods UIDs/GIDs above the range 0-65535, based on
294+
the assumption that the host's files and processes use UIDs/GIDs within this
295+
range, which is standard for most Linux distributions. This approach prevents
296+
any overlap between the UIDs/GIDs of the host and those of the pods.
297+
-->
298+
默认情况下,kubelet 会分配 0-65535 范围以上的 Pod UID/GID,
299+
这是基于主机的文件和进程使用此范围内的 UID/GID 的假设,也是大多数 Linux 发行版的标准。
300+
此方法可防止主机的 UID/GID 与 Pod 的 UID/GID 之间出现重叠。
259301

260-
The kubelet will assign UIDs/GIDs higher than that to pods. Therefore, to
261-
guarantee as much isolation as possible, the UIDs/GIDs used by the host's files
262-
and host's processes should be in the range 0-65535.
302+
<!--
303+
Avoiding the overlap is important to mitigate the impact of vulnerabilities such
304+
as [CVE-2021-25741][CVE-2021-25741], where a pod can potentially read arbitrary
305+
files in the host. If the UIDs/GIDs of the pod and the host don't overlap, it is
306+
limited what a pod would be able to do: the pod UID/GID won't match the host's
307+
file owner/group.
308+
-->
309+
避免重叠对于减轻 [CVE-2021-25741][CVE-2021-25741] 等漏洞的影响非常重要,
310+
其中 Pod 可能会读取主机中的任意文件。
311+
如果 Pod 和主机的 UID/GID 不重叠,则 Pod 的功能将受到限制:
312+
Pod UID/GID 将与主机的文件所有者/组不匹配。
263313

264-
Note that this recommendation is important to mitigate the impact of CVEs like
265-
[CVE-2021-25741][CVE-2021-25741], where a pod can potentially read arbitrary
266-
files in the hosts. If the UIDs/GIDs of the pod and the host don't overlap, it
267-
is limited what a pod would be able to do: the pod UID/GID won't match the
268-
host's file owner/group.
314+
<!--
315+
The kubelet can use a custom range for user IDs and group IDs for pods. To
316+
configure a custom range, the node needs to have:
317+
318+
* A user `kubelet` in the system (you cannot use any other username here)
319+
* The binary `getsubids` installed (part of [shadow-utils][shadow-utils]) and
320+
in the `PATH` for the kubelet binary.
321+
* A configuration of subordinate UIDs/GIDs for the `kubelet` user (see
322+
[`man 5 subuid`](https://man7.org/linux/man-pages/man5/subuid.5.html) and
323+
[`man 5 subgid`](https://man7.org/linux/man-pages/man5/subgid.5.html)).
269324
-->
270-
建议主机的文件和主机的进程使用 0-65535 范围内的 UID/GID。
325+
kubelet 可以对 Pod 的用户 ID 和组 ID 使用自定义范围。要配置自定义范围,节点需要具有:
326+
* 系统中的用户 `kubelet`(此处不能使用任何其他用户名)。
327+
* 已安装二进制文件 `getsubids`[shadow-utils][shadow-utils] 的一部分)并位于 kubelet 二进制文件的 `PATH` 中。
328+
* `kubelet` 用户的从属 UID/GID 配置
329+
(请参阅 [`man 5 subuid`](https://man7.org/linux/man-pages/man5/subuid.5.html)
330+
[`man 5 subgid`](https://man7.org/linux/man-pages/man5/subgid.5.html)
271331

272-
kubelet 会把高于这个范围的 UID/GID 分配给 Pod。
273-
因此,为了保证尽可能多的隔离,主机的文件和主机的进程所使用的 UID/GID 应该在 0-65535 范围内。
332+
<!--
333+
This setting only gathers the UID/GID range configuration and does not change
334+
the user executing the `kubelet`.
335+
336+
You must follow some constraints for the subordinate ID range that you assign
337+
to the `kubelet` user:
338+
-->
339+
此设置仅收集 UID/GID 范围配置,不会更改执行 `kubelet` 的用户。
274340

275-
请注意,这个建议对减轻 [CVE-2021-25741][CVE-2021-25741] 等 CVE 的影响很重要;
276-
在这些 CVE 中,Pod 有可能读取主机中的任意文件。
277-
如果 Pod 和主机的 UID/GID 不重叠,Pod 能够做的事情就会受到限制:
278-
Pod 的 UID/GID 不会与主机的文件所有者/组相匹配。
341+
对于分配给 `kubelet` 用户的从属 ID 范围, 你必须遵循一些限制:
342+
343+
<!--
344+
* The subordinate user ID, that starts the UID range for Pods, **must** be a
345+
multiple of 65536 and must also be greater than or equal to 65536. In other
346+
words, you cannot use any ID from the range 0-65535 for Pods; the kubelet
347+
imposes this restriction to make it difficult to create an accidentally insecure
348+
configuration.
349+
-->
350+
* 启动 Pod 的 UID 范围的从属用户 ID **必须**是 65536 的倍数,并且还必须大于或等于 65536。
351+
换句话说,Pod 不能使用 0-65535 范围内的任何 ID;kubelet 施加此限制是为了使创建意外不安全的配置变得困难。
352+
353+
<!--
354+
* The subordinate ID count must be a multiple of 65536
355+
356+
* The subordinate ID count must be at least `65536 x <maxPods>` where `<maxPods>`
357+
is the maximum number of pods that can run on the node.
358+
359+
* You must assign the same range for both user IDs and for group IDs, It doesn't
360+
matter if other users have user ID ranges that don't align with the group ID
361+
ranges.
362+
-->
363+
* 从属 ID 计数必须是 65536 的倍数
364+
365+
* 从属 ID 计数必须至少为 `65536 x <maxPods>`,其中 `<maxPods>` 是节点上可以运行的最大 Pod 数量。
366+
367+
* 你必须为用户 ID 和组 ID 分配相同的范围。如果其他用户的用户 ID 范围与组 ID 范围不一致也没关系。
368+
369+
<!--
370+
* None of the assigned ranges should overlap with any other assignment.
371+
372+
* The subordinate configuration must be only one line. In other words, you can't
373+
have multiple ranges.
374+
375+
For example, you could define `/etc/subuid` and `/etc/subgid` to both have
376+
these entries for the `kubelet` user:
377+
-->
378+
* 所分配的范围不得与任何其他分配重叠。
379+
380+
* 从属配置必须只有一行。换句话说,你不能有多个范围。
381+
382+
例如,你可以定义 `/etc/subuid``/etc/subgid` 来为 `kubelet` 用户定义以下条目:
383+
384+
<!--
385+
```
386+
# The format is
387+
# name:firstID:count of IDs
388+
# where
389+
# - firstID is 65536 (the minimum value possible)
390+
# - count of IDs is 110 (default limit for number of) * 65536
391+
```
392+
-->
393+
```
394+
# 格式为:
395+
# name:firstID:count of IDs
396+
# 在哪里:
397+
# - firstID 是 65536 (可能的最小值)
398+
# - IDs 的数量是 110(默认数量限制)* 65536
399+
kubelet:65536:7208960
400+
```
279401

280402
[CVE-2021-25741]: https://github.com/kubernetes/kubernetes/issues/104980
403+
[shadow-utils]: https://github.com/shadow-maint/shadow
281404

282405
<!--
283406
## Integration with Pod security admission checks

0 commit comments

Comments
 (0)