Kubernetes access control for every kubectl request

Formal's Connector sits in front of the Kubernetes API server. Engineers sign in with SSO through the Formal Endpoint and keep kubectl, with no shared kubeconfig. Every request passes a Rego policy, and impersonation leaves Kubernetes RBAC in charge of what each user can do.

kubectl · k8s-prodexample
# every Kubernetes API request, evaluated per identity
ALLOW   sam@example.com  list pods         namespace=payments
BLOCK   sam@example.com  get secrets       namespace=kube-system
VERIFY  sam@example.com  exec api-7f       MFA approved (Touch ID)
# exec session recorded, forwarded with Impersonate-User: sam@example.com

Why now

Where Kubernetes RBAC stops

Kubernetes RBAC decides whether a subject can run a verb on a resource, and it does that well. Kubernetes access control needs more: RBAC has no step that asks for MFA before an exec into production, it doesn’t record the shell that follows, and a binding has no end date. When a team shares one kubeconfig, RBAC also loses the subject: the cluster sees the same identity for everyone.

  1. Shared kubeconfigs and standing cluster-admin

    One kubeconfig for the whole team means one identity in every audit event, and cluster-admin rights that nobody hands back.

  2. No MFA before kubectl exec

    Whoever holds the kubeconfig gets a shell in a production pod, with no second check and no record of what runs in it.

  3. Bindings that never expire

    A RoleBinding grants a verb until someone deletes it, so access granted for one incident stays until someone remembers to remove it.

today · no policy on the pathexample
01
shared-kubeconfig · kubectlget secrets -n kube-systemALLOWED
02
sam · kubectlexec -it api-7f -- shALLOWED
03
leo · kubectldelete deployment api -n paymentsALLOWED

# RBAC allows all three, and the audit event names the shared identity.

What you get

What Kubernetes access control covers

Kubernetes access controlnoun

Kubernetes access control decides who can reach a cluster’s API server and what each request may do once it gets there. Kubernetes ships RBAC for the second half. Formal puts a Connector in front of the API server that checks identity and policy on every kubectl request, then hands the request to RBAC as the engineer who sent it.
  • Namespace, kind and verb policies

    Rego reads the group, namespace, kind, name, verb and subresource of each API request, so one rule can block the kube- namespaces and another every read of Secrets.

  • MFA for kubectl exec

    The Endpoint prompts for Touch ID or the passcode on macOS and Windows Hello on Windows. No answer within the timeout, 60 seconds by default, blocks the request.

  • Native RBAC per user

    Impersonation forwards each request as the engineer who sent it, so the cluster applies their own bindings and its audit log names them.

  • kubectl exec and attach recorded

    Sessions shows the pod, container, commands and user of each exec, with an AI summary and a risk score from 1 to 5.

  • Risky sessions stopped while they run

    Terminate an exec from Sessions, or let a policy suspend it or quarantine the user across SSH, Kubernetes and RDP.

  • Just-in-time exceptions

    A blocked engineer requests a one-time or time-bound exception, from 30 minutes to 7 days. Approval creates a policy suspension that ends on its own.

Setup

How it works

  1. Step 1 of 4

    Register the cluster

    Add the Kubernetes API endpoint as a Resource on a Connector, with a Native User: AWS IAM, AWS IAM Role, Azure IAM, GCP IAM or a kubeconfig. Cloud integrations discover EKS, GKE and AKS clusters.

    KUBERNETES RESOURCESexample
    • eks-prod via AWS IAM Role✓
    • gke-data via GCP IAM✓
    • on-prem cluster via kubeconfig✓
  2. Step 2 of 4

    Sign in, keep kubectl

    Engineers sign in to the Formal Endpoint with SSO. It updates the local kubeconfig and switches the current context, so kubectl talks to the Connector and the cluster credential stays on the Connector.

    WHO CONNECTSexample
    • sam@example.com · SSOPERSON
    • kubeconfig context set to the ConnectorENDPOINT
    • eks-prod credential · AWS IAM RoleNEVER SHOWN
  3. Step 3 of 4

    Write the policies

    Session-stage Rego policies read input.kubernetes on every API request and return allow, block, mfa or impersonate. Run a new policy in dry-run first.

    EVERY API REQUESTexample
    • list pods -n paymentsALLOWED
    • get secrets -n kube-systemBLOCKED
    • new policy · MFA on execDRY RUN
  4. Step 4 of 4

    Review and forward

    exec and attach sessions land in Sessions with a summary and a risk score. Every request is logged with the Formal user and can be forwarded to your SIEM.

    SESSIONSexample
    • exec api-7f · summary and risk scoreRECORDED
    • attach worker-2RECORDED
    • port-forward svc/api · logged onlyALLOWED

Policy

Kubernetes access control: RBAC plus per-request policy

Kubernetes RBAC answers one question: can this subject run this verb on this resource? Roles and ClusterRoles list permissions; RoleBindings and ClusterRoleBindings attach them to users, groups or service accounts. The RBAC good practices are the right baseline: namespace-scoped bindings, no wildcards, no casual cluster-admin, and nobody in system:masters, a group that bypasses every RBAC check.

  • What RBAC doesn’t see is context. A Rego policy on the Connector runs on every Kubernetes API request, with the request’s group, namespace, kind, name, verb and subresource in input.kubernetes and the engineer’s SSO identity and groups in input.user. That’s where MFA, recording and expiring exceptions come from
  • RBAC keeps the final say. With the impersonate action, the Connector forwards each request with Impersonate-User and Impersonate-Group headers, and the API server authorizes it against that user’s own bindings
  • This policy from the Kubernetes guide impersonates the calling user and keeps only the groups the cluster’s bindings use, so the Connector’s own impersonation rights can stay narrow
Impersonation in the Kubernetes guide ›
impersonate-end-user.regorego
package formal.v2

import future.keywords.if
import future.keywords.in

kubernetes_groups := {"k8s-viewers", "k8s-editors"}

session := {
  "action": "impersonate",
  "user": input.user.username,
  "groups": [g | some g in input.user.groups; g in kubernetes_groups],
} if {
  input.datastore.technology == "kubernetes"
}

Connect

Connect EKS, GKE and AKS clusters

Each engineer runs the authenticated Formal Endpoint. On the Connector, the Kubernetes Resource targets the API endpoint on port 443, and the Native User decides how the Connector finds the upstream cluster.

  • AWS IAM and AWS IAM Role

    Look up the EKS cluster by the Resource name, so the name must match the EKS cluster name exactly. The Connector’s role needs eks:DescribeCluster and sts:GetCallerIdentity, plus an EKS access entry and an access policy association that sets its permissions in the cluster.

    EKS
  • Kubeconfig and Kubeconfig Path

    Pick the context whose server URL matches the Resource hostname and port. Context names are ignored, and exactly one context must match.

    Any cluster
  • Azure IAM and GCP IAM

    Use the Connector’s ambient identity and connect to the Resource hostname directly.

    AKS and GKE
  • GKE Connect Gateway

    GKE clusters and other fleet clusters, such as GKE on bare metal or attached clusters, can also be reached through GKE Connect Gateway instead of the cluster’s own API endpoint.

    Fleet clusters

Without impersonation, every request runs with the Native User’s RBAC permissions, so scope them to what you’d give the least-privileged engineer. Cloud integrations discover EKS, GKE and AKS clusters (GKE discovery needs a public endpoint).

Cluster RBAC

Let the Connector impersonate your groups only

The Connector’s credential needs the impersonate verb on users and groups, and Kubernetes warns that impersonation gives the holder every right of the identity it impersonates. Without resourceNames on the groups rule, the Connector could impersonate system:masters. List the same groups as the policy.

  • Users stay unrestricted when the policy impersonates input.user.username, since those names can’t be listed in advance
  • An impersonated user only gets the bindings for that username, the groups the policy set and system:authenticated
  • Don’t bind the Connector’s credential to cluster-admin, which can impersonate anyone
Kubernetes resources docs ›
connector-clusterrole.yamlyaml
- apiGroups: [""]
  resources: ["groups"]
  resourceNames: ["k8s-viewers", "k8s-editors"]
  verbs: ["impersonate"]

Capabilities

Kubernetes access management for each engineer

Identity

SSO for kubectl, no shared kubeconfig

Engineers sign in to the Formal Endpoint with SSO. It updates the local kubeconfig and switches the current context, so kubectl talks to the Connector.

  • The kubeconfig entry points at the Connector. The cluster credential (an IAM identity or a kubeconfig) is a Native User on the Connector, so it never reaches the laptop
  • Impersonation forwards each request as the engineer who sent it, so the cluster applies their own bindings and its audit log names them
Formal Endpoint ›
kubectl · k8s-prodexample
14:01:55sam@example.comSSO sign-in, kubeconfig context setALLOWED
14:01:58connectoreks-prod via AWS IAM RoleTOKEN INJECTED
14:02:01sam@example.comlist pods -n payments as Impersonate-User samALLOWED
Sessions

Record and stop kubectl exec sessions

The Connector records kubectl exec and kubectl attach sessions. Other requests, including kubectl port-forward, are logged but not recorded.

  • In Sessions, each exec shows the pod, container, commands and user, with an AI summary and a risk score from 1 (lowest) to 5 (highest) based on the commands run, file access patterns, privilege escalation and destructive actions
  • An admin can terminate an active session, which disconnects the user
  • The session stage keeps evaluating while the exec runs. suspend ends that one session and lets the user reconnect
  • quarantine closes all of the user’s open sessions and keeps the account out of SSH, Kubernetes and RDP until an admin clicks Unblock User (enforcement actions)
Replay, search and the same controls on SSH ›
kubectl exec · api-7frecording · 4m 12s
sam@example.comrisk4/5
  1. 14:02:10kubectl exec -it api-7f -- sh
  2. 14:02:31ps aux
  3. 14:03:05cat /var/run/secrets/kubernetes.io/serviceaccount/token
  4. 14:06:22exit
SummaryOpened a shell in the api container and read the mounted service account token, which the debugging task didn't need.
Just-in-time

Just-in-time Kubernetes access

Most teams start by taking away standing cluster-admin. What replaces it is a policy that blocks the risky action, plus a way to ask for an exception.

  • An engineer who hits the block requests access in the employee Catalog: a one-time exception for that action, or time-bound access for 30 minutes to 7 days
  • Approval creates a policy suspension for that user. An admin can also create one by hand, with a CEL condition that narrows it to the requests it should cover and a reason for the audit trail. Deleting a suspension revokes it, and Formal removes expired ones on its own
  • Formal doesn’t send notifications for Access Requests, so someone has to check the queue. For on-call work that can’t wait, a Slack form can start a workflow that asks for approval in Slack and creates the same suspension; the just-in-time access guide explains the model behind it
  • Cursor replaced its homegrown access proxies with the Formal Connector. Its engineers don’t keep permanent production permissions; they ask for just-in-time access when an operational task needs it
Just-in-time access in Workflows ›
slack · #k8s-oncallexample
FormalAPP
sam requests a one-time exec on k8s-prod
Resource
k8s-prod
Action
exec api-7f -n payments
Scope
once
leo approved. Sam ran the exec, and the suspension closed.
APPROVED

Per-request rules

Policies on namespace, kind and verb

Each policy sees the fields kubectl sends to the API server, so the rule reads like the access you mean. Stepping up for exec is one line of condition.

  • The guide’s examples block every request to a namespace that starts with kube- (startswith(input.kubernetes.namespace, "kube-")) and block a kind such as secrets
  • When you protect Secrets, cover more than get: Kubernetes notes that list and watch on Secrets return their contents too, as kubectl get secrets -A -o yaml shows
  • When this rule matches, the Connector raises a challenge in the Control Plane and waits. The engineer’s Formal Endpoint picks it up and asks for Touch ID or the device passcode on macOS, or Windows Hello on Windows
  • If nobody answers within the timeout (60 seconds unless the policy sets timeout), Formal blocks the request with MFA authentication failed or timed out. Please try again.
  • For requests that don’t target a resource, such as API discovery, verb holds the lower-cased HTTP method instead
Every field and action in policy evaluation ›
mfa-on-exec.regorego
package formal.v2

import future.keywords.if

session := { "action": "mfa" } if {
  input.kubernetes.subresource == "exec"
}

The limits

What stays outside the Connector

This page covers Kubernetes access management for people reaching the cluster API through the Formal Connector. Plan for these.

  1. An Endpoint on every engineer's machine

    The Kubernetes guide lists a running, authenticated Endpoint as a requirement, and the MFA prompt can’t be answered without it, so plan to roll it out to every engineer’s machine. Your MDM can do that.

  2. Recording covers exec and attach only

    Every other Kubernetes API request, including kubectl port-forward, is logged but not recorded.

  3. No filtering of what the API server returns

    Kubernetes policies decide on the request at the session stage. A get secrets that a policy allows returns the Secret, so block it on the request instead.

  4. The Formal Endpoint for Kubernetes is separate

    The Formal Endpoint for Kubernetes is a native sidecar that applies policies to traffic leaving your pods.

  5. The Kubernetes operator is separate

    The Kubernetes operator registers in-cluster services, such as a Postgres database, as Formal resources.

Audit

Kubernetes audit logs that name the engineer

Behind a proxy or a shared kubeconfig, the API server sees one identity for everyone, so Kubernetes audit logs can’t say which person initiated a request. Without impersonation, the shared identity shows up in RBAC errors too. This one is from the Kubernetes guide, on EKS with no impersonation policy. The engineer who ran it isn’t in that message, and wouldn’t be in the cluster’s audit event either.

  • With Formal’s impersonate action, the API server’s audit events record the Connector as user and the engineer as impersonatedUser, so each action in the Kubernetes audit log ties back to a person
  • The cluster’s own auditing depends on how the API server is configured: on a self-managed control plane, no events are logged until kube-apiserver gets an audit policy file
  • Formal keeps its own Kubernetes access logs regardless. Each request is logged with the Formal user and the resource, searchable with resource.technology:kubernetes, and forwardable to S3, GCS, Pub/Sub, Azure Blob Storage, Datadog, Splunk or Panther
  • For a Kubernetes security audit, that gives you one access trail across clusters, databases and SSH hosts, in the same schema
Sessions and recordings docs ›
kubectl on EKS, no impersonationtext
$ kubectl get nodes
Error from server (Forbidden): nodes is forbidden: User "arn:aws:sts::123456789012:assumed-role/formal-connector-20240101000000000000000001/1234567890123456789" cannot list resource "nodes" in API group "" at the cluster scope

Deployment and enterprise

Runs in your VPC, and on each engineer's machine

Formal Connector in your VPC

Linux on AMD64 or ARM64: AWS ECS Fargate behind a Network Load Balancer, or Helm on EKS, GKE, AKS or on-premises Kubernetes. In production, run 2 or more nodes behind a load balancer.

Deployment docs ›

Formal Endpoint on laptops

Signs engineers in with SSO, writes the kubeconfig entry and answers MFA prompts with Touch ID or Windows Hello. Roll it out with your MDM.

Endpoint docs ›

Your identity provider

People sign in with SSO, and SCIM keeps users and groups in sync. Policies use the groups you already manage.

Logs in your SIEM

Log integrations forward Formal logs to AWS S3, Google Cloud Storage, Azure Blob Storage, Datadog, Splunk or Panther.

Policy and configuration as code

Policies are written in Rego. Manage Formal with Terraform, Pulumi or the Kubernetes Operator.

Audited controls

Formal holds SOC 2 Type II and ISO/IEC 27001. The reports are on security.formal.ai.

The Connector in front of your clusters also brokers SSH access and database access, with one policy language, one log and one approval flow in Workflows. Recorded kubectl exec sessions sit next to SSH recordings in session recording, and the privileged access management software hub covers the rest of the vertical.

In production

Technologies secured
10+
Resources secured
1,000+
“With Formal, we can finally manage least privilege access across our entire infrastructure through a single control plane.”
Tom Daniels
Tom Daniels
CISO, Cursor
Read the Cursor story ›

FAQ

Questions about Kubernetes access control

Buying and fit

Does Formal replace Kubernetes RBAC?

No. Kubernetes RBAC stays the authority on what each user can do. Formal checks a policy before the request reaches the API server, and with the impersonate action it forwards the request as the end user, so the cluster applies that user’s own bindings. Without impersonation, requests run with the Native User’s permissions, which is why that credential should never be bound to cluster-admin.

Which is better, ABAC or RBAC?

In Kubernetes, RBAC. The ABAC mode reads a policy file at startup, and the API server has to restart to pick up a change. RBAC objects change through the API. For rules that depend on context, such as MFA for production or an exception that expires, policy-based access control in front of RBAC works better: Formal evaluates Rego at the Connector and leaves the RBAC bindings in place.

What should a k8s access management tool add to RBAC?

Identity, context and a record. Each engineer should reach the cluster with their own SSO identity instead of a shared kubeconfig, risky actions such as exec should ask for MFA, elevated access should expire, and the audit trail should name the person behind every request. Formal does each of these at the Connector, in front of the API server.

Product

Do engineers still hold a kubeconfig?

They hold a kubeconfig entry that points at the Connector, written by the Formal Endpoint when they sign in. The cluster credential (an IAM identity or a kubeconfig) is a Native User on the Connector, so it never reaches the laptop.

Which kubectl actions does Formal record?

kubectl exec and kubectl attach sessions are recorded and reviewed in Sessions. Every other Kubernetes API request, including kubectl port-forward, is logged but not recorded.

Where are Kubernetes audit logs stored?

Wherever the API server’s audit backend sends them. Kubernetes ships a log backend that writes JSON lines to a file and a webhook backend that posts events to an external API, both set by kube-apiserver flags. Formal’s access logs don’t depend on either: the Connector logs each request it forwards, whatever the cluster’s audit policy says.

Put a policy in front of every kubectl request

Kubernetes access control with SSO, MFA on exec, recorded sessions and audit logs that name each engineer.