@@ -106,12 +106,164 @@ Kubernetes 区分用户账号和服务账号的概念,主要基于以下原因
106
106
- 针对复杂系统的配置包可能包含系统组件相关的各种服务账号的定义。
107
107
因为服务账号的创建约束不多并且有名字空间域的名称,所以这种配置通常是轻量的。
108
108
109
+ <!--
110
+ ## Bound service account tokens
111
+ -->
112
+ ## 绑定的服务账户令牌 {#bound-service-account-tokens}
113
+
114
+ <!--
115
+ ServiceAccount tokens can be bound to API objects that exist in the kube-apiserver.
116
+ This can be used to tie the validity of a token to the existence of another API object.
117
+ Supported object types are as follows:
118
+
119
+ * Pod (used for projected volume mounts, see below)
120
+ * Secret (can be used to allow revoking a token by deleting the Secret)
121
+ * Node (in v1.30, creating new node-bound tokens is alpha, using existing node-bound tokens is beta)
122
+ -->
123
+ ServiceAccount 令牌可以被绑定到 kube-apiserver 中存在的 API 对象。
124
+ 这可用于将令牌的有效性与另一个 API 对象的存在与否关联起来。
125
+ 支持的对象类型如下:
126
+
127
+ * Pod(用于投射卷的挂载,见下文)
128
+ * Secret(可用于允许通过删除 Secret 来撤销令牌)
129
+ * 节点(在 v1.30 中,创建新的节点绑定令牌是 Alpha 特性,使用现有的节点绑定特性是 Beta 特性)
130
+
131
+ <!--
132
+ When a token is bound to an object, the object's `metadata.name` and `metadata.uid` are
133
+ stored as extra 'private claims' in the issued JWT.
134
+
135
+ When a bound token is presented to the kube-apiserver, the service account authenticator
136
+ will extract and verify these claims.
137
+ If the referenced object no longer exists (or its `metadata.uid` does not match),
138
+ the request will not be authenticated.
139
+ -->
140
+ 当将令牌绑定到某对象时,该对象的 ` metadata.name ` 和 ` metadata.uid `
141
+ 将作为额外的“私有声明”存储在所发布的 JWT 中。
142
+
143
+ 当将被绑定的令牌提供给 kube-apiserver 时,服务帐户身份认证组件将提取并验证这些声明。
144
+ 如果所引用的对象不再存在(或其 ` metadata.uid ` 不匹配),则请求将无法通过认证。
145
+
146
+ <!--
147
+ ### Additional metadata in Pod bound tokens
148
+ -->
149
+ ### Pod 绑定令牌中的附加元数据 {#additional-metadata-in-pod-bound-tokens}
150
+
151
+ {{< feature-state feature_gate_name="ServiceAccountTokenPodNodeInfo" >}}
152
+
153
+ <!--
154
+ When a service account token is bound to a Pod object, additional metadata is also
155
+ embedded into the token that indicates the value of the bound pod's `spec.nodeName` field,
156
+ and the uid of that Node, if available.
157
+
158
+ This node information is **not** verified by the kube-apiserver when the token is used for authentication.
159
+ It is included so integrators do not have to fetch Pod or Node API objects to check the associated Node name
160
+ and uid when inspecting a JWT.
161
+ -->
162
+ 当服务帐户令牌被绑定到某 Pod 对象时,一些额外的元数据也会被嵌入到令牌中,
163
+ 包括所绑定 Pod 的 ` spec.nodeName ` 字段的值以及该节点的 uid(如果可用)。
164
+
165
+ 当使用令牌进行身份认证时,kube-apiserver ** 不会** 检查此节点信息的合法性。
166
+ 由于节点信息被包含在令牌内,所以集成商在检查 JWT 时不必获取 Pod 或 Node API 对象来检查所关联的 Node 名称和 uid。
167
+
168
+ <!--
169
+ ### Verifying and inspecting private claims
170
+
171
+ The `TokenReview` API can be used to verify and extract private claims from a token:
172
+ -->
173
+ ### 查验和检视私有声明 {#verifying-and-inspecting-private-claims}
174
+
175
+ ` TokenReview ` API 可用于校验并从令牌中提取私有声明:
176
+
177
+ <!--
178
+ 1. First, assume you have a pod named `test-pod` and a service account named `my-sa`.
179
+ 2. Create a token that is bound to this Pod:
180
+ -->
181
+ 1 . 首先,假设你有一个名为 ` test-pod ` 的 Pod 和一个名为 ` my-sa ` 的服务帐户。
182
+ 2 . 创建绑定到此 Pod 的令牌:
183
+
184
+ ``` shell
185
+ kubectl create token my-sa --bound-object-kind=" Pod" --bound-object-name=" test-pod"
186
+ ```
187
+
188
+ <!--
189
+ 3. Copy this token into a new file named `tokenreview.yaml`:
190
+ -->
191
+ 3 . 将此令牌复制到名为 ` tokenreview.yaml ` 的新文件中:
192
+
193
+ ``` yaml
194
+ apiVersion : authentication.k8s.io/v1
195
+ kind : TokenReview
196
+ spec :
197
+ token : <来自第二步的令牌内容>
198
+ ` ` `
199
+
200
+ <!--
201
+ 4. Submit this resource to the apiserver for review:
202
+ -->
203
+ 4. 将此资源提交给 API 服务器进行审核:
204
+
205
+ <!--
206
+ # we use '-o yaml' so we can inspect the output
207
+ -->
208
+ ` ` ` shell
209
+ kubectl create -o yaml -f tokenreview.yaml # 我们使用 '-o yaml' 以便检视命令输出
210
+ ```
211
+
212
+ <!--
213
+ You should see an output like below:
214
+ -->
215
+ 你应该看到如下所示的输出:
216
+
217
+ ``` yaml
218
+ apiVersion : authentication.k8s.io/v1
219
+ kind : TokenReview
220
+ metadata :
221
+ creationTimestamp : null
222
+ spec :
223
+ token : <token>
224
+ status :
225
+ audiences :
226
+ - https://kubernetes.default.svc.cluster.local
227
+ authenticated : true
228
+ user :
229
+ extra :
230
+ authentication.kubernetes.io/credential-id :
231
+ - JTI=7ee52be0-9045-4653-aa5e-0da57b8dccdc
232
+ authentication.kubernetes.io/node-name :
233
+ - kind-control-plane
234
+ authentication.kubernetes.io/node-uid :
235
+ - 497e9d9a-47aa-4930-b0f6-9f2fb574c8c6
236
+ authentication.kubernetes.io/pod-name :
237
+ - test-pod
238
+ authentication.kubernetes.io/pod-uid :
239
+ - e87dbbd6-3d7e-45db-aafb-72b24627dff5
240
+ groups :
241
+ - system:serviceaccounts
242
+ - system:serviceaccounts:default
243
+ - system:authenticated
244
+ uid : f8b4161b-2e2b-11e9-86b7-2afc33b31a7e
245
+ username : system:serviceaccount:default:my-sa
246
+ ` ` `
247
+
248
+ {{< note >}}
249
+ <!--
250
+ Despite using ` kubectl create -f` to create this resource, and defining it similar to
251
+ other resource types in Kubernetes, TokenReview is a special type and the kube-apiserver
252
+ does not actually persist the TokenReview object into etcd.
253
+ Hence `kubectl get tokenreview` is not a valid command.
254
+ -->
255
+ 尽管你使用了 `kubectl create -f` 来创建此资源,并与 Kubernetes
256
+ 中的其他资源类型类似的方式定义它,但 TokenReview 是一种特殊类别,
257
+ kube-apiserver 实际上并不将 TokenReview 对象持久保存到 etcd 中。
258
+ 因此 `kubectl get tokenreview` 不是一个有效的命令。
259
+ {{< /note >}}
260
+
109
261
<!--
110
262
# # Bound service account token volume mechanism {#bound-service-account-token-volume}
111
263
-->
112
264
# # 绑定的服务账号令牌卷机制 {#bound-service-account-token-volume}
113
265
114
- {{< feature-state for_k8s_version="v1.22" state="stable " >}}
266
+ {{< feature-state feature_gate_name="BoundServiceAccountTokenVolume " >}}
115
267
116
268
<!--
117
269
By default, the Kubernetes control plane (specifically, the
@@ -445,7 +597,7 @@ it does the following when a Pod is created:
445
597
-->
446
598
# ## 传统 ServiceAccount 令牌追踪控制器
447
599
448
- {{< feature-state for_k8s_version="v1.28" state="stable " >}}
600
+ {{< feature-state feature_gate_name="LegacyServiceAccountTokenTracking " >}}
449
601
450
602
<!--
451
603
This controller generates a ConfigMap called
@@ -462,7 +614,7 @@ account tokens began to be monitored by the system.
462
614
-->
463
615
# ## 传统 ServiceAccount 令牌清理器
464
616
465
- {{< feature-state for_k8s_version="v1.29" state="beta " >}}
617
+ {{< feature-state feature_gate_name="LegacyServiceAccountTokenCleanUp " >}}
466
618
467
619
<!--
468
620
The legacy ServiceAccount token cleaner runs as part of the
0 commit comments