|
1 | 1 | ---
|
2 | 2 | reviewers:
|
3 |
| -- bprashanth |
4 |
| -- davidopp |
5 |
| -- lavalamp |
6 |
| -- liggitt |
| 3 | + - bprashanth |
| 4 | + - davidopp |
| 5 | + - lavalamp |
| 6 | + - liggitt |
7 | 7 | title: Managing Service Accounts
|
8 | 8 | content_type: concept
|
9 | 9 | weight: 50
|
10 | 10 | ---
|
11 | 11 |
|
12 | 12 | <!-- overview -->
|
| 13 | + |
13 | 14 | This is a Cluster Administrator guide to service accounts. You should be familiar with
|
14 | 15 | [configuring Kubernetes service accounts](/docs/tasks/configure-pod-container/configure-service-account/).
|
15 | 16 |
|
16 |
| -Support for authorization and user accounts is planned but incomplete. Sometimes |
| 17 | +Support for authorization and user accounts is planned but incomplete. Sometimes |
17 | 18 | incomplete features are referred to in order to better describe service accounts.
|
18 | 19 |
|
19 |
| - |
20 | 20 | <!-- body -->
|
| 21 | + |
21 | 22 | ## User accounts versus service accounts
|
22 | 23 |
|
23 | 24 | Kubernetes distinguishes between the concept of a user account and a service account
|
@@ -53,37 +54,51 @@ It is part of the API server.
|
53 | 54 | It acts synchronously to modify pods as they are created or updated. When this plugin is active
|
54 | 55 | (and it is by default on most distributions), then it does the following when a pod is created or modified:
|
55 | 56 |
|
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. |
61 | 62 |
|
62 | 63 | #### Bound Service Account Token Volume
|
| 64 | + |
63 | 65 | {{< feature-state for_k8s_version="v1.21" state="beta" >}}
|
64 | 66 |
|
65 | 67 | 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. |
87 | 102 |
|
88 | 103 | ### Token Controller
|
89 | 104 |
|
|
0 commit comments