Skip to content

Commit 052fb8a

Browse files
committed
Improve explanation of client cert authn
The commit makes a minimal number of less related changes, to ensure that the page still makes sense.
1 parent a2ed1db commit 052fb8a

File tree

1 file changed

+79
-21
lines changed

1 file changed

+79
-21
lines changed

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

Lines changed: 79 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -138,38 +138,81 @@ are available; for example using an [authenticating proxy](#authenticating-proxy
138138

139139
### X.509 client certificates {#x509-client-certificates}
140140

141-
Client certificate authentication is enabled by passing the `--client-ca-file=SOMEFILE`
142-
option to API server. The referenced file must contain one or more certificate authorities
143-
to use to validate client certificates presented to the API server. If a client certificate
144-
is presented and verified, the common name of the subject is used as the user name for the
145-
request. As of Kubernetes 1.4, client certificates can also indicate a user's group memberships
141+
Any Kubernetes client that presents a valid client certificate signed by the cluster's
142+
_client trust_ certificate authority (CA) is considered authenticated. In this configuration, Kubernetes determines
143+
the username from the `commonName` field in the _subject_ of the certificate
144+
(for example, `commonName=bob` represents a user with username "bob").
145+
From there, Kubernetes [authorization](/docs/reference/access-authn-authz/authorization)
146+
mechanisms determine whether the user is allowed to perform a specific operation on a resource.
147+
148+
Client certificate authentication is enabled by passing the `--client-ca-file=<SOMEFILE>`
149+
option to the API server.
150+
This option configures the cluster's _client trust_ certificate authority.
151+
The referenced file must contain one or more certificate authorities that
152+
the API server can use, when it needs to validate client certificates.
153+
If a client certificate is presented and verified, the common name of the subject is used as
154+
the user name for the request. Client certificates can also indicate a user's group memberships
146155
using the certificate's organization fields. To include multiple group memberships for a user,
147156
include multiple organization fields in the certificate.
148157

149-
For example, using the `openssl` command line tool to generate a certificate signing request:
158+
See [Managing Certificates](/docs/tasks/administer-cluster/certificates/) for how to generate a client cert, or read the brief [example](#x509-client-certificates-example) later in this page.
150159

151-
```bash
152-
openssl req -new -key jbeda.pem -out jbeda-csr.pem -subj "/CN=jbeda/O=app1/O=app2"
153-
```
160+
#### Kubernetes-compatible client certificates {#x509-client-certificates-k8s}
154161

155-
This would create a CSR for the username "jbeda", belonging to two groups, "app1" and "app2".
162+
You can present a valid certificate, issued with a trust chain that the API server accepts
163+
for client certificates, and use that to authenticate to Kubernetes.
164+
The certificate must be valid; the API server checks that based on the X.509 `notBefore` and `notAfter` attributes.
156165

157-
See [Managing Certificates](/docs/tasks/administer-cluster/certificates/) for how to generate a client cert.
166+
{{< note >}}
167+
Kubernetes {{< skew currentVersion >}} does not support certificate _revocation_.
168+
Any certificate that is issued remains valid until it expires.
169+
{{< /note >}}
158170

159-
#### Putting a bearer token in a request
171+
##### Username mapping {#x509-client-certificates-k8s-username}
160172

161-
When using bearer token authentication from an http client, the API
162-
server expects an `Authorization` header with a value of `Bearer
163-
<token>`. The bearer token must be a character sequence that can be
164-
put in an HTTP header value using no more than the encoding and
165-
quoting facilities of HTTP. For example: if the bearer token is
166-
`31ada4fd-adec-460c-809a-9e56ceb75269` then it would appear in an HTTP
167-
header as shown below.
173+
Kubernetes expects a client certificates with a subject that contains a `commonName` attribute,
174+
and does not use any other certificate attributes to identity the subject.
175+
The API server maps the `commonName` (OID `2.5.4.3`) field to the client's username.
168176

169-
```http
170-
Authorization: Bearer 31ada4fd-adec-460c-809a-9e56ceb75269
177+
Here is an example to explain what that means. If you have a certificate with the common name
178+
set to "Ada Lovelace" and the certificate also had a `uid` attribute, (OID `0.9.2342.19200300.100.1.1`)
179+
with uid set to "aaking1815", Kubernetes considers that the client's username is "Ada Lovelace";
180+
Kubernetes ignores the `uid` attribute.
181+
182+
##### Group mapping {#x509-client-certificates-k8s-group}
183+
184+
You can map a user into groups by statically including group information into
185+
the certificate. For each group that the user is a member of, add the group
186+
name as an organization (OID `2.5.6.4`) in your certificate's subject.
187+
To include multiple group memberships for a user, include multiple organizations in the certificate subject
188+
(the order does not matter).
189+
For the example user, the distinguished name for a certificate might be
190+
CN=Ada&nbsp;Lovelace,O=Users,O=Staff,O=Programmers, which would place her into the groups
191+
"Programmers", "Staff", "system:authenticated", and "Users".
192+
193+
##### Node client certificates {#x509-client-certificates-nodes}
194+
195+
Kubernetes can use the same approach for node identity; nodes are clients of the Kubernetes API server
196+
(also, although less relevant here, the API server is usually also a client of each node).
197+
For example: a Node "server-1a-antartica42", with the domain name "server-1a-antartica42.cluster.example", could use a certificate issued to "CN=system:node:server-1a-antartica42,O=system:nodes". The node's username is then "system:node:server-1a-antartica42", and the node is a member of "system:authenticated" and "system:nodes".
198+
199+
{{< note >}}
200+
Machine identities for nodes are not the same as
201+
{{< glossary_tooltip text="ServiceAccounts" term_id="service-account" >}}.
202+
{{< /note >}}
203+
204+
#### Example {#x509-client-certificates-example}
205+
206+
You could use the `openssl` command line tool to generate a certificate signing request:
207+
208+
```bash
209+
# This example assumes that you already have a private key alovelace.pem
210+
openssl req -new -key alovelace.pem -out alovelace-csr.pem -subj "/CN=alovelace/O=app1/O=app2"
171211
```
172212

213+
This would create a signing request for the username "alovelace", belonging to two groups, "app1" and "app2". You could then use that signing request to obtain
214+
a certificate.
215+
173216
### Bootstrap tokens
174217

175218
{{< feature-state for_k8s_version="v1.18" state="stable" >}}
@@ -206,6 +249,21 @@ Please see [Bootstrap Tokens](/docs/reference/access-authn-authz/bootstrap-token
206249
documentation on the Bootstrap Token authenticator and controllers along with
207250
how to manage these tokens with `kubeadm`.
208251

252+
#### Putting a bearer token in a request
253+
254+
When using bearer token authentication from an http client, the API
255+
server expects an `Authorization` header with a value of `Bearer
256+
<token>`. The bearer token must be a character sequence that can be
257+
put in an HTTP header value using no more than the encoding and
258+
quoting facilities of HTTP. For example: if the bearer token is
259+
`31ada4fd-adec-460c-809a-9e56ceb75269` then it would appear in an HTTP
260+
header as shown below.
261+
262+
```http
263+
Authorization: Bearer 31ada4fd-adec-460c-809a-9e56ceb75269
264+
```
265+
266+
209267
### Service account tokens
210268

211269
A service account is an automatically enabled authenticator that uses signed

0 commit comments

Comments
 (0)