Skip to content

Commit 978b7ca

Browse files
authored
Merge pull request #33675 from liggitt/token
Expand manual token secret creation docs
2 parents a7d02c4 + 259da65 commit 978b7ca

File tree

1 file changed

+25
-14
lines changed
  • content/en/docs/concepts/configuration

1 file changed

+25
-14
lines changed

content/en/docs/concepts/configuration/secret.md

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@ You can still [manually create](/docs/tasks/configure-pod-container/configure-se
247247
a service account token Secret; for example, if you need a token that never expires.
248248
However, using the [TokenRequest](/docs/reference/kubernetes-api/authentication-resources/token-request-v1/)
249249
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.
250252
{{< /note >}}
251253

252254
#### Projection of Secret keys to specific paths
@@ -886,15 +888,30 @@ In this case, `0` means you have created an empty Secret.
886888
### Service account token Secrets
887889

888890
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
890892
{{< 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+
891907
When using this Secret type, you need to ensure that the
892908
`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.
898915

899916
The following example configuration declares a service account token Secret:
900917

@@ -911,20 +928,14 @@ data:
911928
extra: YmFyCg==
912929
```
913930

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.
921932

922933
See the [ServiceAccount](/docs/tasks/configure-pod-container/configure-service-account/)
923934
documentation for more information on how service accounts work.
924935
You can also check the `automountServiceAccountToken` field and the
925936
`serviceAccountName` field of the
926937
[`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.
928939

929940
### Docker config Secrets
930941

0 commit comments

Comments
 (0)