Skip to content

Commit 8a3d7ac

Browse files
committed
update doc for BoundServiceAccountTokenVolume
1 parent 4beb4d2 commit 8a3d7ac

File tree

1 file changed

+47
-32
lines changed

1 file changed

+47
-32
lines changed

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

Lines changed: 47 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
---
22
reviewers:
3-
- bprashanth
4-
- davidopp
5-
- lavalamp
6-
- liggitt
3+
- bprashanth
4+
- davidopp
5+
- lavalamp
6+
- liggitt
77
title: Managing Service Accounts
88
content_type: concept
99
weight: 50
1010
---
1111

1212
<!-- overview -->
13+
1314
This is a Cluster Administrator guide to service accounts. You should be familiar with
1415
[configuring Kubernetes service accounts](/docs/tasks/configure-pod-container/configure-service-account/).
1516

16-
Support for authorization and user accounts is planned but incomplete. Sometimes
17+
Support for authorization and user accounts is planned but incomplete. Sometimes
1718
incomplete features are referred to in order to better describe service accounts.
1819

19-
2020
<!-- body -->
21+
2122
## User accounts versus service accounts
2223

2324
Kubernetes distinguishes between the concept of a user account and a service account
@@ -53,37 +54,51 @@ It is part of the API server.
5354
It acts synchronously to modify pods as they are created or updated. When this plugin is active
5455
(and it is by default on most distributions), then it does the following when a pod is created or modified:
5556

56-
1. If the pod does not have a `ServiceAccount` set, it sets the `ServiceAccount` to `default`.
57-
1. It ensures that the `ServiceAccount` referenced by the pod exists, and otherwise rejects it.
58-
1. If the pod does not contain any `ImagePullSecrets`, then `ImagePullSecrets` of the `ServiceAccount` are added to the pod.
59-
1. It adds a `volume` to the pod which contains a token for API access.
60-
1. It adds a `volumeSource` to each container of the pod mounted at `/var/run/secrets/kubernetes.io/serviceaccount`.
57+
1. If the pod does not have a `ServiceAccount` set, it sets the `ServiceAccount` to `default`.
58+
1. It ensures that the `ServiceAccount` referenced by the pod exists, and otherwise rejects it.
59+
1. It adds a `volume` to the pod which contains a token for API access if neither the ServiceAccount `automountServiceAccountToken` nor the Pod's `automountServiceAccountToken` is set to `false`.
60+
1. It adds a `volumeSource` to each container of the pod mounted at `/var/run/secrets/kubernetes.io/serviceaccount`, if the previous step has created a volume for ServiceAccount token.
61+
1. If the pod does not contain any `ImagePullSecrets`, then `ImagePullSecrets` of the `ServiceAccount` are added to the pod.
6162

6263
#### Bound Service Account Token Volume
64+
6365
{{< feature-state for_k8s_version="v1.21" state="beta" >}}
6466

6567
When the `BoundServiceAccountTokenVolume` [feature gate](/docs/reference/command-line-tools-reference/feature-gates/) is enabled, the service account admission controller will
66-
add a projected service account token volume instead of a secret volume. The service account token will expire after 1 hour by default or the pod is deleted. See more details about [projected volume](/docs/tasks/configure-pod-container/configure-projected-volume-storage/).
67-
68-
This feature depends on the `RootCAConfigMap` feature gate enabled which publish a "kube-root-ca.crt" ConfigMap to every namespace. This ConfigMap contains a CA bundle used for verifying connections to the kube-apiserver.
69-
1. If the pod does not have a `serviceAccountName` set, it sets the
70-
`serviceAccountName` to `default`.
71-
1. It ensures that the `serviceAccountName` referenced by the pod exists, and
72-
otherwise rejects it.
73-
1. If the pod does not contain any `imagePullSecrets`, then `imagePullSecrets`
74-
of the ServiceAccount referenced by `serviceAccountName` are added to the pod.
75-
1. It adds a `volume` to the pod which contains a token for API access
76-
if neither the ServiceAccount `automountServiceAccountToken` nor the Pod's
77-
`automountServiceAccountToken` is set to `false`.
78-
1. It adds a `volumeSource` to each container of the pod mounted at
79-
`/var/run/secrets/kubernetes.io/serviceaccount`, if the previous step has
80-
created a volume for ServiceAccount token.
81-
82-
You can migrate a service account volume to a projected volume when
83-
the `BoundServiceAccountTokenVolume` feature gate is enabled.
84-
The service account token will expire after 1 hour or the pod is deleted. See
85-
more details about
86-
[projected volume](/docs/tasks/configure-pod-container/configure-projected-volume-storage/).
68+
add the following projected volume instead of a secret volume for the non-expiring service account token created by Token Controller.
69+
70+
```yaml
71+
- name: kube-api-access-c5cs8
72+
projected:
73+
defaultMode: 420 # 0644
74+
sources:
75+
- serviceAccountToken:
76+
expirationSeconds: 3600
77+
path: token
78+
- configMap:
79+
items:
80+
- key: ca.crt
81+
path: ca.crt
82+
name: kube-root-ca.crt
83+
- downwardAPI:
84+
items:
85+
- fieldRef:
86+
apiVersion: v1
87+
fieldPath: metadata.namespace
88+
path: namespace
89+
```
90+
91+
This projected volume consists of three sources:
92+
93+
1. A ServiceAccountToken acquired from kube-apiserver via TokenRequest API. It will expire after 1 hour by default or the pod is deleted. It is bound to the pod and has kube-apiserver as the audience.
94+
1. A ConfigMap contains a CA bundle used for verifying connections to the kube-apiserver. This feature depends on the `RootCAConfigMap` feature gate enabled which publish a "kube-root-ca.crt" ConfigMap to every namespace.
95+
1. A DownwardAPI that references the namespace of the pod.
96+
97+
See more details about [projected volume](/docs/tasks/configure-pod-container/configure-projected-volume-storage/).
98+
99+
You can manually migrate a secret-based service account volume to a projected volume when
100+
the `BoundServiceAccountTokenVolume` feature gate is not enabled by adding the above
101+
projected volume to the pod spec. However, `RootCAConfigMap` needs to be enabled.
87102

88103
### Token Controller
89104

0 commit comments

Comments
 (0)