Skip to content

Commit acac224

Browse files
authored
Merge pull request #30734 from chenxuc/authn-authz-2
[zh] sync auth for 1.22
2 parents 4d519da + fdfa669 commit acac224

File tree

3 files changed

+88
-52
lines changed

3 files changed

+88
-52
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
22
title: 访问 API
3-
weight: 20
3+
weight: 15
44
no_list: true
55
---
66

77
<!--
88
title: API Access Control
9-
weight: 20
9+
weight: 15
1010
no_list: true
1111
-->
1212

content/zh/docs/reference/access-authn-authz/certificate-signing-requests.md

Lines changed: 84 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ reviewers:
88
- liggitt
99
- mikedanese
1010
- munnerz
11+
- enj
1112
title: Certificate Signing Requests
1213
content_type: concept
1314
weight: 20
@@ -50,13 +51,18 @@ The CertificateSigningRequest object includes a PEM-encoded PKCS#10 signing requ
5051
the `spec.request` field. The CertificateSigningRequest denotes the _signer_ (the
5152
recipient that the request is being made to) using the `spec.signerName` field.
5253
Note that `spec.signerName` is a required key after api version `certificates.k8s.io/v1`.
54+
In Kubernetes v1.22 and later, clients may optionally set the `spec.expirationSeconds`
55+
field to request a particular lifetime for the issued certificate. The minimum valid
56+
value for this field is `600`, i.e. ten minutes.
5357
-->
5458
## 请求签名流程 {#request-signing-process}
5559

5660
CertificateSigningRequest 资源类型允许客户使用它申请发放 X.509 证书。
5761
CertificateSigningRequest 对象 在 `spec.request` 中包含一个 PEM 编码的 PKCS#10 签名请求。
5862
CertificateSigningRequest 使用 `spec.signerName` 字段标示 _签名者_(请求的接收方)。
5963
注意,`spec.signerName``certificates.k8s.io/v1` 之后的 API 版本是必填项。
64+
在 Kubernetes v1.22 和以后的版本,客户可以可选地设置 `spec.expirationSeconds`
65+
字段来为颁发的证书设定一个特定的有效期。该字段的最小有效值是 `600`,也就是 10 分钟。
6066

6167
<!--
6268
Once created, a CertificateSigningRequest must be approved before it can be signed.
@@ -113,15 +119,19 @@ state for some duration:
113119
114120
* Approved requests: automatically deleted after 1 hour
115121
* Denied requests: automatically deleted after 1 hour
116-
* Pending requests: automatically deleted after 1 hour
122+
* Failed requests: automatically deleted after 1 hour
123+
* Pending requests: automatically deleted after 24 hours
124+
* All requests: automatically deleted after the issued certificate has expired
117125
-->
118126
为了减少集群中遗留的过时的 CertificateSigningRequest 资源的数量,
119127
一个垃圾收集控制器将会周期性地运行。
120128
此垃圾收集器会清除在一段时间内没有改变过状态的 CertificateSigningRequests:
121129

122130
* 已批准的请求:1小时后自动删除
123131
* 已拒绝的请求:1小时后自动删除
124-
* 挂起的请求:1小时后自动删除
132+
* 已失败的请求:1小时后自动删除
133+
* 挂起的请求:24小时后自动删除
134+
* 所有请求:在颁发的证书过期后自动删除
125135

126136
<!--
127137
## Signers
@@ -146,10 +156,8 @@ This includes:
146156
and behavior when a disallowed extension is requested.
147157
4. **Permitted key usages / extended key usages**: any restrictions on and behavior
148158
when usages different than the signer-determined usages are specified in the CSR.
149-
5. **Expiration/certificate lifetime**: whether it is fixed by the signer,
150-
configurable by the admin, determined by the CSR object etc and the behavior
151-
when an expiration is different than the signer-determined expiration
152-
that is specified in the CSR.
159+
5. **Expiration/certificate lifetime**: whether it is fixed by the signer, configurable by the admin, determined by the CSR `spec.expirationSeconds` field, etc
160+
and the behavior when the signer-determined expiration is different from the CSR `spec.expirationSeconds` field.
153161
6. **CA bit allowed/disallowed**: and behavior if a CSR contains a request
154162
a for a CA certificate when the signer does not permit it.
155163
-->
@@ -159,8 +167,8 @@ This includes:
159167
Email subjectAltNames、URI subjectAltNames 等,请求一个受限制的扩展项时的应对手段。
160168
4. **许可的密钥用途/扩展的密钥用途**:当用途和签名者在 CSR 中指定的用途不同时,
161169
相应的限制和应对手段。
162-
5. **过期时间/证书有效期**:过期时间由签名者确定、由管理员配置还是由 CSR 对象指定等
163-
以及过期时间与签名者在 CSR 中指定过期时间不同时的应对手段
170+
5. **过期时间/证书有效期**:过期时间由签名者确定、由管理员配置还是由 CSR `spec.expirationSeconds` 字段指定等
171+
以及签名者决定的过期时间与 CSR `spec.expirationSeconds` 字段不同时的应对手段
164172
6. **允许/不允许 CA 位**:当 CSR 包含一个签名者并不允许的 CA 证书的请求时,相应的应对手段。
165173

166174
<!--
@@ -178,21 +186,30 @@ intermediates to be presented during TLS handshakes.
178186
例如,这是要在 TLS 握手时提供的证书和中继证书。
179187

180188
<!--
181-
The PKCS#10 signing request format doesn't allow to specify a certificate
182-
expiration or lifetime. The expiration or lifetime therefore has to be set
183-
through e.g. an annotation on the CSR object. While it's theoretically
184-
possible for a signer to use that expiration date, there is currently no
185-
known implementation that does. (The built-in signers all use the same
186-
`ClusterSigningDuration` configuration option, which defaults to 1 year,
187-
and can be changed with the `--cluster-signing-duration` command-line
188-
flag of the kube-controller-manager.)
189-
-->
190-
PKCS#10 签名请求格式不允许设置证书的过期时间或者生命期。因此,证书的过期
191-
时间或者生命期必须通过类似 CSR 对象的注解字段这种形式来设置。
192-
尽管让签名者使用过期日期从理论上来讲也是可行的,目前还不存在哪个实现这样做了。
193-
(内置的签名者都是用相同的 `ClusterSigningDuration` 配置选项,而该选项
194-
中将生命期的默认值设为 1 年,且可通过 kube-controller-manager 的命令行选项
195-
`--cluster-signing-duration` 来更改。)
189+
The PKCS#10 signing request format does not have a standard mechanism to specify a
190+
certificate expiration or lifetime. The expiration or lifetime therefore has to be set
191+
through the `spec.expirationSeconds` field of the CSR object. The built-in signers
192+
use the `ClusterSigningDuration` configuration option, which defaults to 1 year,
193+
(the `--cluster-signing-duration` command-line flag of the kube-controller-manager)
194+
as the default when no `spec.expirationSeconds` is specified. When `spec.expirationSeconds`
195+
is specified, the minimum of `spec.expirationSeconds` and `ClusterSigningDuration` is
196+
used.
197+
-->
198+
PKCS#10 签名请求格式并没有一种标准的方法去设置证书的过期时间或者生命期。
199+
因此,证书的过期时间或者生命期必须通过 CSR 对象的 `spec.expirationSeconds` 字段来设置。
200+
`spec.expirationSeconds` 没有被指定时,内置的签名者默认使用 `ClusterSigningDuration` 配置选项
201+
(kube-controller-manager 的命令行选项 `--cluster-signing-duration`),该选项的默认值设为 1 年。
202+
`spec.expirationSeconds` 被指定时,`spec.expirationSeconds``ClusterSigningDuration`
203+
中的最小值会被使用。
204+
205+
{{< note >}}
206+
<!--
207+
The `spec.expirationSeconds` field was added in Kubernetes v1.22. Earlier versions of Kubernetes do not honor this field.
208+
Kubernetes API servers prior to v1.22 will silently drop this field when the object is created.
209+
-->
210+
`spec.expirationSeconds` 字段是在 Kubernetes v1.22 中加入的。早期的 Kubernetes 版本并不认识该字段。
211+
v1.22 版本之前的 Kubernetes API 服务器会在创建对象的时候忽略该字段。
212+
{{< /note >}}
196213

197214
<!--
198215
### Kubernetes signers
@@ -214,8 +231,8 @@ Kubernetes提供了内置的签名者,每个签名者都有一个众所周知
214231
but it is often not the only cluster-admin subject in a cluster.
215232
1. Permitted x509 extensions - honors subjectAltName and key usage extensions and discards other extensions.
216233
1. Permitted key usages - must include `["client auth"]`. Must not include key usages beyond `["digital signature", "key encipherment", "client auth"]`.
217-
1. Expiration/certificate lifetime - set by the `--cluster-signing-duration` option for the
218-
kube-controller-manager implementation of this signer.
234+
1. Expiration/certificate lifetime - for the kube-controller-manager implementation of this signer, set to the minimum
235+
of the `--cluster-signing-duration` option or, if specified, the `spec.expirationSeconds` field of the CSR object.
219236
1. CA bit allowed/disallowed - not allowed.
220237
-->
221238
1. `kubernetes.io/kube-apiserver-client`:签名的证书将被 API 服务器视为客户证书。
@@ -229,8 +246,8 @@ Kubernetes提供了内置的签名者,每个签名者都有一个众所周知
229246
1. 许可的 x509 扩展:允许 subjectAltName 和 key usage 扩展,弃用其他扩展。
230247
1. 许可的密钥用途:必须包含 `["client auth"]`,但不能包含
231248
`["digital signature", "key encipherment", "client auth"]` 之外的键。
232-
1. 过期时间/证书有效期:通过 kube-controller-manager `--cluster-signing-duration`
233-
标志来设置,由其中的签名者实施
249+
1. 过期时间/证书有效期:对于 kube-controller-manager 实现的签名者,
250+
设置为 `--cluster-signing-duration` 选项和 CSR 对象的 `spec.expirationSeconds` 字段(如有设置该字段)中的最小值
234251
1. 允许/不允许 CA 位:不允许。
235252

236253
<!--
@@ -242,8 +259,8 @@ Kubernetes提供了内置的签名者,每个签名者都有一个众所周知
242259
1. Permitted subjects - organizations are exactly `["system:nodes"]`, common name starts with "`system:node:`".
243260
1. Permitted x509 extensions - honors key usage extensions, forbids subjectAltName extensions and drops other extensions.
244261
1. Permitted key usages - exactly `["key encipherment", "digital signature", "client auth"]`.
245-
1. Expiration/certificate lifetime - set by the `--cluster-signing-duration` option for the
246-
kube-controller-manager implementation of this signer.
262+
1. Expiration/certificate lifetime - for the kube-controller-manager implementation of this signer, set to the minimum
263+
of the `--cluster-signing-duration` option or, if specified, the `spec.expirationSeconds` field of the CSR object.
247264
1. CA bit allowed/disallowed - not allowed.
248265
-->
249266
2. `kubernetes.io/kube-apiserver-client-kubelet`: 签名的证书将被 kube-apiserver 视为客户证书。
@@ -253,8 +270,8 @@ Kubernetes提供了内置的签名者,每个签名者都有一个众所周知
253270
1. 许可的主体:组织名必须是 `["system:nodes"]`,用户名以 "`system:node:`" 开头
254271
1. 许可的 x509 扩展:允许 key usage 扩展,禁用 subjectAltName 扩展,并删除其他扩展。
255272
1. 许可的密钥用途:必须是 `["key encipherment", "digital signature", "client auth"]`
256-
1. 过期时间/证书有效期:通过 kube-controller-manager 中签名者的实现所对应的标志
257-
`--cluster-signing-duration` 来设置
273+
1. 过期时间/证书有效期:对于 kube-controller-manager 实现的签名者,
274+
设置为 `--cluster-signing-duration` 选项和 CSR 对象的 `spec.expirationSeconds` 字段(如有设置该字段)中的最小值
258275
1. 允许/不允许 CA 位:不允许。
259276

260277
<!--
@@ -266,7 +283,8 @@ Kubernetes提供了内置的签名者,每个签名者都有一个众所周知
266283
1. Permitted x509 extensions - honors key usage and DNSName/IPAddress subjectAltName extensions, forbids EmailAddress and
267284
URI subjectAltName extensions, drops other extensions. At least one DNS or IP subjectAltName must be present.
268285
1. Permitted key usages - exactly `["key encipherment", "digital signature", "server auth"]`.
269-
1. Expiration/certificate lifetime - minimum of CSR signer or request.
286+
1. Expiration/certificate lifetime - for the kube-controller-manager implementation of this signer, set to the minimum
287+
of the `--cluster-signing-duration` option or, if specified, the `spec.expirationSeconds` field of the CSR object.
270288
1. CA bit allowed/disallowed - not allowed.
271289
-->
272290
3. `kubernetes.io/kubelet-serving`: 签名服务证书,该服务证书被 API 服务器视为有效的 kubelet 服务证书,
@@ -277,8 +295,8 @@ Kubernetes提供了内置的签名者,每个签名者都有一个众所周知
277295
禁止 EmailAddress、URI subjectAltName 等扩展,并丢弃其他扩展。
278296
至少有一个 DNS 或 IP 的 SubjectAltName 存在。
279297
1. 许可的密钥用途:必须是 `["key encipherment", "digital signature", "client auth"]`
280-
1. 过期日期/证书生命期:通过 kube-controller-manager 中签名者的实现所对应的标志
281-
`--cluster-signing-duration` 来设置
298+
1. 过期时间/证书有效期:对于 kube-controller-manager 实现的签名者,
299+
设置为 `--cluster-signing-duration` 选项和 CSR 对象的 `spec.expirationSeconds` 字段(如有设置该字段)中的最小值
282300
1. 允许/不允许 CA 位:不允许。
283301

284302
<!--
@@ -290,8 +308,8 @@ Kubernetes提供了内置的签名者,每个签名者都有一个众所周知
290308
1. Permitted subjects - any
291309
1. Permitted x509 extensions - honors subjectAltName and key usage extensions and discards other extensions.
292310
1. Permitted key usages - any
293-
1. Expiration/certificate lifetime - set by the `--cluster-signing-duration` option for the
294-
kube-controller-manager implementation of this signer.
311+
1. Expiration/certificate lifetime - for the kube-controller-manager implementation of this signer, set to the minimum
312+
of the `--cluster-signing-duration` option or, if specified, the `spec.expirationSeconds` field of the CSR object.
295313
1. CA bit allowed/disallowed - not allowed.
296314
-->
297315
4. `kubernetes.io/legacy-unknown`: 不保证信任。Kubernetes 的一些第三方发行版可能会使用它签署的客户端证书。
@@ -302,8 +320,8 @@ Kubernetes提供了内置的签名者,每个签名者都有一个众所周知
302320
1. 许可的主体:全部。
303321
1. 许可的 x509 扩展:允许 subjectAltName 和 key usage 等扩展,并弃用其他扩展。
304322
1. 许可的密钥用途:全部。
305-
1. 过期日期/证书生命期:通过 kube-controller-manager 中签名者的实现所对应的标志
306-
`--cluster-signing-duration` 来设置
323+
1. 过期时间/证书有效期:对于 kube-controller-manager 实现的签名者,
324+
设置为 `--cluster-signing-duration` 选项和 CSR 对象的 `spec.expirationSeconds` 字段(如有设置该字段)中的最小值
307325
1. 允许/不允许 CA 位 - 不允许。
308326

309327
{{< note >}}
@@ -313,6 +331,15 @@ Failures for all of these are only reported in kube-controller-manager logs.
313331
注意:所有这些故障仅在 kube-controller-manager 日志中报告。
314332
{{< /note >}}
315333

334+
{{< note >}}
335+
<!--
336+
The `spec.expirationSeconds` field was added in Kubernetes v1.22. Earlier versions of Kubernetes do not honor this field.
337+
Kubernetes API servers prior to v1.22 will silently drop this field when the object is created.
338+
-->
339+
`spec.expirationSeconds` 字段是在 Kubernetes v1.22 中加入的。早期的 Kubernetes 版本并不认识该字段。
340+
v1.22 版本之前的 Kubernetes API 服务器会在创建对象的时候忽略该字段。
341+
{{< /note >}}
342+
316343
<!--
317344
Distribution of trust happens out of band for these signers. Any trust outside of those described above are strictly
318345
coincidental. For instance, some distributions may honor `kubernetes.io/legacy-unknown` as client certificates for the
@@ -399,15 +426,14 @@ To allow signing a CertificateSigningRequest:
399426
## Normal User
400427
401428
A few steps are required in order to get a normal user to be able to
402-
authenticate and invoke an API. First, this user must have certificate issued
403-
by the Kubernetes cluster, and then present that Certificate to the API call
404-
as the Certificate Header or through the kubectl.
429+
authenticate and invoke an API. First, this user must have a certificate issued
430+
by the Kubernetes cluster, and then present that certificate to the Kubernetes API.
405431
-->
406432
## 普通用户 {#normal-user}
407433

408434
为了让普通用户能够通过认证并调用 API,需要执行几个步骤。
409435
首先,该用户必须拥有 Kubernetes 集群签发的证书,
410-
然后将该证书作为 API 调用的 Certificate 头或通过 kubectl 提供
436+
然后将该证书提供给 Kubernetes API
411437

412438
<!--
413439
### Create private key
@@ -446,10 +472,9 @@ kind: CertificateSigningRequest
446472
metadata:
447473
name: myuser
448474
spec:
449-
groups:
450-
- system:authenticated
451475
request: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURSBSRVFVRVNULS0tLS0KTUlJQ1ZqQ0NBVDRDQVFBd0VURVBNQTBHQTFVRUF3d0dZVzVuWld4aE1JSUJJakFOQmdrcWhraUc5dzBCQVFFRgpBQU9DQVE4QU1JSUJDZ0tDQVFFQTByczhJTHRHdTYxakx2dHhWTTJSVlRWMDNHWlJTWWw0dWluVWo4RElaWjBOCnR2MUZtRVFSd3VoaUZsOFEzcWl0Qm0wMUFSMkNJVXBGd2ZzSjZ4MXF3ckJzVkhZbGlBNVhwRVpZM3ExcGswSDQKM3Z3aGJlK1o2MVNrVHF5SVBYUUwrTWM5T1Nsbm0xb0R2N0NtSkZNMUlMRVI3QTVGZnZKOEdFRjJ6dHBoaUlFMwpub1dtdHNZb3JuT2wzc2lHQ2ZGZzR4Zmd4eW8ybmlneFNVekl1bXNnVm9PM2ttT0x1RVF6cXpkakJ3TFJXbWlECklmMXBMWnoyalVnald4UkhCM1gyWnVVV1d1T09PZnpXM01LaE8ybHEvZi9DdS8wYk83c0x0MCt3U2ZMSU91TFcKcW90blZtRmxMMytqTy82WDNDKzBERHk5aUtwbXJjVDBnWGZLemE1dHJRSURBUUFCb0FBd0RRWUpLb1pJaHZjTgpBUUVMQlFBRGdnRUJBR05WdmVIOGR4ZzNvK21VeVRkbmFjVmQ1N24zSkExdnZEU1JWREkyQTZ1eXN3ZFp1L1BVCkkwZXpZWFV0RVNnSk1IRmQycVVNMjNuNVJsSXJ3R0xuUXFISUh5VStWWHhsdnZsRnpNOVpEWllSTmU3QlJvYXgKQVlEdUI5STZXT3FYbkFvczFqRmxNUG5NbFpqdU5kSGxpT1BjTU1oNndLaTZzZFhpVStHYTJ2RUVLY01jSVUyRgpvU2djUWdMYTk0aEpacGk3ZnNMdm1OQUxoT045UHdNMGM1dVJVejV4T0dGMUtCbWRSeEgvbUNOS2JKYjFRQm1HCkkwYitEUEdaTktXTU0xMzhIQXdoV0tkNjVoVHdYOWl4V3ZHMkh4TG1WQzg0L1BHT0tWQW9FNkpsYWFHdTlQVmkKdjlOSjVaZlZrcXdCd0hKbzZXdk9xVlA3SVFjZmg3d0drWm89Ci0tLS0tRU5EIENFUlRJRklDQVRFIFJFUVVFU1QtLS0tLQo=
452476
signerName: kubernetes.io/kube-apiserver-client
477+
expirationSeconds: 86400 # one day
453478
usages:
454479
- client auth
455480
EOF
@@ -459,12 +484,14 @@ EOF
459484
Some points to note:
460485
461486
- `usages` has to be '`client auth`'
487+
- `expirationSeconds` could be made longer (i.e. `864000` for ten days) or shorter (i.e. `3600` for one hour)
462488
- `request` is the base64 encoded value of the CSR file content.
463489
You can get the content using this command: ```cat myuser.csr | base64 | tr -d "\n"```
464490
-->
465491
需要注意的几点:
466492

467493
- `usage` 字段必须是 '`client auth`'
494+
- `expirationSeconds` 可以设置为更长(例如 `864000` 是十天)或者更短(例如 `3600` 是一个小时)
468495
- `request` 字段是 CSR 文件内容的 base64 编码值。
469496
要得到该值,可以执行命令 `cat myuser.csr | base64 | tr -d "\n"`
470497

@@ -522,19 +549,19 @@ kubectl get csr myuser -o jsonpath='{.status.certificate}'| base64 -d > myuser.c
522549
```
523550

524551
<!--
525-
### Create Role and Role Binding
552+
### Create Role and RoleBinding
526553
527-
With the certificate created. it is time to define the Role and RoleBinding for
554+
With the certificate created it is time to define the Role and RoleBinding for
528555
this user to access Kubernetes cluster resources.
529556
530-
This is a sample script to create Role for this new user
557+
This is a sample command to create a Role for this new user:
531558
-->
532559
### 创建角色和角色绑定 {#create-role-and-role-binding}
533560

534561
创建了证书之后,为了让这个用户能访问 Kubernetes 集群资源,现在就要创建
535562
Role 和 RoleBinding 了。
536563

537-
下面是为这个新用户创建 Role 的示例脚本
564+
下面是为这个新用户创建 Role 的示例命令
538565

539566
```shell
540567
kubectl create role developer --verb=create --verb=get --verb=list --verb=update --verb=delete --resource=pods
@@ -725,6 +752,15 @@ Kubernetes 控制平面实现了每一个
725752
kube-controller-manager 签名所有标记为 approved 的 CSR。
726753
{{< /note >}}
727754

755+
{{< note >}}
756+
<!--
757+
The `spec.expirationSeconds` field was added in Kubernetes v1.22. Earlier versions of Kubernetes do not honor this field.
758+
Kubernetes API servers prior to v1.22 will silently drop this field when the object is created.
759+
-->
760+
`spec.expirationSeconds` 字段是在 Kubernetes v1.22 中加入的。早期的 Kubernetes 版本并不认识该字段。
761+
v1.22 版本之前的 Kubernetes API 服务器会在创建对象的时候忽略该字段。
762+
{{< /note >}}
763+
728764
<!--
729765
### API-based signers {#signer-api}
730766

0 commit comments

Comments
 (0)