@@ -29,13 +29,18 @@ these certificates will validate against the cluster root CA.
29
29
## {{% heading "prerequisites" %}}
30
30
31
31
32
- {{< include "task-tutorial-prereqs.md" >}} {{< version-check >}}
32
+ {{< include "task-tutorial-prereqs.md" >}}
33
33
34
+ You need the ` cfssl ` tool. You can download ` cfssl ` from
35
+ [ https://github.com/cloudflare/cfssl/releases ] ( https://github.com/cloudflare/cfssl/releases ) .
34
36
37
+ Some steps in this page use the ` jq ` tool. If you don't have ` jq ` , you can
38
+ install it via your operating system's software sources, or fetch it from
39
+ [ https://stedolan.github.io/jq/ ] ( https://stedolan.github.io/jq/ ) .
35
40
36
41
<!-- steps -->
37
42
38
- ## Trusting TLS in a Cluster
43
+ ## Trusting TLS in a cluster
39
44
40
45
Trusting the custom CA from an application running as a pod usually requires
41
46
some extra application configuration. You will need to add the CA certificate
@@ -48,7 +53,7 @@ You can distribute the CA certificate as a
48
53
[ ConfigMap] ( /docs/tasks/configure-pod-container/configure-pod-configmap ) that your
49
54
pods have access to use.
50
55
51
- ## Requesting a Certificate
56
+ ## Requesting a certificate
52
57
53
58
The following section demonstrates how to create a TLS certificate for a
54
59
Kubernetes service accessed through DNS.
@@ -57,12 +62,7 @@ Kubernetes service accessed through DNS.
57
62
This tutorial uses CFSSL: Cloudflare's PKI and TLS toolkit [ click here] ( https://blog.cloudflare.com/introducing-cfssl/ ) to know more.
58
63
{{< /note >}}
59
64
60
- ## Download and install CFSSL
61
-
62
- The cfssl tools used in this example can be downloaded at
63
- [ https://github.com/cloudflare/cfssl/releases ] ( https://github.com/cloudflare/cfssl/releases ) .
64
-
65
- ## Create a Certificate Signing Request
65
+ ## Create a certificate signing request
66
66
67
67
Generate a private key and certificate signing request (or CSR) by running
68
68
the following command:
@@ -98,14 +98,14 @@ is the pod's DNS name. You should see the output similar to:
98
98
```
99
99
100
100
This command generates two files; it generates ` server.csr ` containing the PEM
101
- encoded [ pkcs #10 ] ( https://tools.ietf.org/html/rfc2986 ) certification request,
101
+ encoded [ PKCS #10 ] ( https://tools.ietf.org/html/rfc2986 ) certification request,
102
102
and ` server-key.pem ` containing the PEM encoded key to the certificate that
103
103
is still to be created.
104
104
105
- ## Create a Certificate Signing Request object to send to the Kubernetes API
105
+ ## Create a CertificateSigningRequest object to send to the Kubernetes API
106
106
107
- Generate a CSR yaml blob and send it to the apiserver by running the following
108
- command:
107
+ Generate a CSR manifest (in YAML), and send it to the API server. You can do that by
108
+ running the following command:
109
109
110
110
``` shell
111
111
cat << EOF | kubectl apply -f -
124
124
```
125
125
126
126
Notice that the ` server.csr ` file created in step 1 is base64 encoded
127
- and stashed in the ` .spec.request ` field. We are also requesting a
127
+ and stashed in the ` .spec.request ` field. You are also requesting a
128
128
certificate with the "digital signature", "key encipherment", and "server
129
129
auth" key usages, signed by an example ` example.com/serving ` signer.
130
130
A specific ` signerName ` must be requested.
@@ -157,7 +157,7 @@ Subject Alternative Names:
157
157
Events: <none>
158
158
```
159
159
160
- ## Get the Certificate Signing Request Approved
160
+ ## Get the CertificateSigningRequest approved {#get-the-certificate-signing-request-approved}
161
161
162
162
Approving the [ certificate signing request] ( /docs/reference/access-authn-authz/certificate-signing-requests/ )
163
163
is either done by an automated approval process or on a one off basis by a cluster
@@ -186,16 +186,18 @@ my-svc.my-namespace 10m example.com/serving
[email protected] <none>
186
186
This means the certificate request has been approved and is waiting for the
187
187
requested signer to sign it.
188
188
189
- ## Sign the Certificate Signing Request
189
+ ## Sign the CertificateSigningRequest {#sign-the-certificate-signing-request}
190
190
191
191
Next, you'll play the part of a certificate signer, issue the certificate, and upload it to the API.
192
192
193
- A signer would typically watch the Certificate Signing Request API for objects with its ` signerName ` ,
194
- check that they have been approved, sign certificates for those requests,
193
+ A signer would typically watch the CertificateSigningRequest API for objects with its ` signerName ` ,
194
+ check that they have been approved, sign certificates for those requests,
195
195
and update the API object status with the issued certificate.
196
196
197
197
### Create a Certificate Authority
198
198
199
+ You need an authority to provide the digital signature on the new certificate.
200
+
199
201
First, create a signing certificate by running the following:
200
202
201
203
``` shell
@@ -210,7 +212,7 @@ cat <<EOF | cfssl gencert -initca - | cfssljson -bare ca
210
212
EOF
211
213
```
212
214
213
- You should see the output similar to:
215
+ You should see output similar to:
214
216
215
217
``` none
216
218
2022/02/01 11:50:39 [INFO] generating a new CA key and certificate from CSR
@@ -223,7 +225,7 @@ You should see the output similar to:
223
225
224
226
This produces a certificate authority key file (` ca-key.pem ` ) and certificate (` ca.pem ` ).
225
227
226
- ### Issue a Certificate
228
+ ### Issue a certificate
227
229
228
230
{{< codenew file="tls/server-signing-config.json" >}}
229
231
@@ -245,7 +247,7 @@ You should see the output similar to:
245
247
246
248
This produces a signed serving certificate file, ` ca-signed-server.pem ` .
247
249
248
- ### Upload the Signed Certificate
250
+ ### Upload the signed certificate
249
251
250
252
Finally, populate the signed certificate in the API object's status:
251
253
@@ -256,62 +258,76 @@ kubectl get csr my-svc.my-namespace -o json | \
256
258
```
257
259
258
260
{{< note >}}
259
- This uses the command line tool [ jq] ( https://stedolan.github.io/jq/ ) to populate the base64-encoded content in the ` .status.certificate ` field.
260
- If you do not have ` jq ` , you can also save the JSON output to a file, populate this field manually, and upload the resulting file.
261
+ This uses the command line tool [ ` jq ` ] ( https://stedolan.github.io/jq/ ) to populate the base64-encoded
262
+ content in the ` .status.certificate ` field.
263
+ If you do not have ` jq ` , you can also save the JSON output to a file, populate this field manually, and
264
+ upload the resulting file.
261
265
{{< /note >}}
262
266
263
- Once the CSR is approved and the signed certificate is uploaded you should see the following :
267
+ Once the CSR is approved and the signed certificate is uploaded, run :
264
268
265
269
``` shell
266
270
kubectl get csr
267
271
```
268
272
273
+ The output is similar to:
269
274
``` none
270
275
NAME AGE SIGNERNAME REQUESTOR REQUESTEDDURATION CONDITION
271
276
my-svc.my-namespace 20m example.com/serving [email protected] <none> Approved,Issued
272
277
```
273
278
274
- ## Download the Certificate and Use It
279
+ ## Download the certificate and use it
275
280
276
- Now, as the requesting user, you can download the issued certificate
281
+ Now, as the requesting user, you can download the issued certificate
277
282
and save it to a ` server.crt ` file by running the following:
278
283
279
284
``` shell
280
285
kubectl get csr my-svc.my-namespace -o jsonpath=' {.status.certificate}' \
281
286
| base64 --decode > server.crt
282
287
```
283
288
284
- Now you can populate ` server.crt ` and ` server-key.pem ` in a secret and mount
285
- it into a pod to use as the keypair to start your HTTPS server:
289
+ Now you can populate ` server.crt ` and ` server-key.pem ` in a
290
+ {{< glossary_tooltip text="Secret" term_id="secret" >}}
291
+ that you could later mount into a Pod (for example, to use with a webserver
292
+ that serves HTTPS).
286
293
287
294
``` shell
288
- kubectl create secret tls server --cert server.crt --key server-key.pem
295
+ kubectl create secret tls server --cert server.crt --key server-key.pem
289
296
```
290
297
291
298
``` none
292
299
secret/server created
293
300
```
294
301
295
- Finally, you can populate ` ca.pem ` in a configmap and use it as the trust root
296
- to verify the serving certificate:
302
+ Finally, you can populate ` ca.pem ` into a {< glossary_tooltip text="ConfigMap" term_id="configmap" >}}
303
+ and use it as the trust root to verify the serving certificate:
297
304
298
305
``` shell
299
- kubectl create configmap example-serving-ca --from-file ca.crt=ca.pem
306
+ kubectl create configmap example-serving-ca --from-file ca.crt=ca.pem
300
307
```
301
308
302
309
``` none
303
310
configmap/example-serving-ca created
304
311
```
305
312
306
- ## Approving Certificate Signing Requests
313
+ ## Approving CertificateSigningRequests {#approving-certificate-signing-requests}
307
314
308
315
A Kubernetes administrator (with appropriate permissions) can manually approve
309
- (or deny) Certificate Signing Requests by using the `kubectl certificate
316
+ (or deny) CertificateSigningRequests by using the `kubectl certificate
310
317
approve` and ` kubectl certificate deny` commands. However if you intend
311
318
to make heavy usage of this API, you might consider writing an automated
312
319
certificates controller.
313
320
314
- Whether a machine or a human using kubectl as above, the role of the approver is
321
+ {{< caution >}}
322
+ The ability to approve CSRs decides who trusts whom within your environment. The
323
+ ability to approve CSRs should not be granted broadly or lightly.
324
+
325
+ You should make sure that you confidently understand both the verification requirements
326
+ that fall on the approver ** and** the repercussions of issuing a specific certificate
327
+ before you grant the ` approve ` permission.
328
+ {{< /caution >}}
329
+
330
+ Whether a machine or a human using kubectl as above, the role of the _ approver_ is
315
331
to verify that the CSR satisfies two requirements:
316
332
317
333
1 . The subject of the CSR controls the private key used to sign the CSR. This
@@ -326,20 +342,15 @@ to verify that the CSR satisfies two requirements:
326
342
If and only if these two requirements are met, the approver should approve
327
343
the CSR and otherwise should deny the CSR.
328
344
329
- ## A Word of Warning on the Approval Permission
345
+ For more information on certificate approval and access control, read
346
+ the [ Certificate Signing Requests] ( /docs/reference/access-authn-authz/certificate-signing-requests/ )
347
+ reference page.
330
348
331
- The ability to approve CSRs decides who trusts whom within your environment. The
332
- ability to approve CSRs should not be granted broadly or lightly. The
333
- requirements of the challenge noted in the previous section and the
334
- repercussions of issuing a specific certificate should be fully understood
335
- before granting this permission.
336
-
337
- ## A Note to Cluster Administrators
349
+ ## Configuring your cluster to provide signing
338
350
339
- This tutorial assumes that a signer is setup to serve the certificates API. The
351
+ This page assumes that a signer is setup to serve the certificates API. The
340
352
Kubernetes controller manager provides a default implementation of a signer. To
341
353
enable it, pass the ` --cluster-signing-cert-file ` and
342
354
` --cluster-signing-key-file ` parameters to the controller manager with paths to
343
355
your Certificate Authority's keypair.
344
356
345
-
0 commit comments