Kubernetes access with your own kubectl
Give people and vendors access to a cluster's API server without handing out a kubeconfig, a VPN or a cluster credential: they use their own kubectl, Lens, k9s or Helm, Captivo checks every request, and every request is logged.
How it works
A Kubernetes resource is a cluster's API server. The user presses Connect in the portal and downloads a kubeconfig. Its server is your console's own address under /k8s/ and its token is a short-lived connection ticket, not a cluster credential. The connector next to the cluster signs each request in to the API server with a service account you created for Captivo, and tells the cluster which person is acting.
- No new port and no new certificate: kubectl talks HTTPS on 443 to the console host.
- The API server stays private. Only the connector reaches it, over its outbound tunnel.
- The cluster's own audit log can show the person, because requests act as the user's e-mail address (impersonation).
Use it for vendors who must run kubectl on one namespace, on-call engineers who should not hold a long-lived kubeconfig, and audits that ask who ran what. It is not a browser kubectl, and it does not discover clusters for you (see What is and is not supported).
Prepare the cluster
Captivo needs one service account with a long-lived token. In the resource form, Set up the cluster prints the YAML below, already filled in with your groups and your read-only choice. Apply it once with a cluster admin's kubectl.
# captivo.yaml: apply once with a cluster admin's kubectl
apiVersion: v1
kind: Namespace
metadata:
name: captivo
---
apiVersion: v1
kind: ServiceAccount
metadata:
name: captivo-access
namespace: captivo
---
apiVersion: v1
kind: Secret
metadata:
name: captivo-access-token
namespace: captivo
annotations:
kubernetes.io/service-account.name: captivo-access
type: kubernetes.io/service-account-token
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: captivo-access-impersonator
rules:
- apiGroups: [""]
resources: ["users"]
verbs: ["impersonate"]
- apiGroups: [""]
resources: ["groups"]
verbs: ["impersonate"]
resourceNames: ["captivo-users"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: captivo-access-impersonator
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: captivo-access-impersonator
subjects:
- kind: ServiceAccount
name: captivo-access
namespace: captivo
---
# What Captivo users may do: the built-in "edit" role for the captivo-users group.
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: captivo-users-edit
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: edit
subjects:
- kind: Group
name: captivo-users
apiGroup: rbac.authorization.k8s.ioWhat the YAML does
- Creates the
captivonamespace, thecaptivo-accessservice account and a Secret that holds its token. - Lets that account impersonate users, and groups only from the list you named (here
captivo-users). It cannot act assystem:mastersor any other group, so it cannot become cluster-admin. - Gives the first group a starting role: the built-in
editrole, orviewif the resource is read-only. Narrow it: bind roles to a person's e-mail address or to another group instead.
Read the token and the CA
# the service account's token (paste it into the resource form)
kubectl -n captivo get secret captivo-access-token -o jsonpath='{.data.token}' | base64 -d
# the cluster's CA certificate (paste it into "Cluster CA certificate")
kubectl -n captivo get secret captivo-access-token -o jsonpath='{.data.ca\.crt}' | base64 -dThe same recipe works on managed clusters (EKS, GKE, AKS). Their cloud sign-in plugins are not used: Captivo signs in with the service account token.
Add the cluster as a resource
Open Infrastructure → Resources → Add resource and choose Kubernetes (tag K8S). Fields, in form order (see also Resources):
| Field | What to enter | Example |
|---|---|---|
| API server | host:port as kubectl cluster-info shows it. Without a port, 443 is used; the form's placeholder uses 6443. https:// in front is accepted. | 10.0.0.5:6443 |
| Service account | The account the connector signs in as (the form pre-fills it). | captivo-access |
| Token | The token from the Secret. Users never see it. It is sealed to the connector (to each connector of a group) and stored encrypted; you can also take it from a credential provider instead of pasting it. | eyJhbGciOi… |
| Cluster CA certificate | PEM of the cluster's CA. Leave empty only when the API server has a publicly trusted certificate. | -----BEGIN CERTIFICATE----- |
| Certificate name | Optional. Only when the API server's certificate does not name the address above. | kubernetes.default |
| Requests act as | Each user, by name (impersonation, default) or The service account. | Each user, by name |
| Groups | Impersonation only. Up to 20 group names the user acts in; empty means captivo-users. Names starting with system: are refused. | captivo-users, shop-devs |
| Namespaces | Optional. Lowercase names, at most 50. Empty means all namespaces. | shop, shop-staging |
| Read only | Toggle, off by default. | on |
| Port forwarding | Toggle, off by default; hidden while Read only is on. | off |
| Request log and exec recording | Toggle; a new cluster starts with it on. Shows only when recording is enabled on the installation. | on |
Use Test connection before saving. The connector must be version 2.62.0 or later; the form warns when it is older. If you set ALLOWED_TARGETS on the connector, it must include the API server. With a connector group the token is sealed to every member.
/k8s/ route is already in place. On your own server your front proxy must send /k8s/ to the data plane with upgrades allowed, response buffering off and no request body limit (running it yourself); without it, kubectl gets the console's web page instead of the API.What the user does
First give the person a grant on the resource. Then, under My access, they press Connect on the cluster, choose macOS / Linux or Windows (PowerShell), and press Download kubeconfig. The dialog shows the two commands to use it and when the file expires. A kubeconfig looks like this:
# Captivo Access: works until 2026-11-25T18:20:00Z. Get a new one from the portal after that.
apiVersion: v1
kind: Config
clusters:
- name: captivo-prod-cluster
cluster:
server: https://acme.cloud.captivo.io/k8s/cmx12abcd0001
contexts:
- name: captivo-prod-cluster
context:
cluster: captivo-prod-cluster
user: captivo-prod-cluster
namespace: shop
current-context: captivo-prod-cluster
users:
- name: captivo-prod-cluster
user:
token: k7f3q9wz2m4xh8c2r6v5n9paThe context is named captivo- plus the resource name (captivo-prod-cluster). If the resource lists namespaces, the first one becomes the context's default namespace.
# macOS / Linux
export KUBECONFIG=~/Downloads/captivo-prod-cluster.yaml
kubectl get pods
kubectl -n shop logs deploy/api --tail=50
kubectl -n shop exec -it deploy/api -- sh
# Windows (PowerShell)
$env:KUBECONFIG = "$HOME\Downloads\captivo-prod-cluster.yaml"
kubectl get pods
# Lens, k9s and Helm read the same file
k9s --kubeconfig ~/Downloads/captivo-prod-cluster.yaml
helm --kubeconfig ~/Downloads/captivo-prod-cluster.yaml -n shop listEach press of Connect makes a new kubeconfig; earlier ones keep working until they end. The token in the file belongs to that person alone: do not share it or commit it.
Rules the resource enforces
Captivo reads each request's verb, resource and namespace the way the API server does and refuses before the request leaves. kubectl prints the reason. The cluster's own RBAC still applies on top: a rule can only narrow, never widen.
| Setting | Allowed | Refused |
|---|---|---|
| Read only | get, list, watch, logs, and the self-checks kubectl auth can-i makes. | Any change, kubectl exec and attach, port forwarding, and reading secrets. |
| Namespaces: shop | Anything in that namespace; reading cluster-wide kinds such as nodes, namespaces and CRDs. | Other namespaces, requests across all namespaces (kubectl get pods -A), and changing cluster-wide objects. |
| Port forwarding off | Everything else. | kubectl port-forward and the API server's proxy to pods, services and nodes. |
$ kubectl get pods -A
Error from server (Forbidden): Captivo Access: this resource reaches only the namespaces shop; name one with -n
$ kubectl -n shop delete pod api-7c9
Error from server (Forbidden): Captivo Access: this resource is read-onlyRule changes you make on the resource apply to open sessions within a minute; the user does not reconnect. Port forwarding is only possible when Read only is off. What crosses a port forward is not recorded; each one is logged.
Who the cluster sees
| Requests act as | The cluster sees | Use it when |
|---|---|---|
| Each user, by name | The user's e-mail address, in the groups you listed. Roles bound to that address or group decide what is allowed, and the cluster's audit log names the person. | Default. Different people need different rights. |
| The service account | One account, captivo-access, for everybody, with the role you bound to it. Captivo's request log still names the person. | Small clusters where one shared role is enough. |
The data plane removes any Authorization or Impersonate-* header the user's client sends. Only the connector decides who acts, so a user cannot impersonate someone else by editing the kubeconfig.
Ticket and session lifetime
- Eight hours at most. The kubeconfig token is a connection ticket. It never outlives the user's grant or the browser sign-in it was made in; signing out of the console ends it. It is stored only hashed.
- One session per ticket and address. kubectl opens a connection per command, so all requests of one ticket from one IP address are a single session in Live sessions and a single recording. It ends five minutes after the last request finishes.
- Checked every minute. Access, the grant and the resource's rules are re-checked each minute. When a grant ends or the ticket ends, the session is terminated, including exec sessions in flight. An admin can also end the session with End session in Live sessions.
- After expiry kubectl gets 401 Unauthorized. The user opens Connect again and downloads a new file.
Other rules from Policy, such as an IP allowlist, also apply to the address kubectl connects from.
Logging, recording and audit
- Request log. With Request log and exec recording on, each request is kept with its verb, resource, namespace, result and duration, for example
list pods,patch deployments.apps/api; refused requests are marked. Request bodies and what secrets hold are never stored. Discovery requests (what the cluster serves) are only counted. The log lives on the connector, like other recordings. - kubectl exec and attach are recorded like a terminal. Each exec is a session of its own in Live sessions, can be watched live, and has the terminal size and the exit code. With keystroke logging on (default for clusters), typed commands appear in the timeline.
kubectl cpruns as an exec, so its transfer is in that recording. - Audit log lists the session start and end (marked K8S), refused requests ("Refused by the resource's rules"), exec, attach and port forwards. Sessions ended by policy show whether the grant or the ticket ended.
- If recording is off for the resource, sessions are still listed and audited; only the request log and the exec recording are missing. On a recorded resource, an exec over a stream Captivo cannot read is refused (HTTP 501, update kubectl) rather than relayed unrecorded.
What is and is not supported
Supported
- kubectl, Lens, k9s, Helm
- Watches and log streaming
- exec and attach over WebSocket (kubectl 1.30+) or SPDY (older clients and libraries)
- Managed clusters (EKS, GKE, AKS) through a service account token
- Connector groups: another member carries the traffic if one is offline
Not supported
- A kubectl in the browser
- Moderated exec sessions
- Captivo ID groups as cluster groups (you list the groups on the resource)
- Finding clusters in a cloud account
- Cloud sign-in plugins (aws eks get-token, gke-gcloud-auth-plugin)
Common problems
| What kubectl says | Cause and fix |
|---|---|
| 401 Unauthorized: sign in with the kubeconfig from Captivo Access | The request had no bearer token: a different kubeconfig is in use (check echo $KUBECONFIG) or the user entry was edited. |
| 401 Unauthorized: this kubeconfig has expired or its sign-in ended | Past 8 hours, past the grant's end, or the user signed out of the console. Press Connect and download a new file. |
| 403 …you don't have access to this resource now | No active grant, or a Policy rule (for example IP allowlist) refuses. Check the grant and the Audit log. |
| 403 …this kubeconfig is for another resource | The URL's resource id differs from the ticket's. Use the file made for that cluster. |
| 403 …read-only / reaches only the namespaces | A rule of the resource; see Rules. Name a namespace with -n, or ask an admin to change the rule. |
| Forbidden by the cluster (pods is forbidden: User "vendor@acme.example" cannot list…) | Captivo let it through, the cluster's RBAC did not. Bind a role to that e-mail address or to the group. |
| 409 …can't be reached as a cluster now | The connector is older than 2.62.0, or the saved token must be entered again (it was sealed for an earlier address, account or connector). Edit the resource and paste the token. |
| 409 …no connector can carry this resource | No eligible connector is online. See connector offline. |
| 429 …too many sign-ins from this address | More than 30 new sessions per minute from one IP. Wait a minute. |
| 502 …connector is offline / API server didn't answer | The connector is down, or it cannot reach the API server (address, firewall, ALLOWED_TARGETS, CA or certificate name). |
| kubectl shows the console's HTML page | Self-hosted only: /k8s/ is not routed to the data plane. |
If the connector is down, see connector offline.
Related topics
For product-wide problems: The connector shows offline · The app does not open · Cannot sign in with a passkey