Skip to content
HomeConfigurationKubernetes Impersonation

Kubernetes Impersonation ​

By default, Kite connects to each cluster using the cluster's configured credentials (in-cluster ServiceAccount, kubeconfig, or Cluster Agent ServiceAccount): multi-tenant permissions are enforced inside Kite via RBAC Configuration, while kube-apiserver sees every request as coming from Kite's ServiceAccount.

When Kubernetes Impersonation is enabled on a cluster, Kite attaches Impersonate-User and Impersonate-Group headers to requests sent to kube-apiserver, acting on behalf of the currently logged-in Kite user.

How It Works (Why Cluster RBAC Matters) ​

In kube-apiserver, Kubernetes Impersonation works like sudo -u <current-user> (switching identity) rather than merely rewriting an audit label while keeping Kite's permissions:

  1. kube-apiserver first authenticates Kite's credential (e.g., Kite's ServiceAccount) and checks whether it has impersonate permission.
  2. Once verified, kube-apiserver discards Kite ServiceAccount's own permissions (even if Kite's ServiceAccount is bound to cluster-admin) and evaluates Kubernetes RBAC (RoleBinding / ClusterRoleBinding) strictly against the impersonated User and Groups.
  3. If the target cluster has no RoleBinding or ClusterRoleBinding matching that user or any of their groups, kube-apiserver treats the user as unauthorized and returns 403 Forbidden.

For every authenticated (non-anonymous) Kite user, Kite sends:

  • Impersonate-User: <impersonateUsernamePrefix> + user.Username
  • Impersonate-Group: <impersonateGroupsPrefix> + group for each of the user's OAuth/OIDC or LDAP groups, plus the fixed group kite:authenticated

kite:authenticated is a group name defined by Kite (similar to Kubernetes' built-in system:authenticated, but limited to users signed in through Kite). Kubernetes does not know about it in advance; it only takes effect if you reference it in a RoleBinding / ClusterRoleBinding. See Scenario 2.


Two Typical Usage Scenarios ​

Choose the setup below that matches how you want to manage permissions:

Scenario 1: Reuse Existing Native Kubernetes RBAC ​

When to use: Your cluster already maintains RoleBinding / ClusterRoleBinding rules for users or OIDC/LDAP groups (for example, engineers already access the cluster via OIDC + kubectl). You want Kite to enforce those exact cluster-native permissions without duplicating fine-grained rules in Kite, while recording real users in Kubernetes audit logs.

1. Target Cluster Setup ​

  • Ensure Kite can impersonate: If Kite's credential already uses cluster-admin, no extra setup is needed; otherwise see Kite Credential Permissions.
  • No new per-user RBAC needed for Kite: Reuse your cluster's existing RoleBinding / ClusterRoleBinding rules, such as:
yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: dev-team-edit
  namespace: app-staging
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: edit
subjects:
  - kind: Group
    name: oidc:developers
  - kind: User
    name: oidc:[email protected]

Namespace & Custom Resource Visibility

Under native Kubernetes RBAC, loading the namespace selector (GET /api/v1/namespaces) or resolving Custom Resource schemas (GET /apis/apiextensions.k8s.io/v1/customresourcedefinitions/<name>) also runs as the impersonated user and requires read permission on namespaces or customresourcedefinitions.

2. Kite Setup ​

  1. Enable Kubernetes Impersonation on the cluster, and set Username Prefix / Groups Prefix to match your existing bindings (e.g., oidc: in the example above).
  2. Control cluster visibility and delegate resource RBAC: In Kite's RBAC Configuration, create a role (do not name it admin, since admin grants Kite platform admin settings access) with wildcard resource permissions on that cluster so kube-apiserver makes all resource-level decisions:
yaml
rbac:
  roles:
    - name: prod-k8s-rbac
      description: "Allow access to production in Kite; delegate resource RBAC to Kubernetes"
      clusters: ["production"]
      namespaces: ["*"]
      resources: ["*"]
      verbs: ["*"]
  roleMapping:
    - name: prod-k8s-rbac
      oidcGroups: ["developers", "sre"]
      # Or allow all authenticated Kite users to see this cluster:
      # users: ["*"]

If you prefer Dual Authorization (intersection of Kite RBAC and Kubernetes RBAC), assign fine-grained Kite roles instead — requests will require permission in both systems.

Kite admins are impersonated too

Impersonation applies to every user, including Kite admin users. On an impersonated cluster, a Kite admin can only do what Kubernetes RBAC grants to their impersonated identity.


Scenario 2: Manage RBAC in Kite, Use Impersonation for K8s Audit Logs Only ​

When to use: You do not want to create or maintain Kubernetes RoleBinding rules for individual users or teams inside the cluster. You want to manage all multi-tenant roles and permissions inside Kite's UI (or config.yaml), and enable Impersonation solely so kube-apiserver audit logs record the real Kite operator (e.g., alice) instead of Kite's ServiceAccount.

Impersonation also changes some Kite behavior (no local cache, kubectl terminal disabled, and more). Review Behavior Changes before enabling it only for auditing.

Why You Don't Need Per-User Kubernetes RBAC Rules ​

Whenever Kite impersonates an authenticated user (whether logged in via Local Password, OAuth/OIDC, LDAP, or API Key), Kite automatically includes Impersonate-Group: kite:authenticated. A single static ClusterRoleBinding for this group gives every request sent through Kite the permissions it needs, while Kite RBAC decides who may do what.

Make sure nothing else can assert kite:authenticated

Kubernetes groups are plain strings, so kube-apiserver cannot tell whether a group came from Kite. Binding kite:authenticated to cluster-admin hands cluster-admin to anything that can present this group, for example:

  • Any other subject allowed to impersonate groups;
  • The cluster's own OIDC authenticator without --oidc-groups-prefix, if your IdP has a group named kite:authenticated;
  • A client certificate with O=kite:authenticated.

Confirm none of these apply to the cluster before creating the binding below.

1. Target Cluster Setup ​

  1. Ensure Kite's credential has impersonate permission (already included if Kite uses cluster-admin; see also Kite Credential Permissions).
  2. Create one ClusterRoleBinding in the target cluster granting Group: kite:authenticated the maximum scope Kite is allowed to manage (e.g., cluster-admin):
yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: kite-impersonated-users
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
  - kind: Group
    name: kite:authenticated
    apiGroup: rbac.authorization.k8s.io

After this one-time binding, adding or changing users, groups, or roles in Kite requires zero changes to Kubernetes RBAC in the cluster.

2. Kite Setup ​

  1. Enable Kubernetes Impersonation on the cluster (leave Username Prefix and Groups Prefix empty).
  2. Configure fine-grained roles and role mappings in Kite's RBAC Configuration as usual (e.g., viewer, namespace-scoped developer roles).
    • Unauthorized actions are blocked by Kite RBAC;
    • Authorized actions are forwarded to kube-apiserver with Impersonate-User: <username> and Impersonate-Group: kite:authenticated, recording the real user under impersonatedUser in Kubernetes audit logs.

Behavior Changes ​

On clusters with Impersonation enabled:

  • All users are impersonated, including Kite admin users. Their effective permissions on the cluster come from Kubernetes RBAC.
  • No local cache: The controller-runtime Informer cache is disabled, so every read goes directly to kube-apiserver and API request volume increases. Tune client rate limits with KITE_KUBE_API_QPS / KITE_KUBE_API_BURST if needed. Clusters without Impersonation keep using the cache.
  • Kubectl Terminal is disabled, because its helper Pod uses a static ServiceAccount token instead of per-user impersonation. Pod terminals (pods/exec) and logs (pods/log) work under the impersonated identity.
  • Overview counts: If the user cannot list nodes, pods, namespaces, or services, the overview shows 0 for that item instead of an error.
  • Scheduled tasks: Helm auto-upgrade tasks run as the user who last saved the task, and fail if that user is disabled or deleted.
  • Prometheus metrics:
    • Cluster-local URL (.svc / .svc.cluster.local): requests go through the Kubernetes Service proxy as the impersonated user, who needs services/proxy access to that Prometheus Service.
    • External URL: all users share one Prometheus client that does not use Kubernetes credentials, so queries are not restricted by Kubernetes RBAC.
    • In both cases, PromQL results are not filtered per Kubernetes object.

Enabling Impersonation ​

Impersonation is configured per cluster.

Option 1: Via Dashboard UI ​

  1. Sign in as a Kite admin and go to Settings -> Cluster Management.
  2. Click Add Cluster or Edit on an existing cluster.
  3. Turn on Kubernetes Impersonation and optionally set Username Prefix and Groups Prefix.
  4. Save changes.

Option 2: Via Configuration File / Helm Values ​

In config.yaml or inline Helm config.clusters:

yaml
clusters:
  - name: production
    inCluster: true
    impersonate: true
    impersonateUsernamePrefix: "" # e.g. "oidc:" for Scenario 1; leave empty for Scenario 2
    impersonateGroupsPrefix: ""   # e.g. "oidc:" for Scenario 1; leave empty for Scenario 2
    default: true

Kite Credential Permissions ​

With Impersonation enabled, Kite no longer needs a cluster-admin binding. Kite's own credential (without impersonation) is only used for:

PurposeRequestPermission
Cluster versionGET /versionAllowed by the default system:public-info-viewer binding
API discoveryGET /api, GET /apisAllowed by the default system:discovery binding
Prometheus auto-discovery (only when no Prometheus URL is set)List Services in all namespacesOptional; failures are only logged

Every other request uses the impersonated identity, so the credential only needs impersonate:

yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: kite-impersonator
rules:
  - apiGroups: [""]
    resources: ["users", "groups"]
    verbs: ["impersonate"]
  # Optional: allow Prometheus auto-discovery
  # - apiGroups: [""]
  #   resources: ["services"]
  #   verbs: ["list"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: kite-impersonator
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: kite-impersonator
subjects:
  - kind: ServiceAccount
    name: kite
    namespace: kite-system

For the cluster Kite runs in, you can set these rules through the Helm value rbac.rules instead. Only do this if every cluster that uses this ServiceAccount has Impersonation enabled.

impersonate is still a cluster-admin-equivalent permission

A credential that can impersonate any user and group can impersonate the system:masters group or built-in users such as system:kube-controller-manager. Kite refuses to impersonate system:* identities, but that is an application-level check: if the credential leaks, the impact is the same as leaking cluster-admin. The benefit of Impersonation is that day-to-day requests run as the real user and are authorized and audited by the cluster, not that Kite's credential becomes low-privilege.

In Scenario 2, the only group Kite needs to assert is kite:authenticated (plus system:unauthenticated if anonymous access is enabled), so you can restrict groups with resourceNames. This blocks impersonating system:masters, but users cannot be restricted the same way because usernames are dynamic:

yaml
rules:
  - apiGroups: [""]
    resources: ["users"]
    verbs: ["impersonate"]
  - apiGroups: [""]
    resources: ["groups"]
    verbs: ["impersonate"]
    resourceNames: ["kite:authenticated"]

Identity Mapping ​

  • Username: Impersonate-User is <impersonateUsernamePrefix> + user.Username (never the editable display name Name). API Key users are impersonated as the API Key name.
  • Groups: Impersonate-Group includes kite:authenticated plus <impersonateGroupsPrefix> + group for each OAuth/OIDC or LDAP group.
  • Prefixes are per cluster, not per login provider: Local password, LDAP, and API Key users get the same prefix as OAuth/OIDC users.
  • Anonymous Mode: If anonymous access is enabled, anonymous requests map to system:anonymous with the group system:unauthenticated only (without kite:authenticated).
  • OAuth / OIDC Best Practice: Configure usernameClaim to a stable, immutable identifier that users cannot freely change in your IdP (such as a corporate email or sub), or prefer binding Kubernetes RBAC permissions to OIDC/LDAP groups.

Security Notes ​

  • Reserved identities are rejected (fail-closed): system:*, kubeadm:*, and kubernetes-admin cannot be impersonated. Reserved groups such as system:masters are dropped from group claims, and reserved usernames are rejected with 403 Forbidden without falling back to Kite's own credentials.
  • Client-supplied impersonation headers are ignored: Kite always replaces any incoming Impersonate-* headers with the signed-in user's identity.
  • Group name collisions: See the warning in Scenario 2 before binding kite:authenticated.
  • Credential permissions: See Kite Credential Permissions.

Released under the Apache License.