Add a Kubernetes Cluster Via Service Account
Last modified on May 12, 2025
This guide describes how to set up a Kubernetes cluster in StrongDM with the credentials of a Kubernetes service account. This process involves setting up a Kubernetes cluster, generating a permanent service account token, and using that token to configure a new Kubernetes (Service Account) cluster in the StrongDM Admin UI. When done with this guide, you will be able to use StrongDM to connect to a Kubernetes cluster with the credentials of a Kubernetes service account.
Prerequisites
Ensure that the API server you intend to add to StrongDM is accessible from your StrongDM nodes (gateways, relays, or proxy clusters). See our guide on Nodes for more information.
If you are using kubectl 1.30 or higher, it will default to using websockets, which the StrongDM client did not support prior to version 45.35.0. This can be remedied by taking one of the following actions:
- Update your client to version 45.35.0 or greater.
- Set the environment variable
KUBECTL_REMOTE_COMMAND_WEBSOCKETS=false
to restore the previous behavior in your kubectl.
Configure the Kubernetes Cluster
Before you can add the cluster to your StrongDM environment, you need to set up the cluster itself. Follow these steps to configure your cluster.
Create a ServiceAccount:
kubectl create serviceaccount <serviceaccount-name>
Create a Role or ClusterRole.
The permissions given in this Role are exactly what StrongDM users get when they connect to this resource.The following example ClusterRole gives blanket permissions to the whole cluster:
apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: annotations: rbac.authorization.kubernetes.io/autoupdate: "true" labels: kubernetes.io/bootstrapping: rbac-defaults name: <clusterrolebinding-name> rules: - apiGroups: - '*' resources: - '*' verbs: - '*' - nonResourceURLs: - '*' verbs: - '*'
Create a RoleBinding or ClusterRoleBinding to associate the Role or ClusterRole with the ServiceAccount.
To create a RoleBinding:
kubectl create rolebinding <rolebinding-name> --role <role-name> --serviceaccount <serviceaccount-name>
To create a ClusterRoleBinding:
kubectl create clusterrolebinding <clusterrolebinding-name> --clusterrole <clusterrole-name> --serviceaccount <serviceaccount-name>
Create a Secret to manually generate a permanent token.
In this step, you manually create a token secret that the kube-apiserver detects and then populates with a token associated with the ServiceAccount. This secret (and token) does not expire. For reference, please see the Kubernetes documentation, Configure Service Accounts for Pods.- First save and complete the following yaml template:
apiVersion: v1 kind: Secret metadata: name: build-robot-secret annotations: kubernetes.io/service-account.name: <serviceaccount-name> type: kubernetes.io/service-account-token
- Run:
kubectl apply -f template.yaml
- If not done already, obtain the generated token by inspecting the Secret just created.
kubectl get secret spirit -o json | jq -r '.data.token'
- Save the token in a safe place, as you will need it when adding your resource in the StrongDM Admin UI next.
- First save and complete the following yaml template:
There are alternative ways to generate tokens, other than the manual way described in this guide. However, such ways typically yield temporary tokens, which may adversely affect resource registration. For example, if the following command is used to get a token directly to stdout, the --duration
flag may not be respected:
kubectl create token <serviceaccount-name> --duration <duration> | pbcopy
Add Your Kubernetes (Service Account) Cluster in StrongDM
- Log in to the StrongDM Admin UI and go to Resources > Clusters.
- Click Add cluster.
- For Cluster Type, select Kubernetes (Service Account).
- For API Token, set the token that you generated and saved in the previous section of this guide.
- Set all other required resource properties to configure how the StrongDM node connects.
- Click Create to save the resource.
The Admin UI updates and shows your new cluster in a healthy or unhealthy state. Healthy indicates a successful connection. If it is unhealthy, click into the cluster’s name and view the Diagnostics tab to determine where the connection is failing.
Resource properties
The following table describes the configuration properties available for your Kubernetes (Service Account) cluster.
Property | Requirement | Description |
---|---|---|
Display Name | Required | Meaningful name to display the resource throughout StrongDM; exclude special characters like quotes (") or angle brackets (< or >) |
Cluster Type | Required | Select Kubernetes (Service Account) |
Proxy Cluster | Required | Defaults to “None (use gateways)”; if using proxy clusters, select the appropriate cluster to proxy traffic to this resource |
Hostname | Required | Hostname or IP address of the API server, such as api.aks.example.com ; relay server should be able to connect to your target server or hostname |
Port | Required | Port to connect to the API server; default port value 443 |
IP Address | Optional | Shows up when a loopback range is configured for the organization; local IP address used to connect to this resource using the local loopback adapter in the user’s operating system; defaults to 127.0.0.1 |
Port Override | Optional | Automatically generated with a value between 1024 to 64999 as long as that port is not used by another resource; preferred port can be modified later under Settings > Port Overrides; after specifying the port override number, you must also update the kubectl configuration, which you can learn more about in section Port Overrides |
Secret Store | Optional | Credential store location; defaults to Strong Vault; to learn more, see Secret Store options |
API Token | Required | Permanent token associated with the ServiceAccount on the Kubernetes cluster |
Healthcheck Namespace | Optional | If enabled for your organization, the namespace used for the resource healthcheck; defaults to default if empty; supplied credentials must have the rights to perform one of the following kubectl commands in the specified namespace: get pods , get deployments , or describe namespace |
API Token | Required | Permanent token associated with the ServiceAccount on the Kubernetes cluster |
Authentication | Required | Authentication method to access the cluster; select either Leased Credential (default) or Identity Aliases (to use the Identity Aliases of StrongDM users to access the cluster) |
Identity Set | Required | Displays if Authentication is set to Identity Aliases; select an Identity Set name from the list |
Healthcheck Username | Required | If Authentication is set to Identity Aliases, the username that should be used to verify StrongDM’s connection to it; username must already exist on the target cluster |
Resource Tags | Optional | Resource tags consisting of key-value pairs <KEY>=<VALUE> (for example, env=dev ) |
Display name
Some Kubernetes management interfaces, such as Visual Studio Code, do not properly render cluster names containing spaces. If you run into problems, please choose a Display Name without spaces.
Secret Store
By default, server credentials are stored in StrongDM. However, these credentials can also be saved in a secrets management tool.
Non-StrongDM options appear in the Secret Store dropdown if they are created under Settings > Secrets Management. When you select another Secret Store type, its unique properties display. For more details, see Configure Secret Store Integrations.