@@ -247,6 +247,8 @@ You can still [manually create](/docs/tasks/configure-pod-container/configure-se
247
247
a service account token Secret; for example, if you need a token that never expires.
248
248
However, using the [TokenRequest](/docs/reference/kubernetes-api/authentication-resources/token-request-v1/)
249
249
subresource to obtain a token to access the API is recommended instead.
250
+ You can use the [`kubectl create token`](/docs/reference/generated/kubectl/kubectl-commands#-em-token-em-)
251
+ command to obtain a token from the `TokenRequest` API.
250
252
{{< /note >}}
251
253
252
254
# ### Projection of Secret keys to specific paths
@@ -886,15 +888,30 @@ In this case, `0` means you have created an empty Secret.
886
888
# ## Service account token Secrets
887
889
888
890
A `kubernetes.io/service-account-token` type of Secret is used to store a
889
- token that identifies a
891
+ token credential that identifies a
890
892
{{< glossary_tooltip text="service account" term_id="service-account" >}}.
893
+
894
+ Since 1.22, this type of Secret is no longer used to mount credentials into Pods,
895
+ and obtaining tokens via the [TokenRequest](/docs/reference/kubernetes-api/authentication-resources/token-request-v1/)
896
+ API is recommended instead of using service account token Secret objects.
897
+ Tokens obtained from the `TokenRequest` API are more secure than ones stored in Secret objects,
898
+ because they have a bounded lifetime and are not readable by other API clients.
899
+ You can use the [`kubectl create token`](/docs/reference/generated/kubectl/kubectl-commands#-em-token-em-)
900
+ command to obtain a token from the `TokenRequest` API.
901
+
902
+ You should only create a service account token Secret object
903
+ if you can't use the `TokenRequest` API to obtain a token,
904
+ and the security exposure of persisting a non-expiring token credential
905
+ in a readable API object is acceptable to you.
906
+
891
907
When using this Secret type, you need to ensure that the
892
908
` kubernetes.io/service-account.name` annotation is set to an existing
893
- service account name. A Kubernetes
894
- {{< glossary_tooltip text="controller" term_id="controller" >}} fills in some
895
- other fields such as the `kubernetes.io/service-account.uid` annotation, and the
896
- ` token` key in the `data` field, which is set to contain an authentication
897
- token.
909
+ service account name. If you are creating both the ServiceAccount and
910
+ the Secret objects, you should create the ServiceAccount object first.
911
+
912
+ After the Secret is created, a Kubernetes {{< glossary_tooltip text="controller" term_id="controller" >}}
913
+ fills in some other fields such as the `kubernetes.io/service-account.uid` annotation, and the
914
+ ` token` key in the `data` field, which is populated with an authentication token.
898
915
899
916
The following example configuration declares a service account token Secret :
900
917
@@ -911,20 +928,14 @@ data:
911
928
extra: YmFyCg==
912
929
` ` `
913
930
914
- When creating a `Pod`, Kubernetes automatically finds or creates a service account
915
- Secret and then automatically modifies your Pod to use this Secret. The service account
916
- token Secret contains credentials for accessing the Kubernetes API.
917
-
918
- The automatic creation and use of API credentials can be disabled or
919
- overridden if desired. However, if all you need to do is securely access the
920
- API server, this is the recommended workflow.
931
+ After creating the Secret, wait for Kubernetes to populate the `token` key in the `data` field.
921
932
922
933
See the [ServiceAccount](/docs/tasks/configure-pod-container/configure-service-account/)
923
934
documentation for more information on how service accounts work.
924
935
You can also check the `automountServiceAccountToken` field and the
925
936
` serviceAccountName` field of the
926
937
[`Pod`](/docs/reference/generated/kubernetes-api/{{< param "version" >}}/#pod-v1-core)
927
- for information on referencing service account from Pods.
938
+ for information on referencing service account credentials from within Pods.
928
939
929
940
# ## Docker config Secrets
930
941
0 commit comments