Skip to content

Commit 378e505

Browse files
authored
Merge pull request #33444 from kinzhi/kinzhi91
[zh]Update content/zh/docs/reference/access-authn-authz/authentication.md
2 parents cbe94e3 + 50af1ef commit 378e505

File tree

1 file changed

+140
-57
lines changed

1 file changed

+140
-57
lines changed

content/zh/docs/reference/access-authn-authz/authentication.md

Lines changed: 140 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,11 @@ Kubernetes 假定普通用户是由一个与集群无关的服务通过以下方
5151
普通用户的信息无法通过 API 调用添加到集群中。
5252

5353
<!--
54-
Even though normal user cannot be added via an API call, but any user that
55-
presents a valid certificate signed by the clusters certificate authority
54+
Even though a normal user cannot be added via an API call, any user that
55+
presents a valid certificate signed by the cluster's certificate authority
5656
(CA) is considered authenticated. In this configuration, Kubernetes determines
57-
the username from the common name field in the subject of the cert (e.g.,
58-
/CN=bob). From there, the role based access control (RBAC) sub-system would
57+
the username from the common name field in the 'subject' of the cert (e.g.,
58+
"/CN=bob"). From there, the role based access control (RBAC) sub-system would
5959
determine whether the user is authorized to perform a specific operation on a
6060
resource. For more details, refer to the normal users topic in
6161
[certificate request](/docs/reference/access-authn-authz/certificate-signing-requests/#normal-user)
@@ -160,7 +160,7 @@ can be accomplished using an [authenticating proxy](#authenticating-proxy) or th
160160
<!--
161161
### X509 Client Certs
162162
163-
Client certificate authentication is enabled by passing the `-client-ca-file=SOMEFILE`
163+
Client certificate authentication is enabled by passing the `--client-ca-file=SOMEFILE`
164164
option to API server. The referenced file must contain one or more certificate authorities
165165
to use to validate client certificates presented to the API server. If a client certificate
166166
is presented and verified, the common name of the subject is used as the user name for the
@@ -198,7 +198,7 @@ See [Managing Certificates](/docs/tasks/administer-cluster/certificates/) for ho
198198
<!--
199199
### Static Token File
200200
201-
The API server reads bearer tokens from a file when given the `-token-auth-file=SOMEFILE` option on the command line. Currently, tokens last indefinitely, and the token list cannot be
201+
The API server reads bearer tokens from a file when given the `--token-auth-file=SOMEFILE` option on the command line. Currently, tokens last indefinitely, and the token list cannot be
202202
changed without restarting the API server.
203203
204204
The token file is a csv file with a minimum of 3 columns: token, user name, user uid,
@@ -395,7 +395,7 @@ kubectl create serviceaccount jenkins
395395
```
396396

397397
```
398-
serviceaccount/jenkins created
398+
serviceaccount "jenkins" created
399399
```
400400
401401
<!--
@@ -829,7 +829,7 @@ current-context: webhook
829829
contexts:
830830
- context:
831831
cluster: name-of-remote-authn-service
832-
user: name-of-api-sever
832+
user: name-of-api-server
833833
name: webhook
834834
```
835835
-->
@@ -857,116 +857,199 @@ current-context: webhook
857857
contexts:
858858
- context:
859859
cluster: name-of-remote-authn-service
860-
user: name-of-api-sever
860+
user: name-of-api-server
861861
name: webhook
862862
```
863863

864864
<!--
865-
When a client attempts to authenticate with the API server using a bearer token
866-
as discussed [above](#putting-a-bearer-token-in-a-request),
867-
the authentication webhook POSTs a JSON-serialized `authentication.k8s.io/v1beta1` `TokenReview` object containing the token
868-
to the remote service. Kubernetes will not challenge a request that lacks such a header.
865+
When a client attempts to authenticate with the API server using a bearer token as discussed [above](#putting-a-bearer-token-in-a-request),
866+
the authentication webhook POSTs a JSON-serialized `TokenReview` object containing the token to the remote service.
869867
-->
870868
当客户端尝试在 API 服务器上使用持有者令牌完成身份认证(
871869
如[前](#putting-a-bearer-token-in-a-request)所述)时,
872870
身份认证 Webhook 会用 POST 请求发送一个 JSON 序列化的对象到远程服务。
873-
该对象是 `authentication.k8s.io/v1beta1` 组的 `TokenReview` 对象,
871+
该对象是 `TokenReview` 对象,
874872
其中包含持有者令牌。
875873
Kubernetes 不会强制请求提供此 HTTP 头部。
876874

877875
<!--
878-
Note that webhook API objects are subject to the same [versioning compatibility rules](/docs/concepts/overview/kubernetes-api/)
879-
as other Kubernetes API objects. Implementers should be aware of looser
880-
compatibility promises for beta objects and check the "apiVersion" field of the
881-
request to ensure correct deserialization. Additionally, the API server must
882-
enable the `authentication.k8s.io/v1beta1` API extensions group (`--runtime-config=authentication.k8s.io/v1beta1=true`).
883-
884-
The POST body will be of the following format:
876+
Note that webhook API objects are subject to the same [versioning compatibility rules](/docs/concepts/overview/kubernetes-api/) as other Kubernetes API objects.
877+
Implementers should check the `apiVersion` field of the request to ensure correct deserialization,
878+
and **must** respond with a `TokenReview` object of the same version as the request.
885879
-->
886880
要注意的是,Webhook API 对象和其他 Kubernetes API 对象一样,也要受到同一
887881
[版本兼容规则](/zh/docs/concepts/overview/kubernetes-api/)约束。
888-
实现者要了解对 Beta 阶段对象的兼容性承诺,并检查请求的 `apiVersion` 字段,
889-
以确保数据结构能够正常反序列化解析。此外,API 服务器必须启用
890-
`authentication.k8s.io/v1beta1` API 扩展组
891-
(`--runtime-config=authentication.k8s.io/v1beta1=true`)。
882+
实现者应检查请求的 `apiVersion` 字段以确保正确的反序列化,
883+
并且**必须**以与请求相同版本的 `TokenReview` 对象进行响应。
892884

893-
POST 请求的 Body 部分将是如下格式:
894885

886+
{{< tabs name="TokenReview_request" >}}
887+
{{% tab name="authentication.k8s.io/v1" %}}
888+
{{< note >}}
895889
<!--
896-
```json
890+
The Kubernetes API server defaults to sending `authentication.k8s.io/v1beta1` token reviews for backwards compatibility.
891+
To opt into receiving `authentication.k8s.io/v1` token reviews, the API server must be started with `--authentication-token-webhook-version=v1`.
892+
-->
893+
Kubernetes API 服务器默认发送 `authentication.k8s.io/v1beta1` 令牌以实现向后兼容性。
894+
要选择接收 `authentication.k8s.io/v1` 令牌认证,API 服务器必须以 `--authentication-token-webhook-version=v1` 启动。
895+
{{< /note >}}
896+
897+
```yaml
897898
{
898-
"apiVersion": "authentication.k8s.io/v1beta1",
899+
"apiVersion": "authentication.k8s.io/v1",
899900
"kind": "TokenReview",
900901
"spec": {
901-
"token": "(BEARERTOKEN)"
902+
# 发送到 API 服务器的不透明持有者令牌
903+
"token": "014fbff9a07c...",
904+
905+
# 提供令牌的服务器的受众标识符的可选列表。
906+
# 受众感知令牌验证器(例如,OIDC 令牌验证器)
907+
# 应验证令牌是否针对此列表中的至少一个受众,
908+
# 并返回此列表与响应状态中令牌的有效受众的交集。
909+
# 这确保了令牌对于向其提供给的服务器进行身份验证是有效的。
910+
# 如果未提供受众,则应验证令牌以向 Kubernetes API 服务器进行身份验证。
911+
"audiences": ["https://myserver.example.com", "https://myserver.internal.example.com"]
902912
}
903913
}
904914
```
905-
-->
906-
```json
915+
{{% /tab %}}
916+
{{% tab name="authentication.k8s.io/v1beta1" %}}
917+
```yaml
907918
{
908919
"apiVersion": "authentication.k8s.io/v1beta1",
909920
"kind": "TokenReview",
910921
"spec": {
911-
"token": "<持有者令牌>"
922+
# 发送到 API 服务器的不透明匿名令牌
923+
"token": "014fbff9a07c...",
924+
925+
# 提供令牌的服务器的受众标识符的可选列表。
926+
# 受众感知令牌验证器(例如,OIDC 令牌验证器)
927+
# 应验证令牌是否针对此列表中的至少一个受众,
928+
# 并返回此列表与响应状态中令牌的有效受众的交集。
929+
# 这确保了令牌对于向其提供给的服务器进行身份验证是有效的。
930+
# 如果未提供受众,则应验证令牌以向 Kubernetes API 服务器进行身份验证。
931+
"audiences": ["https://myserver.example.com", "https://myserver.internal.example.com"]
912932
}
913933
}
914934
```
935+
{{% /tab %}}
936+
{{< /tabs >}}
915937

916938
<!--
917-
The remote service is expected to fill the `status` field of
918-
the request to indicate the success of the login. The response body's `spec`
919-
field is ignored and may be omitted. A successful validation of the bearer
920-
token would return:
939+
The remote service is expected to fill the `status` field of the request to indicate the success of the login.
940+
The response body's `spec` field is ignored and may be omitted.
941+
The remote service must return a response using the same `TokenReview` API version that it received.
942+
A successful validation of the bearer token would return:
921943
-->
922-
远程服务应该会填充请求的 `status` 字段,以标明登录操作是否成功。
923-
响应的 Body 中的 `spec` 字段会被忽略,因此可以省略。
924-
如果持有者令牌验证成功,应该返回如下所示的响应:
944+
远程服务预计会填写请求的 `status` 字段以指示登录成功。
945+
响应正文的 `spec` 字段被忽略并且可以省略。
946+
远程服务必须使用它收到的相同 `TokenReview` API 版本返回响应。
947+
承载令牌的成功验证将返回:
925948

926-
```json
949+
{{< tabs name="TokenReview_response_success" >}}
950+
{{% tab name="authentication.k8s.io/v1" %}}
951+
```yaml
952+
{
953+
"apiVersion": "authentication.k8s.io/v1",
954+
"kind": "TokenReview",
955+
"status": {
956+
"authenticated": true,
957+
"user": {
958+
# 必要
959+
"username": "[email protected]",
960+
# 可选
961+
"uid": "42",
962+
# 可选的组成员身份
963+
"groups": ["developers", "qa"],
964+
# 认证者提供的可选附加信息。
965+
# 此字段不可包含机密数据,因为这类数据可能被记录在日志或 API 对象中,
966+
# 并且可能传递给 admission webhook。
967+
"extra": {
968+
"extrafield1": [
969+
"extravalue1",
970+
"extravalue2"
971+
]
972+
}
973+
},
974+
# 验证器可以返回的、可选的用户感知令牌列表,
975+
# 包含令牌对其有效的、包含于 `spec.audiences` 列表中的受众。
976+
# 如果省略,则认为该令牌可用于对 Kubernetes API 服务器进行身份验证。
977+
"audiences": ["https://myserver.example.com"]
978+
}
979+
}
980+
```
981+
{{% /tab %}}
982+
{{% tab name="authentication.k8s.io/v1beta1" %}}
983+
```yaml
927984
{
928985
"apiVersion": "authentication.k8s.io/v1beta1",
929986
"kind": "TokenReview",
930987
"status": {
931988
"authenticated": true,
932989
"user": {
990+
# 必要
933991
"username": "[email protected]",
992+
# 可选
934993
"uid": "42",
935-
"groups": [
936-
"developers",
937-
"qa"
938-
],
994+
# 可选的组成员身份
995+
"groups": ["developers", "qa"],
996+
# 认证者提供的可选附加信息。
997+
# 此字段不可包含机密数据,因为这类数据可能被记录在日志或 API 对象中,
998+
# 并且可能传递给 admission webhook。
939999
"extra": {
9401000
"extrafield1": [
9411001
"extravalue1",
9421002
"extravalue2"
9431003
]
9441004
}
945-
}
1005+
},
1006+
# 验证器可以返回的、可选的用户感知令牌列表,
1007+
# 包含令牌对其有效的、包含于 `spec.audiences` 列表中的受众。
1008+
# 如果省略,则认为该令牌可用于对 Kubernetes API 服务器进行身份验证。
1009+
"audiences": ["https://myserver.example.com"]
9461010
}
9471011
}
9481012
```
1013+
{{% /tab %}}
1014+
{{< /tabs >}}
9491015

9501016
<!--
9511017
An unsuccessful request would return:
9521018
-->
9531019
而不成功的请求会返回:
9541020

955-
```json
1021+
{{< tabs name="TokenReview_response_error" >}}
1022+
{{% tab name="authentication.k8s.io/v1" %}}
1023+
```yaml
1024+
{
1025+
"apiVersion": "authentication.k8s.io/v1",
1026+
"kind": "TokenReview",
1027+
"status": {
1028+
"authenticated": false,
1029+
# 可选地包括有关身份验证失败原因的详细信息。
1030+
# 如果没有提供错误信息,API 将返回一个通用的 Unauthorized 消息。
1031+
# 当 authenticated=true 时,error 字段被忽略。
1032+
"error": "Credentials are expired"
1033+
}
1034+
}
1035+
```
1036+
{{% /tab %}}
1037+
{{% tab name="authentication.k8s.io/v1beta1" %}}
1038+
```yaml
9561039
{
9571040
"apiVersion": "authentication.k8s.io/v1beta1",
9581041
"kind": "TokenReview",
9591042
"status": {
960-
"authenticated": false
1043+
"authenticated": false,
1044+
# 可选地包括有关身份验证失败原因的详细信息。
1045+
# 如果没有提供错误信息,API 将返回一个通用的 Unauthorized 消息。
1046+
# 当 authenticated=true 时,error 字段被忽略。
1047+
"error": "Credentials are expired"
9611048
}
9621049
}
9631050
```
964-
965-
<!--
966-
HTTP status codes can be used to supply additional error context.
967-
-->
968-
HTTP 状态码可用来提供进一步的错误语境信息。
969-
1051+
{{% /tab %}}
1052+
{{< /tabs >}}
9701053
<!--
9711054
### Authenticating Proxy
9721055
@@ -981,7 +1064,7 @@ API 服务器可以配置成从请求的头部字段值(如 `X-Remote-User`)
9811064
<!--
9821065
* `--requestheader-username-headers` Required, case-insensitive. Header names to check, in order, for the user identity. The first header containing a value is used as the username.
9831066
* `--requestheader-group-headers` 1.6+. Optional, case-insensitive. "X-Remote-Group" is suggested. Header names to check, in order, for the user's groups. All values in all specified headers are used as group names.
984-
* `-requestheader-extra-headers-prefix` 1.6+. Optional, case-insensitive. "X-Remote-Extra-" is suggested. Header prefixes to look for to determine extra information about the user (typically used by the configured authorization plugin). Any headers beginning with any of the specified prefixes have the prefix removed. The remainder of the header name is lowercased and [percent-decoded](https://tools.ietf.org/html/rfc3986#section-2.1) and becomes the extra key, and the header value is the extra value.
1067+
* `--requestheader-extra-headers-prefix` 1.6+. Optional, case-insensitive. "X-Remote-Extra-" is suggested. Header prefixes to look for to determine extra information about the user (typically used by the configured authorization plugin). Any headers beginning with any of the specified prefixes have the prefix removed. The remainder of the header name is lowercased and [percent-decoded](https://tools.ietf.org/html/rfc3986#section-2.1) and becomes the extra key, and the header value is the extra value.
9851068
-->
9861069
* `--requestheader-username-headers` 必需字段,大小写不敏感。用来设置要获得用户身份所要检查的头部字段名称列表(有序)。第一个包含数值的字段会被用来提取用户名。
9871070
* `--requestheader-group-headers` 可选字段,在 Kubernetes 1.6 版本以后支持,大小写不敏感。
@@ -1096,7 +1179,7 @@ passing the `--anonymous-auth=true` option to the API server.
10961179

10971180
<!--
10981181
In 1.6+, anonymous access is enabled by default if an authorization mode other than `AlwaysAllow`
1099-
is used, and can be disabled by passing the `-anonymous-auth=false` option to the API server.
1182+
is used, and can be disabled by passing the `--anonymous-auth=false` option to the API server.
11001183
Starting in 1.6, the ABAC and RBAC authorizers require explicit authorization of the
11011184
`system:anonymous` user or the `system:unauthenticated` group, so legacy policy rules
11021185
that grant access to the `*` user or `*` group do not include anonymous users.
@@ -1196,12 +1279,11 @@ extra fields:
11961279

11971280
```http
11981281
Impersonate-User: [email protected]
1199-
Impersonate-Group: developers
1200-
Impersonate-Group: admins
12011282
Impersonate-Extra-dn: cn=jane,ou=engineers,dc=example,dc=com
12021283
Impersonate-Extra-acme.com%2Fproject: some-project
12031284
Impersonate-Extra-scopes: view
12041285
Impersonate-Extra-scopes: development
1286+
Impersonate-Uid: 06f6ce97-e2c5-4ab8-7ba5-7654dd08d52b
12051287
```
12061288

12071289
<!--
@@ -1842,6 +1924,7 @@ Certificates)。
18421924
<!--
18431925
Optionally, the response can include the expiry of the credential formatted as a
18441926
[RFC 3339](https://datatracker.ietf.org/doc/html/rfc3339) timestamp.
1927+
18451928
Presence or absence of an expiry has the following impact:
18461929

18471930
- If an expiry is included, the bearer token and TLS credentials are cached until

0 commit comments

Comments
 (0)