@@ -8,6 +8,7 @@ reviewers:
8
8
- liggitt
9
9
- mikedanese
10
10
- munnerz
11
+ - enj
11
12
title: Certificate Signing Requests
12
13
content_type: concept
13
14
weight: 20
@@ -50,13 +51,18 @@ The CertificateSigningRequest object includes a PEM-encoded PKCS#10 signing requ
50
51
the `spec.request` field. The CertificateSigningRequest denotes the _signer_ (the
51
52
recipient that the request is being made to) using the `spec.signerName` field.
52
53
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.
53
57
-->
54
58
## 请求签名流程 {#request-signing-process}
55
59
56
60
CertificateSigningRequest 资源类型允许客户使用它申请发放 X.509 证书。
57
61
CertificateSigningRequest 对象 在 ` spec.request ` 中包含一个 PEM 编码的 PKCS #10 签名请求。
58
62
CertificateSigningRequest 使用 ` spec.signerName ` 字段标示 _ 签名者_ (请求的接收方)。
59
63
注意,` spec.signerName ` 在 ` certificates.k8s.io/v1 ` 之后的 API 版本是必填项。
64
+ 在 Kubernetes v1.22 和以后的版本,客户可以可选地设置 ` spec.expirationSeconds `
65
+ 字段来为颁发的证书设定一个特定的有效期。该字段的最小有效值是 ` 600 ` ,也就是 10 分钟。
60
66
61
67
<!--
62
68
Once created, a CertificateSigningRequest must be approved before it can be signed.
@@ -113,15 +119,19 @@ state for some duration:
113
119
114
120
* Approved requests: automatically deleted after 1 hour
115
121
* 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
117
125
-->
118
126
为了减少集群中遗留的过时的 CertificateSigningRequest 资源的数量,
119
127
一个垃圾收集控制器将会周期性地运行。
120
128
此垃圾收集器会清除在一段时间内没有改变过状态的 CertificateSigningRequests:
121
129
122
130
* 已批准的请求:1小时后自动删除
123
131
* 已拒绝的请求:1小时后自动删除
124
- * 挂起的请求:1小时后自动删除
132
+ * 已失败的请求:1小时后自动删除
133
+ * 挂起的请求:24小时后自动删除
134
+ * 所有请求:在颁发的证书过期后自动删除
125
135
126
136
<!--
127
137
## Signers
@@ -146,10 +156,8 @@ This includes:
146
156
and behavior when a disallowed extension is requested.
147
157
4. **Permitted key usages / extended key usages**: any restrictions on and behavior
148
158
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.
153
161
6. **CA bit allowed/disallowed**: and behavior if a CSR contains a request
154
162
a for a CA certificate when the signer does not permit it.
155
163
-->
@@ -159,8 +167,8 @@ This includes:
159
167
Email subjectAltNames、URI subjectAltNames 等,请求一个受限制的扩展项时的应对手段。
160
168
4 . ** 许可的密钥用途/扩展的密钥用途** :当用途和签名者在 CSR 中指定的用途不同时,
161
169
相应的限制和应对手段。
162
- 5 . ** 过期时间/证书有效期** :过期时间由签名者确定、由管理员配置, 还是由 CSR 对象指定等 ,
163
- 以及过期时间与签名者在 CSR 中指定过期时间不同时的应对手段 。
170
+ 5 . ** 过期时间/证书有效期** :过期时间由签名者确定、由管理员配置、 还是由 CSR ` spec.expirationSeconds ` 字段指定等 ,
171
+ 以及签名者决定的过期时间与 CSR ` spec.expirationSeconds ` 字段不同时的应对手段 。
164
172
6 . ** 允许/不允许 CA 位** :当 CSR 包含一个签名者并不允许的 CA 证书的请求时,相应的应对手段。
165
173
166
174
<!--
@@ -178,21 +186,30 @@ intermediates to be presented during TLS handshakes.
178
186
例如,这是要在 TLS 握手时提供的证书和中继证书。
179
187
180
188
<!--
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 >}}
196
213
197
214
<!--
198
215
### Kubernetes signers
@@ -214,8 +231,8 @@ Kubernetes提供了内置的签名者,每个签名者都有一个众所周知
214
231
but it is often not the only cluster-admin subject in a cluster.
215
232
1. Permitted x509 extensions - honors subjectAltName and key usage extensions and discards other extensions.
216
233
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 .
219
236
1. CA bit allowed/disallowed - not allowed.
220
237
-->
221
238
1 . ` kubernetes.io/kube-apiserver-client ` :签名的证书将被 API 服务器视为客户证书。
@@ -229,8 +246,8 @@ Kubernetes提供了内置的签名者,每个签名者都有一个众所周知
229
246
1 . 许可的 x509 扩展:允许 subjectAltName 和 key usage 扩展,弃用其他扩展。
230
247
1 . 许可的密钥用途:必须包含 ` ["client auth"] ` ,但不能包含
231
248
` ["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 ` 字段(如有设置该字段)中的最小值 。
234
251
1 . 允许/不允许 CA 位:不允许。
235
252
236
253
<!--
@@ -242,8 +259,8 @@ Kubernetes提供了内置的签名者,每个签名者都有一个众所周知
242
259
1. Permitted subjects - organizations are exactly `["system:nodes"]`, common name starts with "`system:node:`".
243
260
1. Permitted x509 extensions - honors key usage extensions, forbids subjectAltName extensions and drops other extensions.
244
261
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 .
247
264
1. CA bit allowed/disallowed - not allowed.
248
265
-->
249
266
2 . ` kubernetes.io/kube-apiserver-client-kubelet ` : 签名的证书将被 kube-apiserver 视为客户证书。
@@ -253,8 +270,8 @@ Kubernetes提供了内置的签名者,每个签名者都有一个众所周知
253
270
1 . 许可的主体:组织名必须是 ` ["system:nodes"] ` ,用户名以 "` system:node: ` " 开头
254
271
1 . 许可的 x509 扩展:允许 key usage 扩展,禁用 subjectAltName 扩展,并删除其他扩展。
255
272
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 ` 字段(如有设置该字段)中的最小值 。
258
275
1 . 允许/不允许 CA 位:不允许。
259
276
260
277
<!--
@@ -266,7 +283,8 @@ Kubernetes提供了内置的签名者,每个签名者都有一个众所周知
266
283
1. Permitted x509 extensions - honors key usage and DNSName/IPAddress subjectAltName extensions, forbids EmailAddress and
267
284
URI subjectAltName extensions, drops other extensions. At least one DNS or IP subjectAltName must be present.
268
285
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.
270
288
1. CA bit allowed/disallowed - not allowed.
271
289
-->
272
290
3 . ` kubernetes.io/kubelet-serving ` : 签名服务证书,该服务证书被 API 服务器视为有效的 kubelet 服务证书,
@@ -277,8 +295,8 @@ Kubernetes提供了内置的签名者,每个签名者都有一个众所周知
277
295
禁止 EmailAddress、URI subjectAltName 等扩展,并丢弃其他扩展。
278
296
至少有一个 DNS 或 IP 的 SubjectAltName 存在。
279
297
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 ` 字段(如有设置该字段)中的最小值 。
282
300
1 . 允许/不允许 CA 位:不允许。
283
301
284
302
<!--
@@ -290,8 +308,8 @@ Kubernetes提供了内置的签名者,每个签名者都有一个众所周知
290
308
1. Permitted subjects - any
291
309
1. Permitted x509 extensions - honors subjectAltName and key usage extensions and discards other extensions.
292
310
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 .
295
313
1. CA bit allowed/disallowed - not allowed.
296
314
-->
297
315
4 . ` kubernetes.io/legacy-unknown ` : 不保证信任。Kubernetes 的一些第三方发行版可能会使用它签署的客户端证书。
@@ -302,8 +320,8 @@ Kubernetes提供了内置的签名者,每个签名者都有一个众所周知
302
320
1 . 许可的主体:全部。
303
321
1 . 许可的 x509 扩展:允许 subjectAltName 和 key usage 等扩展,并弃用其他扩展。
304
322
1 . 许可的密钥用途:全部。
305
- 1 . 过期日期/证书生命期:通过 kube-controller-manager 中签名者的实现所对应的标志
306
- ` --cluster-signing-duration ` 来设置 。
323
+ 1 . 过期时间/证书有效期:对于 kube-controller-manager 实现的签名者,
324
+ 设置为 ` --cluster-signing-duration ` 选项和 CSR 对象的 ` spec.expirationSeconds ` 字段(如有设置该字段)中的最小值 。
307
325
1 . 允许/不允许 CA 位 - 不允许。
308
326
309
327
{{< note >}}
@@ -313,6 +331,15 @@ Failures for all of these are only reported in kube-controller-manager logs.
313
331
注意:所有这些故障仅在 kube-controller-manager 日志中报告。
314
332
{{< /note >}}
315
333
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
+
316
343
<!--
317
344
Distribution of trust happens out of band for these signers. Any trust outside of those described above are strictly
318
345
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:
399
426
## Normal User
400
427
401
428
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.
405
431
-->
406
432
## 普通用户 {#normal-user}
407
433
408
434
为了让普通用户能够通过认证并调用 API,需要执行几个步骤。
409
435
首先,该用户必须拥有 Kubernetes 集群签发的证书,
410
- 然后将该证书作为 API 调用的 Certificate 头或通过 kubectl 提供 。
436
+ 然后将该证书提供给 Kubernetes API 。
411
437
412
438
<!--
413
439
### Create private key
@@ -446,10 +472,9 @@ kind: CertificateSigningRequest
446
472
metadata:
447
473
name: myuser
448
474
spec:
449
- groups:
450
- - system:authenticated
451
475
request: LS0tLS1CRUdJTiBDRVJUSUZJQ0FURSBSRVFVRVNULS0tLS0KTUlJQ1ZqQ0NBVDRDQVFBd0VURVBNQTBHQTFVRUF3d0dZVzVuWld4aE1JSUJJakFOQmdrcWhraUc5dzBCQVFFRgpBQU9DQVE4QU1JSUJDZ0tDQVFFQTByczhJTHRHdTYxakx2dHhWTTJSVlRWMDNHWlJTWWw0dWluVWo4RElaWjBOCnR2MUZtRVFSd3VoaUZsOFEzcWl0Qm0wMUFSMkNJVXBGd2ZzSjZ4MXF3ckJzVkhZbGlBNVhwRVpZM3ExcGswSDQKM3Z3aGJlK1o2MVNrVHF5SVBYUUwrTWM5T1Nsbm0xb0R2N0NtSkZNMUlMRVI3QTVGZnZKOEdFRjJ6dHBoaUlFMwpub1dtdHNZb3JuT2wzc2lHQ2ZGZzR4Zmd4eW8ybmlneFNVekl1bXNnVm9PM2ttT0x1RVF6cXpkakJ3TFJXbWlECklmMXBMWnoyalVnald4UkhCM1gyWnVVV1d1T09PZnpXM01LaE8ybHEvZi9DdS8wYk83c0x0MCt3U2ZMSU91TFcKcW90blZtRmxMMytqTy82WDNDKzBERHk5aUtwbXJjVDBnWGZLemE1dHJRSURBUUFCb0FBd0RRWUpLb1pJaHZjTgpBUUVMQlFBRGdnRUJBR05WdmVIOGR4ZzNvK21VeVRkbmFjVmQ1N24zSkExdnZEU1JWREkyQTZ1eXN3ZFp1L1BVCkkwZXpZWFV0RVNnSk1IRmQycVVNMjNuNVJsSXJ3R0xuUXFISUh5VStWWHhsdnZsRnpNOVpEWllSTmU3QlJvYXgKQVlEdUI5STZXT3FYbkFvczFqRmxNUG5NbFpqdU5kSGxpT1BjTU1oNndLaTZzZFhpVStHYTJ2RUVLY01jSVUyRgpvU2djUWdMYTk0aEpacGk3ZnNMdm1OQUxoT045UHdNMGM1dVJVejV4T0dGMUtCbWRSeEgvbUNOS2JKYjFRQm1HCkkwYitEUEdaTktXTU0xMzhIQXdoV0tkNjVoVHdYOWl4V3ZHMkh4TG1WQzg0L1BHT0tWQW9FNkpsYWFHdTlQVmkKdjlOSjVaZlZrcXdCd0hKbzZXdk9xVlA3SVFjZmg3d0drWm89Ci0tLS0tRU5EIENFUlRJRklDQVRFIFJFUVVFU1QtLS0tLQo=
452
476
signerName: kubernetes.io/kube-apiserver-client
477
+ expirationSeconds: 86400 # one day
453
478
usages:
454
479
- client auth
455
480
EOF
@@ -459,12 +484,14 @@ EOF
459
484
Some points to note:
460
485
461
486
- `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)
462
488
- `request` is the base64 encoded value of the CSR file content.
463
489
You can get the content using this command: ```cat myuser.csr | base64 | tr -d "\n"```
464
490
-->
465
491
需要注意的几点:
466
492
467
493
- ` usage ` 字段必须是 '` client auth ` '
494
+ - ` expirationSeconds ` 可以设置为更长(例如 ` 864000 ` 是十天)或者更短(例如 ` 3600 ` 是一个小时)
468
495
- ` request ` 字段是 CSR 文件内容的 base64 编码值。
469
496
要得到该值,可以执行命令 ` cat myuser.csr | base64 | tr -d "\n" ` 。
470
497
@@ -522,19 +549,19 @@ kubectl get csr myuser -o jsonpath='{.status.certificate}'| base64 -d > myuser.c
522
549
```
523
550
524
551
<!--
525
- ### Create Role and Role Binding
552
+ ### Create Role and RoleBinding
526
553
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
528
555
this user to access Kubernetes cluster resources.
529
556
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:
531
558
-->
532
559
### 创建角色和角色绑定 {#create-role-and-role-binding}
533
560
534
561
创建了证书之后,为了让这个用户能访问 Kubernetes 集群资源,现在就要创建
535
562
Role 和 RoleBinding 了。
536
563
537
- 下面是为这个新用户创建 Role 的示例脚本 :
564
+ 下面是为这个新用户创建 Role 的示例命令 :
538
565
539
566
``` shell
540
567
kubectl create role developer --verb=create --verb=get --verb=list --verb=update --verb=delete --resource=pods
@@ -725,6 +752,15 @@ Kubernetes 控制平面实现了每一个
725
752
kube-controller-manager 签名所有标记为 approved 的 CSR。
726
753
{{< /note >}}
727
754
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
+
728
764
<!--
729
765
# ## API-based signers {#signer-api}
730
766
0 commit comments