diff --git a/content/zh-cn/docs/reference/access-authn-authz/authentication.md b/content/zh-cn/docs/reference/access-authn-authz/authentication.md index 12b16a784a..cc0253cf10 100644 --- a/content/zh-cn/docs/reference/access-authn-authz/authentication.md +++ b/content/zh-cn/docs/reference/access-authn-authz/authentication.md @@ -1987,6 +1987,200 @@ The following `ExecCredential` manifest describes a cluster information sample. {{% /tab %}} {{< /tabs >}} + +## 为客户端提供的对身份验证信息的 API 访问 {#self-subject-review} + +{{< feature-state for_k8s_version="v1.26" state="alpha" >}} + + +如果集群启用了此 API,你可以使用 `SelfSubjectReview` API 来了解 Kubernetes +集群如何映射你的身份验证信息从而将你识别为某客户端。无论你是作为用户(通常代表一个真的人)还是作为 +ServiceAccount 进行身份验证,这一 API 都可以使用。 + +`SelfSubjectReview` 对象没有任何可配置的字段。 +Kubernetes API 服务器收到请求后,将使用用户属性填充 status 字段并将其返回给用户。 + +请求示例(主体将是 `SelfSubjectReview`): + +``` +POST /apis/authentication.k8s.io/v1alpha1/selfsubjectreviews +``` + +```json +{ + "apiVersion": "authentication.k8s.io/v1alpha1", + "kind": "SelfSubjectReview" +} +``` + + +响应示例: + +```json +{ + "apiVersion": "authentication.k8s.io/v1alpha1", + "kind": "SelfSubjectReview", + "status": { + "userInfo": { + "name": "jane.doe", + "uid": "b6c7cfd4-f166-11ec-8ea0-0242ac120002", + "groups": [ + "viewers", + "editors", + "system:authenticated" + ], + "extra": { + "provider_id": ["token.company.example"] + } + } + } +} +``` + + +为了方便,Kubernetes 提供了 `kubectl alpha auth whoami` 命令。 +执行此命令将产生以下输出(但将显示不同的用户属性): + +* 简单的输出示例 + + ``` + ATTRIBUTE VALUE + Username jane.doe + Groups [system:authenticated] + ``` + + +* 包括额外属性的复杂示例 + + ``` + ATTRIBUTE VALUE + Username jane.doe + UID b79dbf30-0c6a-11ed-861d-0242ac120002 + Groups [students teachers system:authenticated] + Extra: skills [reading learning] + Extra: subjects [math sports] + ``` + + +通过提供 output 标志,也可以打印结果的 JSON 或 YAML 表现形式: + +{{< tabs name="self_subject_attributes_review_Example_1" >}} +{{% tab name="JSON" %}} +```json +{ + "apiVersion": "authentication.k8s.io/v1alpha1", + "kind": "SelfSubjectReview", + "status": { + "userInfo": { + "username": "jane.doe", + "uid": "b79dbf30-0c6a-11ed-861d-0242ac120002", + "groups": [ + "students", + "teachers", + "system:authenticated" + ], + "extra": { + "skills": [ + "reading", + "learning" + ], + "subjects": [ + "math", + "sports" + ] + } + } + } +} +``` +{{% /tab %}} + +{{% tab name="YAML" %}} +```yaml +apiVersion: authentication.k8s.io/v1alpha1 +kind: SelfSubjectReview +status: + userInfo: + username: jane.doe + uid: b79dbf30-0c6a-11ed-861d-0242ac120002 + groups: + - students + - teachers + - system:authenticated + extra: + skills: + - reading + - learning + subjects: + - math + - sports +``` +{{% /tab %}} +{{< /tabs >}} + + +在 Kubernetes 集群中使用复杂的身份验证流程时,例如如果你使用 +[Webhook 令牌身份验证](/zh-cn/docs/reference/access-authn-authz/authentication/#webhook-token-authentication)或[身份验证代理](/zh-cn/docs/reference/access-authn-authz/authentication/#authenticating-proxy)时, +此特性极其有用。 + +{{< note >}} + +Kubernetes API 服务器在所有身份验证机制 +(包括[伪装](/zh-cn/docs/reference/access-authn-authz/authentication/#user-impersonation)), +被应用后填充 `userInfo`, +如果你或某个身份验证代理使用伪装进行 SelfSubjectReview,你会看到被伪装用户的用户详情和属性。 +{{< /note >}} + + +默认情况下,所有经过身份验证的用户都可以在 `APISelfSubjectReview` 特性被启用时创建 `SelfSubjectReview` 对象。 +这是 `system:basic-user` 集群角色允许的操作。 + +{{< note >}} + +你只能在以下情况下进行 `SelfSubjectReview` 请求: + +* 集群启用了 `APISelfSubjectReview` + [特性门控](/zh-cn/docs/reference/command-line-tools-reference/feature-gates/) +* 集群的 API 服务器已启用 `authentication.k8s.io/v1alpha1` + {{< glossary_tooltip term_id="api-group" text="API 组" >}}。。 +{{< /note >}} + ## {{% heading "whatsnext" %}}