Skip to content

Commit 59f1e29

Browse files
authored
Merge pull request #49507 from windsonsea/accadm
Clean up service-accounts-admin.md
2 parents 6286069 + a214e10 commit 59f1e29

File tree

1 file changed

+81
-72
lines changed

1 file changed

+81
-72
lines changed

content/en/docs/reference/access-authn-authz/service-accounts-admin.md

Lines changed: 81 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -96,69 +96,70 @@ and uid when inspecting a JWT.
9696

9797
### Verifying and inspecting private claims
9898

99-
The `TokenReview` API can be used to verify and extract private claims from a token:
99+
The TokenReview API can be used to verify and extract private claims from a token:
100100

101101
1. First, assume you have a pod named `test-pod` and a service account named `my-sa`.
102-
2. Create a token that is bound to this Pod:
103-
104-
```shell
105-
kubectl create token my-sa --bound-object-kind="Pod" --bound-object-name="test-pod"
106-
```
107-
108-
3. Copy this token into a new file named `tokenreview.yaml`:
109-
110-
```yaml
111-
apiVersion: authentication.k8s.io/v1
112-
kind: TokenReview
113-
spec:
114-
token: <token from step 2>
115-
```
116-
117-
4. Submit this resource to the apiserver for review:
118-
119-
```shell
120-
kubectl create -o yaml -f tokenreview.yaml # we use '-o yaml' so we can inspect the output
121-
```
122-
123-
You should see an output like below:
124-
125-
```yaml
126-
apiVersion: authentication.k8s.io/v1
127-
kind: TokenReview
128-
metadata:
129-
creationTimestamp: null
130-
spec:
131-
token: <token>
132-
status:
133-
audiences:
134-
- https://kubernetes.default.svc.cluster.local
135-
authenticated: true
136-
user:
137-
extra:
138-
authentication.kubernetes.io/credential-id:
139-
- JTI=7ee52be0-9045-4653-aa5e-0da57b8dccdc
140-
authentication.kubernetes.io/node-name:
141-
- kind-control-plane
142-
authentication.kubernetes.io/node-uid:
143-
- 497e9d9a-47aa-4930-b0f6-9f2fb574c8c6
144-
authentication.kubernetes.io/pod-name:
145-
- test-pod
146-
authentication.kubernetes.io/pod-uid:
147-
- e87dbbd6-3d7e-45db-aafb-72b24627dff5
148-
groups:
149-
- system:serviceaccounts
150-
- system:serviceaccounts:default
151-
- system:authenticated
152-
uid: f8b4161b-2e2b-11e9-86b7-2afc33b31a7e
153-
username: system:serviceaccount:default:my-sa
154-
```
155-
156-
{{< note >}}
157-
Despite using `kubectl create -f` to create this resource, and defining it similar to
158-
other resource types in Kubernetes, TokenReview is a special type and the kube-apiserver
159-
does not actually persist the TokenReview object into etcd.
160-
Hence `kubectl get tokenreview` is not a valid command.
161-
{{< /note >}}
102+
1. Create a token that is bound to this Pod:
103+
104+
```shell
105+
kubectl create token my-sa --bound-object-kind="Pod" --bound-object-name="test-pod"
106+
```
107+
108+
1. Copy this token into a new file named `tokenreview.yaml`:
109+
110+
```yaml
111+
apiVersion: authentication.k8s.io/v1
112+
kind: TokenReview
113+
spec:
114+
token: <token from step 2>
115+
```
116+
117+
1. Submit this resource to the apiserver for review:
118+
119+
```shell
120+
# use '-o yaml' to inspect the output
121+
kubectl create -o yaml -f tokenreview.yaml
122+
```
123+
124+
You should see an output like below:
125+
126+
```yaml
127+
apiVersion: authentication.k8s.io/v1
128+
kind: TokenReview
129+
metadata:
130+
creationTimestamp: null
131+
spec:
132+
token: <token>
133+
status:
134+
audiences:
135+
- https://kubernetes.default.svc.cluster.local
136+
authenticated: true
137+
user:
138+
extra:
139+
authentication.kubernetes.io/credential-id:
140+
- JTI=7ee52be0-9045-4653-aa5e-0da57b8dccdc
141+
authentication.kubernetes.io/node-name:
142+
- kind-control-plane
143+
authentication.kubernetes.io/node-uid:
144+
- 497e9d9a-47aa-4930-b0f6-9f2fb574c8c6
145+
authentication.kubernetes.io/pod-name:
146+
- test-pod
147+
authentication.kubernetes.io/pod-uid:
148+
- e87dbbd6-3d7e-45db-aafb-72b24627dff5
149+
groups:
150+
- system:serviceaccounts
151+
- system:serviceaccounts:default
152+
- system:authenticated
153+
uid: f8b4161b-2e2b-11e9-86b7-2afc33b31a7e
154+
username: system:serviceaccount:default:my-sa
155+
```
156+
157+
{{< note >}}
158+
Despite using `kubectl create -f` to create this resource, and defining it similar to
159+
other resource types in Kubernetes, TokenReview is a special type and the kube-apiserver
160+
does not actually persist the TokenReview object into etcd.
161+
Hence `kubectl get tokenreview` is not a valid command.
162+
{{< /note >}}
162163

163164
#### Schema for service account private claims
164165

@@ -229,7 +230,7 @@ For more information on JWTs and their structure, see the [JSON Web Token RFC](h
229230
{{< feature-state feature_gate_name="BoundServiceAccountTokenVolume" >}}
230231

231232
By default, the Kubernetes control plane (specifically, the
232-
[ServiceAccount admission controller](#serviceaccount-admission-controller))
233+
[ServiceAccount admission controller](#serviceaccount-admission-controller))
233234
adds a [projected volume](/docs/concepts/storage/projected-volumes/) to Pods,
234235
and this volume includes a token for Kubernetes API access.
235236

@@ -292,9 +293,11 @@ and are mounted into Pods using a projected volume.
292293
The tokens obtained using this method have bounded lifetimes, and are automatically
293294
invalidated when the Pod they are mounted into is deleted.
294295

295-
You can still [manually create](/docs/tasks/configure-pod-container/configure-service-account/#manually-create-an-api-token-for-a-serviceaccount) a Secret to hold a service account token; for example, if you need a token that never expires.
296+
You can still [manually create](/docs/tasks/configure-pod-container/configure-service-account/#manually-create-an-api-token-for-a-serviceaccount)
297+
a Secret to hold a service account token; for example, if you need a token that never expires.
296298

297-
Once you manually create a Secret and link it to a ServiceAccount, the Kubernetes control plane automatically populates the token into that Secret.
299+
Once you manually create a Secret and link it to a ServiceAccount,
300+
the Kubernetes control plane automatically populates the token into that Secret.
298301

299302
{{< note >}}
300303
Although the manual mechanism for creating a long-lived ServiceAccount token exists,
@@ -318,7 +321,7 @@ metadata:
318321
name: build-robot
319322
namespace: default
320323
secrets:
321-
- name: build-robot-secret # usually NOT present for a manually generated token
324+
- name: build-robot-secret # usually NOT present for a manually generated token
322325
```
323326

324327
Beginning from version 1.29, legacy ServiceAccount tokens that were generated
@@ -387,7 +390,7 @@ verify the tokens during authentication.
387390
{{< feature-state feature_gate_name="ExternalServiceAccountTokenSigner" >}}
388391

389392
An alternate setup to setting `--service-account-private-key-file` and `--service-account-key-file` flags is
390-
to configure an external JWT signer for [external ServiceAccount token signing and key management](#external-serviceaccount-token-signing-and-key-management).
393+
to configure an external JWT signer for [external ServiceAccount token signing and key management](#external-serviceaccount-token-signing-and-key-management).
391394
Note that these setups are mutually exclusive and cannot be configured together.
392395

393396
### ServiceAccount admission controller
@@ -512,7 +515,7 @@ That manifest snippet defines a projected volume that combines information from
512515
either when the pod is deleted or after a defined lifespan (by default, that is 1 hour).
513516
The token is bound to the specific Pod and has the kube-apiserver as its audience.
514517
1. A `configMap` source. The ConfigMap contains a bundle of certificate authority data. Pods can use these
515-
certificates to make sure that they are connecting to your cluster's kube-apiserver (and not to middlebox
518+
certificates to make sure that they are connecting to your cluster's kube-apiserver (and not to a middlebox
516519
or an accidentally misconfigured peer).
517520
1. A `downwardAPI` source. This `downwardAPI` volume makes the name of the namespace containing the Pod available
518521
to application code running inside the Pod.
@@ -620,15 +623,21 @@ kubectl -n examplens delete secret/example-automated-thing-token-zyxwv
620623
{{< feature-state feature_gate_name="ExternalServiceAccountTokenSigner" >}}
621624

622625
The kube-apiserver can be configured to use external signer for token signing and token verifying key management.
623-
This feature enables kubernetes distributions to integrate with key management solutions of their choice (eg: HSMs, cloud KMSes) for service account credential signing and verification.
624-
To configure kube-apiserver to use external-jwt-signer set the `--service-account-signing-endpoint` flag to the location of a Unix domain socket (UDS) on a filesystem, or be prefixed with an @ symbol and name a UDS in the abstract socket namespace.
625-
At the configured UDS, shall be an RPC server which implements [ExternalJWTSigner](https://github.com/kubernetes/kubernetes/blob/release-1.32/staging/src/k8s.io/externaljwt/apis/v1alpha1/api.proto).
626+
This feature enables kubernetes distributions to integrate with key management solutions of their choice
627+
(for example, HSMs, cloud KMSes) for service account credential signing and verification.
628+
To configure kube-apiserver to use external-jwt-signer set the `--service-account-signing-endpoint` flag
629+
to the location of a Unix domain socket (UDS) on a filesystem, or be prefixed with an @ symbol and name
630+
a UDS in the abstract socket namespace. At the configured UDS, shall be an RPC server which implements
631+
[ExternalJWTSigner](https://github.com/kubernetes/kubernetes/blob/release-1.32/staging/src/k8s.io/externaljwt/apis/v1alpha1/api.proto).
626632
The external-jwt-signer must be healthy and be ready to serve supported service account keys for the kube-apiserver to start.
627633

628-
Check out [KEP-740](https://github.com/kubernetes/enhancements/tree/master/keps/sig-auth/740-service-account-external-signing) for more details on ExternalJWTSigner.
634+
Check out [KEP-740](https://github.com/kubernetes/enhancements/tree/master/keps/sig-auth/740-service-account-external-signing)
635+
for more details on ExternalJWTSigner.
629636

630637
{{< note >}}
631-
The kube-apiserver flags `--service-account-key-file` and `--service-account-signing-key-file` will continue to be used for reading from files unless `--service-account-signing-endpoint` is set; they are mutually exclusive ways of supporting JWT signing and authentication.
638+
The kube-apiserver flags `--service-account-key-file` and `--service-account-signing-key-file` will continue
639+
to be used for reading from files unless `--service-account-signing-endpoint` is set; they are mutually
640+
exclusive ways of supporting JWT signing and authentication.
632641
{{< /note >}}
633642

634643
## Clean up

0 commit comments

Comments
 (0)