Kubernetes (Service Account)

For an overview of the available Kubernetes features and supported platforms, please see our Kubernetes guide.

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.

If you would like to learn more about how to enable automatic resource discovery within your Kubernetes cluster, or use privilege levels to allow users to request various levels of access to the Kubernetes cluster, please read the Kubernetes Discovery and Privilege Levels section to learn more about those features prior to following this configuration guide.

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.

  1. Create a ServiceAccount:

    kubectl create serviceaccount <serviceaccount-name>
  2. 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:
      - '*'
  1. 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>
  2. 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.

  1. 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
  2. Run:

    kubectl apply -f template.yaml
  3. If not done already, obtain the generated token by inspecting the Secret just created.

    kubectl get secret spirit -o json | jq -r '.data.token'
  4. Save the token in a safe place, as you will need it when adding your resource in the StrongDM Admin UI next.

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

  1. Log in to the StrongDM Admin UI and go to Resources > Clusters.

  2. Click Add cluster.

  3. For Cluster Type, select Kubernetes (Service Account).

  4. For API Token, set the token that you generated and saved in the previous section of this guide.

  5. Set all other required resource properties to configure how the StrongDM node connects.

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

Connectivity Mode

Required

Select either Virtual Networking Mode, which lets users connect to the resource with a software-defined, IP-based network; or Loopback Mode, which allows users to connect to the resource using the local loopback adapter in their operating system; this field is shown if Virtual Networking Mode enabled for your organization

IP Address

Optional

If Virtual Networking Mode is the selected connectivity mode, an IP address value in the configured Virtual Networking Mode subnet in the organization network settings; if Loopback Mode is the selected connectivity mode, an IP address value in the configured Loopback IP range in the organization network settings (by default, 127.0.0.1); if not specified, an available IP address in the configured IP address space for the selected connectivity mode will be automatically assigned; this field is shown if Virtual Networking Mode and/or multi-loopback mode is enabled for your organization

Port Override

Optional

If Virtual Networking Mode is the selected connectivity mode, a port value between 1 and 65535 that is not already in use by another resource with the same IP address; if Loopback Mode is the selected connectivity mode, a port value between 1024 to 64999 that is not already in use by another resource with the same IP address; when left empty with Virtual Networking Mode, the system assigns the default port to this resource; when left empty for Loopback Mode, an available port that is not already in use by another resource is assigned; preferred port also can be modified later from the Port Overrides settings

DNS

Optional

If Virtual Networking Mode is the selected connectivity mode, a unique hostname alias for this resource; when set, causes the desktop app to display this resource's human-readable DNS name (for example, k8s.my-organization-name) instead of the bind address that includes IP address and port (for example, 100.64.100.100:5432)

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.

Last updated

Was this helpful?