Skip to content

Commit 7cb2217

Browse files
author
Jamie Klassen
committed
improve serviceAccountToken docs
Give instructions for k8s 1.24+, and mention the in-cluster option Signed-off-by: Jamie Klassen <jklassen@vmware.com>
1 parent 74fb2d3 commit 7cb2217

1 file changed

Lines changed: 33 additions & 2 deletions

File tree

docs/features/kubernetes/configuration.md

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ cluster. Valid values are:
110110
| `google` | This will use a user's Google access token from the [Google auth provider](https://backstage.io/docs/auth/google/provider) to access the Kubernetes API on GKE clusters. |
111111
| `googleServiceAccount` | This will use the Google Cloud service account credentials to access resources in clusters |
112112
| `oidc` | This will use [Oidc Tokens](https://kubernetes.io/docs/reference/access-authn-authz/authentication/#openid-connect-tokens) to authenticate to the Kubernetes API. When this is used the `oidcTokenProvider` field should also be set. Please note the cluster must support OIDC, at the time of writing AKS clusters do not support OIDC. |
113-
| `serviceAccount` | This will use a Kubernetes [service account](https://kubernetes.io/docs/reference/access-authn-authz/service-accounts-admin/) to access the Kubernetes API. When this is used the `serviceAccountToken` field should also be set. |
113+
| `serviceAccount` | This will use a Kubernetes [service account](https://kubernetes.io/docs/reference/access-authn-authz/service-accounts-admin/) to access the Kubernetes API. When this is used the `serviceAccountToken` field should also be set, or else Backstage should be running in-cluster. |
114114

115115
Check the [Kubernetes Authentication][4] section for additional explanation.
116116

@@ -127,7 +127,9 @@ CPU/Memory for pods returned by the API server. Defaults to `false`.
127127
##### `clusters.\*.serviceAccountToken` (optional)
128128

129129
The service account token to be used when using the `serviceAccount` auth
130-
provider. You could get the service account token with:
130+
provider. On versions of Kubernetes [prior to
131+
1.24](https://github.com/kubernetes/kubernetes/blob/master/CHANGELOG/CHANGELOG-1.24.md#no-really-you-must-read-this-before-you-upgrade-1),
132+
you could get an (automatically-generated) token for a service account with:
131133

132134
```sh
133135
kubectl -n <NAMESPACE> get secret $(kubectl -n <NAMESPACE> get sa <SERVICE_ACCOUNT_NAME> -o=json \
@@ -136,6 +138,35 @@ kubectl -n <NAMESPACE> get secret $(kubectl -n <NAMESPACE> get sa <SERVICE_ACCOU
136138
| base64 --decode
137139
```
138140

141+
For Kubernetes 1.24+, as described in [this
142+
guide](https://kubernetes.io/docs/concepts/configuration/secret/#service-account-token-secrets),
143+
you can obtain a long-lived token by creating a secret:
144+
145+
```sh
146+
kubectl apply -f - <<EOF
147+
apiVersion: v1
148+
kind: Secret
149+
metadata:
150+
name: <SECRET_NAME>
151+
namespace: <NAMESPACE>
152+
annotations:
153+
kubernetes.io/service-account.name: <SERVICE_ACCOUNT_NAME>
154+
type: kubernetes.io/service-account-token
155+
EOF
156+
```
157+
158+
waiting for the token controller to populate a token, and retrieving it with:
159+
160+
```sh
161+
kubectl -n <NAMESPACE> get secret <SECRET_NAME> -o go-template='{{.data.token | base64decode}}'
162+
```
163+
164+
If a cluster has `authProvider: serviceAccount` and the `serviceAccountToken`
165+
field is omitted, Backstage will ignore the configured URL and certificate data,
166+
instead attempting to access the Kubernetes API via an in-cluster client as in
167+
[this
168+
example](https://github.com/kubernetes-client/javascript/blob/master/examples/in-cluster.js).
169+
139170
##### `clusters.\*.oidcTokenProvider` (optional)
140171

141172
This field is to be used when using the `oidc` auth provider. It will use the id tokens

0 commit comments

Comments
 (0)