1
1
---
2
- title : 为 Pod 配置用户名字空间
2
+ title : 为 Pod 配置 user 名字空间
3
3
reviewers :
4
4
content_type : task
5
5
weight : 210
@@ -15,14 +15,14 @@ min-kubernetes-server-version: v1.25
15
15
-->
16
16
17
17
<!-- overview -->
18
- {{< feature-state for_k8s_version="v1.25" state="alpha " >}}
18
+ {{< feature-state for_k8s_version="v1.25" state="beta " >}}
19
19
20
20
<!--
21
21
This page shows how to configure a user namespace for stateless pods. This
22
22
allows to isolate the user running inside the container from the one in the
23
23
host.
24
24
-->
25
- 本页展示如何为无状态 Pod 配置用户名字空间 。可以将容器内的用户与主机上的用户隔离开来。
25
+ 本页展示如何为无状态 Pod 配置 user 名字空间 。可以将容器内的用户与主机上的用户隔离开来。
26
26
27
27
<!--
28
28
A 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
31
31
namespace.
32
32
-->
33
33
在容器中以 root 用户运行的进程可以以不同的(非 root)用户在宿主机上运行;换句话说,
34
- 进程在用户名字空间内部拥有执行操作的全部特权,但在用户名字空间外部并没有执行操作的特权 。
34
+ 进程在 user 名字空间内部拥有执行操作的全部特权,但在 user 名字空间外部并没有执行操作的特权 。
35
35
36
36
<!--
37
37
You 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
41
41
mitigate some future vulnerabilities too.
42
42
-->
43
43
你可以使用这个特性来减少有害的容器对同一宿主机上其他容器的影响。
44
- [ 有些安全脆弱性问题] [ KEP-vulns ] 被评为 ** HIGH** or ** CRITICAL** ,但当用户名字空间被启用时 ,
45
- 它们是无法被利用的。相信用户名字空间也能减轻一些未来的漏洞的影响 。
44
+ [ 有些安全脆弱性问题] [ KEP-vulns ] 被评为 ** HIGH** 或 ** CRITICAL** ,但当 user 名字空间被启用时 ,
45
+ 它们是无法被利用的。相信 user 名字空间也能减轻一些未来的漏洞影响 。
46
46
47
47
<!--
48
48
Without using a user namespace a container running as root, in the case of a
49
49
container breakout, has root privileges on the node. And if some capability were
50
50
granted to the container, the capabilities are valid on the host too. None of
51
51
this is true when user namespaces are used.
52
52
-->
53
- 在不使用用户名字空间的情况下 ,对于以 root 用户运行的容器而言,发生容器逃逸时,
53
+ 在不使用 user 名字空间的情况下 ,对于以 root 用户运行的容器而言,发生容器逃逸时,
54
54
容器将拥有在宿主机上的 root 特权。如果容器被赋予了某些权限,则这些权限在宿主机上同样有效。
55
- 当使用用户名字空间时这些都不可能发生 。
55
+ 当使用 user 名字空间时这些都不可能发生 。
56
56
57
57
[ KEP-vulns ] : https://github.com/kubernetes/enhancements/tree/217d790720c5aef09b8bd4d6ca96284a0affe6c2/keps/sig-node/127-user-namespaces#motivation
58
58
@@ -70,18 +70,18 @@ this is true when user namespaces are used.
70
70
* You need to enable the `UserNamespacesSupport`
71
71
[feature gate](/docs/reference/command-line-tools-reference/feature-gates/)
72
72
-->
73
- * 节点上的操作系统必须为 Linux
73
+ * 节点的操作系统必须为 Linux
74
74
* 你需要在宿主机上执行命令
75
75
* 你需要能够通过 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/ )
77
77
78
78
{{< note >}}
79
79
<!--
80
80
The feature gate to enable user namespaces was previously named
81
81
`UserNamespacesStatelessPodsSupport`, when only stateless pods were supported.
82
82
Only Kubernetes v1.25 through to v1.27 recognise `UserNamespacesStatelessPodsSupport`.
83
83
-->
84
- 在用户名字空间原来仅支持无状态的 Pod 时,启用用户名字空间的特性门控先前被命名为 ` UserNamespacesStatelessPodsSupport ` 。
84
+ 在 user 名字空间原来仅支持无状态的 Pod 时,启用 user 名字空间的特性门控先前被命名为 ` UserNamespacesStatelessPodsSupport ` 。
85
85
只有 Kubernetes v1.25 到 v1.27 才能识别 ` UserNamespacesStatelessPodsSupport ` 。
86
86
{{</ note >}}
87
87
@@ -92,39 +92,29 @@ for using user namespaces with Pods.
92
92
-->
93
93
你所使用的集群** 必须** 包括至少一个符合
94
94
[ 要求] ( /zh-cn/docs/concepts/workloads/pods/user-namespaces/#before-you-begin )
95
- 的节点,以便为 Pod 配置用户名字空间 。
95
+ 的节点,以便为 Pod 配置 user 名字空间 。
96
96
97
97
<!--
98
98
If you have a mixture of nodes and only some of the nodes provide user namespace support for
99
99
Pods, you also need to ensure that the user namespace Pods are
100
100
[scheduled](/docs/concepts/scheduling-eviction/assign-pod-node/) to suitable nodes.
101
101
-->
102
- 如果你有混合节点,并且只有部分节点支持为 Pod 配置用户名字空间 ,
103
- 你还需要确保配置了用户名字空间的 Pod
102
+ 如果你有混合节点,并且只有部分节点支持为 Pod 配置 user 名字空间 ,
103
+ 你还需要确保配置了 user 名字空间的 Pod
104
104
被[ 调度] ( /zh-cn/docs/concepts/scheduling-eviction/assign-pod-node/ ) 到合适的节点。
105
105
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
-
116
106
<!-- steps -->
117
107
118
108
<!--
119
109
## Run a Pod that uses a user namespace {#create-pod}
120
110
-->
121
- ## 运行一个使用用户名字空间的 Pod {#create-pod}
111
+ ## 运行一个使用 user 名字空间的 Pod {#create-pod}
122
112
123
113
<!--
124
114
A user namespace for a pod is enabled setting the `hostUsers` field of `.spec`
125
115
to `false`. For example:
126
116
-->
127
- 为一个 Pod 启用用户名字空间需要设置 ` .spec ` 的 ` hostUsers ` 字段为 ` false ` . 例如:
117
+ 为一个 Pod 启用 user 名字空间需要设置 ` .spec ` 的 ` hostUsers ` 字段为 ` false ` 。例如:
128
118
129
119
{{% code_sample file="pods/user-namespaces-stateless.yaml" %}}
130
120
@@ -147,15 +137,39 @@ to `false`. For example:
147
137
```
148
138
149
139
<!--
150
- And run the command. The output is similar to this :
140
+ Run this command:
151
141
-->
152
- 执行命令的输出类似于 :
142
+ 运行这个命令 :
153
143
154
- ``` none
144
+ ``` shell
155
145
readlink /proc/self/ns/user
146
+ ```
147
+
148
+ <!--
149
+ The output is similar to:
150
+ -->
151
+ 输出类似于:
152
+
153
+ ``` shell
156
154
user:[4026531837]
155
+ ```
156
+
157
+ <!--
158
+ Also run:
159
+ -->
160
+ 还运行:
161
+
162
+ ``` shell
157
163
cat /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
159
173
```
160
174
161
175
<!--
@@ -164,30 +178,29 @@ Then, open a shell in the host and run the same command.
164
178
然后,在主机中打开一个 Shell 并运行相同的命令。
165
179
166
180
<!--
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.
170
183
-->
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,在主机上它必须是更大的数字。
173
191
174
192
<!--
175
193
If you are running the kubelet inside a user namespace, you need to compare the
176
194
output from running the command in the pod to the output of running in the host:
177
195
-->
178
- 如果你在用户名字空间中运行 kubelet,则需要将在 Pod 中运行命令的输出与在主机中运行的输出进行比较:
196
+ 如果你在 user 名字空间中运行 kubelet,则需要将在 Pod 中运行命令的输出与在主机中运行的输出进行比较:
179
197
180
- <!--
181
- ```none
198
+ ``` shell
182
199
readlink /proc/$pid /ns/user
183
- user:[4026534732]
184
200
```
185
201
202
+ <!--
186
203
replacing `$pid` with the kubelet PID.
187
204
-->
188
- ``` none
189
- readlink /proc/$pid/ns/user
190
- user:[4026534732]
191
- ```
192
205
193
- 使用 kubelet 的进程号代替 ` $pid `
206
+ 使用 kubelet 的进程号代替 ` $pid ` 。
0 commit comments