docs/documentation/platform/pam/getting-started/resources/kubernetes.mdx
Infisical PAM supports secure, just-in-time access to Kubernetes clusters. Your team can access Kubernetes clusters without sharing long-lived credentials, while maintaining a complete audit trail of who accessed what and when.
There are two ways to authenticate:
When using a service account token, the Gateway forwards kubectl requests to the Kubernetes API server using the provided token.
sequenceDiagram
participant User
participant CLI as Infisical CLI
participant Infisical
participant Gateway as Infisical Gateway
participant K8s as Kubernetes API Server
User->>CLI: Request Kubernetes access
CLI->>Infisical: Authenticate & request session
Infisical-->>CLI: Session credentials & Gateway info
CLI->>CLI: Start local proxy
CLI->>Gateway: Establish secure tunnel
User->>CLI: kubectl commands
CLI->>Gateway: Proxy kubectl requests
Gateway->>K8s: Forward with SA token
K8s-->>Gateway: Response
Gateway-->>CLI: Return response
CLI-->>User: kubectl output
When using Gateway auth, the Gateway authenticates as itself using its own pod service account, then tells the Kubernetes API to treat the request as if it came from the target service account.
sequenceDiagram
participant User
participant CLI as Infisical CLI
participant Infisical
participant Gateway as Infisical Gateway
participant K8s as Kubernetes API Server
User->>CLI: Request Kubernetes access
CLI->>Infisical: Authenticate & request session
Infisical-->>CLI: Session credentials & Gateway info
CLI->>CLI: Start local proxy
CLI->>Gateway: Establish secure tunnel
Gateway->>Infisical: Fetch session credentials (SA name + namespace)
User->>CLI: kubectl commands
CLI->>Gateway: Proxy kubectl requests
Gateway->>K8s: Forward with own token + Impersonate-User header
K8s->>K8s: Verify impersonation permission, apply target SA's RBAC
K8s-->>Gateway: Response
Gateway-->>CLI: Return response
CLI-->>User: kubectl output
No tokens are stored in Infisical. The Gateway reads its own pod token from the filesystem (auto-mounted by Kubernetes) and auto-discovers the Kubernetes API server from environment variables.
Gateway: An Infisical Gateway deployed in your network that can reach the Kubernetes API server. The Gateway handles secure communication between users and your cluster.
Service Account Token: A Kubernetes service account token that grants access to the cluster. This token is stored securely in Infisical and used by the Gateway to authenticate with the Kubernetes API.
Impersonation: A Kubernetes feature where one identity (the Gateway) can act on behalf of another (the target service account). The Gateway authenticates as itself and adds Impersonate-User headers. Kubernetes checks if the Gateway has permission to impersonate the target, then applies the target's RBAC rules.
Local Proxy: The Infisical CLI starts a local proxy on your machine that intercepts kubectl commands and routes them securely through the Gateway to your cluster.
Session Tracking: All access sessions are logged, including when the session was created, who accessed the cluster, session duration, and when it ended.
Infisical tracks:
Before configuring Kubernetes access in Infisical PAM, you need:
The PAM Resource represents the connection between Infisical and your Kubernetes cluster.
<Steps> <Step title="Ensure Gateway is Running"> Before creating the resource, ensure you have an Infisical Gateway running and registered with your Infisical instance. The Gateway must have network access to your Kubernetes API server. </Step> <Step title="Create the Resource in Infisical"> 1. Navigate to your PAM project and go to the **Resources** tab 2. Click **Add Resource** and select **Kubernetes** 3. Enter a name for the resource (e.g., `production-k8s`, `staging-cluster`) 4. Enter the **Kubernetes API Server URL** - the URL to your Kubernetes API endpoint (e.g.`https://kubernetes.example.com:6443`). If using Gateway auth with an in-cluster gateway, use `https://kubernetes.default.svc.cluster.local`. 5. Select the **Gateway** that has access to this cluster 6. Configure SSL verification options if needed<Note>
**SSL Verification**: You may need to disable SSL verification if your Kubernetes API server uses a self-signed certificate or an in-cluster CA. For Gateway auth with `https://kubernetes.default.svc.cluster.local`, disable SSL verification here — the Gateway will use strict TLS with the in-cluster CA certificate during sessions.
</Note>
Choose one of the two authentication methods below based on your setup.
<Tabs> <Tab title="Service Account Token"> Use this method when you have a static service account token, or when the Gateway is not running inside the Kubernetes cluster.### Create a Service Account
<Steps>
<Step title="Create the Service Account YAML">
Create a file named `sa.yaml` with the following content:
```yaml sa.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: infisical-pam-sa
namespace: kube-system
---
# Bind the ServiceAccount to the desired ClusterRole
# This example uses cluster-admin - adjust based on your needs
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: infisical-pam-binding
subjects:
- kind: ServiceAccount
name: infisical-pam-sa
namespace: kube-system
roleRef:
kind: ClusterRole
name: cluster-admin # Change this to a more restrictive role as needed
apiGroup: rbac.authorization.k8s.io
---
# Create a static, non-expiring token for the ServiceAccount
apiVersion: v1
kind: Secret
metadata:
name: infisical-pam-sa-token
namespace: kube-system
annotations:
kubernetes.io/service-account.name: infisical-pam-sa
type: kubernetes.io/service-account-token
```
<Warning>
**Security Best Practice**: The example above uses `cluster-admin` for simplicity. In production environments, you should create custom ClusterRoles or Roles with the minimum permissions required for each use case.
</Warning>
</Step>
<Step title="Apply the Service Account">
Apply the configuration to your cluster:
```bash
kubectl apply -f sa.yaml
```
This creates:
- A ServiceAccount named `infisical-pam-sa` in the `kube-system` namespace
- A ClusterRoleBinding that grants the service account its permissions
- A Secret containing a static, non-expiring token for the service account
</Step>
<Step title="Retrieve the Service Account Token">
Get the service account token that you'll use when creating the PAM account:
```bash
kubectl -n kube-system get secret infisical-pam-sa-token -o jsonpath='{.data.token}' | base64 -d
```
Copy this token - you'll need it in the next step.
</Step>
</Steps>
<Info>
When creating the resource in the step above, use `https://kubernetes.default.svc.cluster.local` as the URL and **disable SSL verification**. The Gateway handles TLS with the correct in-cluster CA automatically during sessions.
</Info>
### Set Up Impersonation Permissions
The Gateway's pod service account needs a ClusterRole that allows it to impersonate the target service accounts.
<Steps>
<Step title="Create the Impersonation ClusterRole">
Create a file named `gateway-impersonation.yaml`:
```yaml gateway-impersonation.yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: infisical-gateway-impersonator
rules:
- apiGroups: [""]
resources: ["serviceaccounts"]
verbs: ["impersonate"]
resourceNames:
- "deploy-bot" # Add each SA the gateway should be able to impersonate
- "ci-runner"
- apiGroups: [""]
resources: ["groups"]
verbs: ["impersonate"]
resourceNames:
- "system:serviceaccounts"
- "system:serviceaccounts:default" # Match the namespace(s) of the target SAs
- "system:authenticated"
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: infisical-gateway-impersonator-binding
subjects:
- kind: ServiceAccount
name: <gateway-pod-service-account> # The Gateway pod's own service account
namespace: <gateway-namespace>
roleRef:
kind: ClusterRole
name: infisical-gateway-impersonator
apiGroup: rbac.authorization.k8s.io
```
<Note>
**Scoped by `resourceNames`**: The `resourceNames` field limits which service accounts the Gateway can impersonate. If someone creates a PAM account pointing at a service account not in this list, the session will fail with a 403 from Kubernetes. This is how you control which accounts are accessible through Infisical.
</Note>
</Step>
<Step title="Apply the ClusterRole">
```bash
kubectl apply -f gateway-impersonation.yaml
```
</Step>
<Step title="Ensure target service accounts exist">
The service accounts you want to impersonate must already exist in the cluster with their own RBAC permissions. For example:
```yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: deploy-bot
namespace: default
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: deploy-bot-binding
subjects:
- kind: ServiceAccount
name: deploy-bot
namespace: default
roleRef:
kind: ClusterRole
name: view # Or whatever permissions this SA should have
apiGroup: rbac.authorization.k8s.io
```
The target SA's own RBAC rules determine what the user can do during the session.
</Step>
</Steps>
Once you have configured the PAM resource and set up authentication, create a PAM account to grant access.
<Steps> <Step title="Navigate to Resource"> Go to the **Resources** tab in your PAM project and open the Kubernetes resource you created. </Step> <Step title="Add New Account"> Click **Add Account**. </Step> <Step title="Select Authentication Method"> Choose the authentication method:- **Service Account Token** — paste the service account token you retrieved earlier.
- **Gateway** — enter the **Service Account Name** and **Namespace** of the Kubernetes service account you want to impersonate. No token is needed.
Once your resource and accounts are configured, users can request access through the Infisical CLI:
<Steps> <Step title="Get the Access Command"> 1. Navigate to the **Resources** tab in your PAM project and open the Kubernetes resource 2. In the resource's accounts section, find the account you want to access 3. Click the **Access** button for that account 4. Copy the provided CLI command </Step> <Step title="Run the Access Command"> Run the copied command in your terminal.The CLI will:
1. Authenticate with Infisical
2. Establish a secure connection through the Gateway
3. Start a local proxy on your machine
4. Configure kubectl to use the proxy
```bash
kubectl get pods
kubectl get namespaces
kubectl describe deployment my-app
```
All commands are routed securely through the Infisical Gateway to your cluster.
You can view session logs in the **Sessions** page of your PAM project.