# AlmaForge Kubernetes Access Guide

Connect Kubernetes clusters to AlmaForge for SSO-backed access through `kubectl`. Users authenticate through your corporate identity provider and receive short-lived credentials tied to mapped Kubernetes identities. The in-cluster agent brokers traffic to the Kubernetes API server using native Kubernetes impersonation headers, keeping API servers off the public internet while Kubernetes RBAC continues to enforce permissions.

Connecting target clusters

This guide shows how to connect target Kubernetes clusters to AlmaForge using the in-cluster agent Helm chart (`almaforge-agent`). To deploy the main control plane instead, see [Cluster on Kubernetes](https://almaforge.com/deployment/kubernetes.md) (`almaforge` chart).

* **Unified access across all clusters.** Manage EKS, GKE, AKS, and self-hosted clusters through one private, audited access plane instead of maintaining fragmented cloud IAM roles and VPN endpoints.
* **SSO mapped to Kubernetes RBAC.** Map IdP groups directly to Kubernetes users and groups. `kubectl` obtains short-lived credentials via an exec credential plugin with no static kubeconfigs or permanent admin tokens to rotate.
* **Keep existing tools.** Engineers continue using `kubectl`, `k9s`, Helm, and IDEs without workflow changes. `alma kube login` sets up the native kubeconfig context transparently.
* **Full audit trail and session replay.** Structured audit logs capture every API request with the user's verified SSO identity. Interactive `kubectl exec` and `attach` sessions are recorded for live observation and playback.

## Architecture[​](#architecture "Direct link to Architecture")

Kubernetes access consists of three components:

1. **AlmaForge Control Plane (`almad`):** The Auth and Proxy services running on Kubernetes or Linux. Terminates user sessions, validates SSO claims, issues short-lived certificates, and manages cluster state.
2. **In-Cluster Agent (`almaforge-agent` Helm chart):** A 2-replica StatefulSet running inside the target Kubernetes cluster. It dials outbound to the Proxy Service over a persistent TLS reverse tunnel and forwards incoming user requests to the in-cluster Kubernetes API server using impersonation headers (`Impersonate-User`, `Impersonate-Group`).
3. **Workstation Client (`alma` and `kubectl`):** Engineers log in via the CLI, select a target cluster with `alma kube login`, and interact with the cluster using standard `kubectl` commands.

![In-cluster agent topology](data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCA3NjAgMzgwIi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eT0iMzIiIHRleHQtYW5jaG9yPSJtaWRkbGUiIGZpbGw9IiMzNzQxNTEiIGZvbnQtc2l6ZT0iMTEiPlNBIHRva2VuPC90ZXh0PgoKCiAgPGxpbmUgeDE9IjQ3MCIgeTE9IjExOCIgeDI9IjQ3MCIgeTI9IjE2MCIKICAgICAgICBzdHJva2U9IiMxZjI5MzciIHN0cm9rZS13aWR0aD0iMS41IiBtYXJrZXItZW5kPSJ1cmwoI2Fycm93KSIvPgogIDx0ZXh0IHg9IjQ4MSIgeT0iMTQzIiBmaWxsPSIjMzc0MTUxIiBmb250LXNpemU9IjExIj5pbi1jbHVzdGVyIG5ldDwvdGV4dD4KCgogIDx0ZXh0IHg9IjM4MCIgeT0iMzcyIiB0ZXh0LWFuY2hvcj0ibWlkZGxlIiBmaWxsPSIjNmI3MjgwIiBmb250LXNpemU9IjExIj4KICAgIEFnZW50cyBjb25uZWN0IG91dGJvdW5kLiBObyBpbmJvdW5kIGFjY2VzcyB0byB0aGUgcHJpdmF0ZSBuZXR3b3JrIGlzIHJlcXVpcmVkLgogIDwvdGV4dD4KPC9zdmc+Cg==)

## Prerequisites[​](#prerequisites "Direct link to Prerequisites")

### AlmaForge Control Plane[​](#almaforge-control-plane "Direct link to AlmaForge Control Plane")

* A running AlmaForge control plane with Proxy Service reachable at `almaforge.example.com:443`. See [Cluster on Kubernetes](https://almaforge.com/deployment/kubernetes.md).
* An SSO connector configured on the control plane (e.g. Okta, Google, Microsoft, GitHub). See [Single Sign-On](https://almaforge.com/sso.md).
* An operator account with permissions to issue tokens (`admin` preset role).

### Target Kubernetes Cluster[​](#target-kubernetes-cluster "Direct link to Target Kubernetes Cluster")

* Target Kubernetes cluster running version 1.24 or later (EKS, GKE, AKS, or self-hosted).
* Network egress allowing outbound TCP/443 connections from agent pods to your AlmaForge Proxy endpoint.

### Operator Workstation[​](#operator-workstation "Direct link to Operator Workstation")

* `kubectl` 1.24+ configured with administrative access to the target cluster.
* Helm **3.12+** installed.
* The `alma` CLI installed and logged in to your control plane. See [Install the CLI](https://almaforge.com/cli.md).

## In-cluster agent[​](#in-cluster-agent "Direct link to In-cluster agent")

The recommended deployment runs the agent inside the target Kubernetes cluster using the official `almaforge/almaforge-agent` Helm chart.

### Step 1. Issue a join token (run on your control plane workstation)[​](#step-1-issue-a-join-token-run-on-your-control-plane-workstation "Direct link to Step 1. Issue a join token (run on your control plane workstation)")

Run this command from your workstation logged in to the **AlmaForge control plane**:

******Terminal

```bash
alma login --proxy=[your-almaforge-host]:443
alma create token --services=kubernetes,app,database --format=text
```

The command outputs the join credentials on two separate lines:

text

```text
[client-id]

[client-secret]
```

* Line 1 is the Client ID (`ALMA_CLIENT_ID`).
* Line 2 is the Client Secret (`ALMA_CLIENT_SECRET`).

Save these values. You will pass them to the target cluster in Step 2.

Secretless Workload Identity

To connect clusters using cloud-native IAM instead of static tokens, see [Workload Identity Join Options](#workload-identity-options) for Kubernetes, AWS IRSA, GCP, or Azure AD Workload Identity.

### Step 2. Install the agent with Helm (run against the target Kubernetes cluster)[​](#step-2-install-the-agent-with-helm-run-against-the-target-kubernetes-cluster "Direct link to Step 2. Install the agent with Helm (run against the target Kubernetes cluster)")

Switch your `kubectl` context to the **target Kubernetes cluster** you want to connect:

******Terminal

```bash
kubectl config use-context [your-target-cluster-context]
```

Add the Helm repository and install the `almaforge-agent` chart using the credentials from Step 1:

******Terminal

```bash
helm repo add almaforge https://get.almaforge.com/helm
helm repo update almaforge
helm upgrade --install almaforge-agent almaforge/almaforge-agent \
    --namespace almaforge --create-namespace \
    --set env.ALMA_PROXY=[your-almaforge-host]:443 \
    --set env.ALMA_CLIENT_ID=[client-id] \
    --set env.ALMA_CLIENT_SECRET=[client-secret] \
    --set clusterName=prod-cluster \
    --set labels.env=prod \
    --wait
```

Alternatively, maintain configuration in a version-controlled values file:

[`agent-values.yaml`](https://almaforge.com/examples/kubernetes/in-cluster-agent/agent-values.yaml):

examples/kubernetes/in-cluster-agent/agent-values.yaml

```yaml
# Helm values for an in-cluster AlmaForge agent (Kubernetes, App, and Database services).

# Issue a join token on the AlmaForge control plane first:

#   alma create token --services=kubernetes --format=text

env:

  ALMA_PROXY: 'almaforge.example.com:443'

  # Pass credentials via env, or comment out and use tokenSecret below for GitOps:

  ALMA_CLIENT_ID: '[client-id]'

  ALMA_CLIENT_SECRET: '[client-secret]'



# For GitOps (Vault, ExternalSecrets, SealedSecrets), load credentials from a Secret:

# tokenSecret:

#   name: almaforge-agent-token

#   clientIdKey: ALMA_CLIENT_ID

#   clientSecretKey: ALMA_CLIENT_SECRET



# Registers this Kubernetes cluster as a target in AlmaForge.

clusterName: prod-cluster

labels:

  env: prod



# RBAC configuration for the agent and impersonated users:

rbac:

  # User access bindings deployed alongside the agent to grant permissions

  # to impersonated AlmaForge groups or users:

  bindings:

    - name: almaforge-developers

      roleRef:

        kind: ClusterRole

        name: view

      subjects:

        - kind: Group

          name: developers
```

******Terminal

```bash
helm upgrade --install almaforge-agent almaforge/almaforge-agent \
    --namespace almaforge --create-namespace \
    -f agent-values.yaml --wait
```

See the [Helm Values Reference](https://almaforge.com/reference/helm.md#agent-chart) for every supported configuration option.

### Step 3. Verify agent registration[​](#step-3-verify-agent-registration "Direct link to Step 3. Verify agent registration")

On the **target cluster**, verify that the agent pods are running:

******Terminal

```bash
kubectl -n almaforge get pods -l app.kubernetes.io/component=agent
NAME                READY   STATUS    RESTARTS   AGE
almaforge-agent-0   1/1     Running   0          45s
almaforge-agent-1   1/1     Running   0          38s
```

On your **control plane workstation**, confirm the cluster has registered:

******Terminal

```bash
alma get kube
Cluster      Labels     Version
------------ ---------- -------
prod-cluster env=prod   2026.2.30
```

## Configure RBAC & SSO mappings[​](#rbac "Direct link to Configure RBAC & SSO mappings")

Access to Kubernetes clusters is governed by two layers:

1. **AlmaForge Role:** Controls which clusters a user can access and which Kubernetes users and groups the agent will impersonate.
2. **Kubernetes RBAC:** Native `ClusterRole`, `Role`, `ClusterRoleBinding`, and `RoleBinding` resources inside the target cluster that determine what those impersonated identities can do.

### Step 1. Define an AlmaForge Role[​](#step-1-define-an-almaforge-role "Direct link to Step 1. Define an AlmaForge Role")

Create an AlmaForge role that grants access to clusters matching `env: prod` and maps the engineer into the `developers` Kubernetes group:

[`kube-access.yaml`](https://almaforge.com/examples/kubernetes/roles/kube-access.yaml):

examples/kubernetes/roles/kube-access.yaml

```yaml
apiVersion: almaforge.com/v1

kind: Role

metadata:

  name: kube-access

spec:

  allow:

    kubernetesLabels:

      env: prod

    kubernetesResources:

      - kind: pod

        namespace: 'app-*'

        name: '*'

        verbs: ['get', 'list', 'watch']

    kubernetesGroups:

      - developers

    kubernetesUsers:

      - '{{external.email}}'
```

Apply the role to the control plane:

******Terminal

```bash
alma apply -f kube-access.yaml
```

Key fields in `spec.allow`:

* `kubernetesLabels`: Label selector matching the target cluster's `labels` (or `clusterName`).
* `kubernetesGroups`: The Kubernetes RBAC groups the agent impersonates when forwarding requests.
* `kubernetesUsers`: The Kubernetes username impersonated (supports template variables like `{{external.email}}`).
* `kubernetesResources`: Optional API-level filter restricting specific verbs, namespaces, and resources.

To grant cluster-admin access to trusted platform engineers, map to `system:masters`:

YAML

```yaml
apiVersion: almaforge.com/v1

kind: Role

metadata:

  name: kube-admin

spec:

  allow:

    kubernetesLabels:

      env: '*'

    kubernetesGroups:

      - system:masters
```

### Step 2. Provision Kubernetes bindings[​](#step-2-provision-kubernetes-bindings "Direct link to Step 2. Provision Kubernetes bindings")

Grant permissions to the impersonated group inside the target Kubernetes cluster. You can provision bindings directly via the agent's Helm values (`rbac.bindings`), or apply them manually with `kubectl`.

* Via Helm Values (Recommended)
* Via kubectl

Configure `rbac.bindings` in your `agent-values.yaml` so user bindings are version-controlled and deployed with the agent:

YAML

```yaml
rbac:

  bindings:

    - name: almaforge-developers

      roleRef:

        kind: ClusterRole

        name: view

      subjects:

        - kind: Group

          name: developers
```

Update the release:

******Terminal

```bash
helm upgrade almaforge-agent almaforge/almaforge-agent \
    --namespace almaforge -f agent-values.yaml
```

Apply a native `ClusterRoleBinding` directly to the target cluster:

[`developers-binding.yaml`](https://almaforge.com/examples/kubernetes/bindings/developers-binding.yaml):

examples/kubernetes/bindings/developers-binding.yaml

```yaml
apiVersion: rbac.authorization.k8s.io/v1

kind: ClusterRoleBinding

metadata:

  name: almaforge-developers

roleRef:

  apiGroup: rbac.authorization.k8s.io

  kind: ClusterRole

  name: view

subjects:

  - kind: Group

    name: developers

    apiGroup: rbac.authorization.k8s.io
```

******Terminal

```bash
kubectl apply -f developers-binding.yaml
```

### Step 3. Assign the role to users[​](#step-3-assign-the-role-to-users "Direct link to Step 3. Assign the role to users")

In your SSO connector (or `Role` assignment), map IdP groups or users to your AlmaForge roles. For example, map the Okta `Engineering` group to `kube-access` and `Platform-Admins` to `kube-admin`. See [OIDC SSO Configuration](https://almaforge.com/sso/oidc.md).

## Connect to Kubernetes[​](#connect-to-kubernetes "Direct link to Connect to Kubernetes")

### Step 1. Log in with the CLI[​](#step-1-log-in-with-the-cli "Direct link to Step 1. Log in with the CLI")

Sign in to AlmaForge from your workstation:

******Terminal

```bash
alma login --proxy=[your-almaforge-host]:443
```

List the available clusters:

******Terminal

```bash
alma get kube
Cluster      Labels     Version
------------ ---------- -------
prod-cluster env=prod   2026.2.30
```

### Step 2. Log in to the target cluster[​](#step-2-log-in-to-the-target-cluster "Direct link to Step 2. Log in to the target cluster")

Generate credentials and set your active `kubectl` context:

******Terminal

```bash
alma kube login prod-cluster
Logged into Kubernetes cluster "prod-cluster".
Try: kubectl get pods
```

`alma kube login` creates a context named `[your-almaforge-host]-prod-cluster` (with alias `prod-cluster`), switches your active `kubectl` context to it, and updates `~/.kube/config` with an `exec` credential plugin stanza ([`kubeconfig-stanza.yaml`](https://almaforge.com/examples/kubernetes/kubeconfig-stanza.yaml)) pointing to `alma kube credentials`. No static tokens or permanent certificates are stored on disk.

CLI in PATH

`kubectl` executes `alma kube credentials` automatically whenever you run a Kubernetes command. Ensure the `alma` binary is in your `$PATH`.

### Step 3. Run native kubectl commands[​](#step-3-run-native-kubectl-commands "Direct link to Step 3. Run native kubectl commands")

Interact with the cluster using standard Kubernetes tools:

******Terminal

```bash
kubectl get namespaces
kubectl get pods -n app-backend
kubectl exec -it deploy/frontend -n app-backend -- sh
kubectl port-forward svc/postgres -n app-backend 5432:5432
```

Tools like `k9s`, Helm, and Lens work out of the box using the configured context.

### Step 4. Switch between clusters[​](#step-4-switch-between-clusters "Direct link to Step 4. Switch between clusters")

To switch between multiple registered clusters:

******Terminal

```bash
# Switch to another cluster
alma kube login staging-cluster

# Or use standard kubectl context switching
kubectl config get-contexts
kubectl config use-context [your-almaforge-host]-prod-cluster
```

To configure all available clusters in your kubeconfig at once, run:

******Terminal

```bash
alma kube login --all
```

## Audit & session replay[​](#audit--session-replay "Direct link to Audit & session replay")

Every Kubernetes request proxied by AlmaForge is recorded and attributed to the operator's authenticated SSO identity:

* **Structured API Audit Events:** Non-interactive requests (such as `kubectl get`, `kubectl apply`, or port-forwards) generate structured audit events capturing the authenticated user, target cluster, namespace, resource, and HTTP verb. See [Audit Events Reference](https://almaforge.com/reference/audit.md).
* **Interactive Terminal Recording:** Sessions initiated via `kubectl exec` and `kubectl attach` record full terminal PTY input and output.

List recent session recordings:

******Terminal

```bash
alma recording ls --last=1h
ID                                   Type  User               Cluster      Duration
------------------------------------ ----- ------------------ ------------ --------
d6f4b2a1-89ce-4a7b-a49e-11f8139e88d1 kube  alice@example.com  prod-cluster 4m12s
```

Play back an interactive session in your terminal:

******Terminal

```bash
alma recording play d6f4b2a1-89ce-4a7b-a49e-11f8139e88d1
```

## Advanced[​](#advanced "Direct link to Advanced")

### Namespace isolation and RBAC scoping[​](#namespace-isolation "Direct link to Namespace isolation and RBAC scoping")

The agent requires a cluster-scoped `ClusterRole` to perform native Kubernetes user and group impersonation (`impersonate` on `users`, `groups`, and `serviceaccounts`).

Multi-tenant isolation and namespace jailing are enforced within AlmaForge roles rather than by restricting the agent's ServiceAccount:

* Map users to native Kubernetes groups or users that only possess permissions in specific namespaces.
* Use AlmaForge role definitions to restrict which namespaces, resources, and verbs users can access.

If you manage Kubernetes RBAC out-of-band via GitOps, set `rbac.create: false` to disable automatic `ClusterRole` and `ClusterRoleBinding` provisioning.

### Workload identity join options[​](#workload-identity-options "Direct link to Workload identity join options")

For production environments with supported cloud workload identity providers, agents can authenticate without static tokens:

* AWS IAM (EKS)
* GCP (GKE)
* Azure (AKS)
* Kubernetes (Same Cluster)

The agent authenticates using IAM Roles for Service Accounts (IRSA):

[`kube-iam.yaml`](https://almaforge.com/examples/kubernetes/tokens/kube-iam.yaml):

examples/kubernetes/tokens/kube-iam.yaml

```yaml
apiVersion: almaforge.com/v1

kind: Token

metadata:

  name: kube-agent

spec:

  roles:

    - system:kubernetes

  aws:

    allow:

      - awsAccount: '123456789012'

        awsARN: 'arn:aws:sts::123456789012:assumed-role/almaforge-agent/*'
```

******Terminal

```bash
alma apply -f kube-iam.yaml
```

Set `env.ALMA_JOIN_METHOD=aws` and `env.ALMA_CLIENT_ID=kube-iam` during install.

The agent authenticates via GKE Workload Identity:

[`kube-gcp.yaml`](https://almaforge.com/examples/kubernetes/tokens/kube-gcp.yaml):

examples/kubernetes/tokens/kube-gcp.yaml

```yaml
apiVersion: almaforge.com/v1

kind: Token

metadata:

  name: kube-agent

spec:

  roles:

    - system:kubernetes

  gcp:

    allow:

      - projectIDs:

          - 'my-project'

        serviceAccounts:

          - 'agent@my-project.iam.gserviceaccount.com'
```

******Terminal

```bash
alma apply -f kube-gcp.yaml
```

Set `env.ALMA_JOIN_METHOD=gcp` and `env.ALMA_CLIENT_ID=kube-gcp` during install.

The agent authenticates via Azure AD Workload Identity:

[`kube-azure.yaml`](https://almaforge.com/examples/kubernetes/tokens/kube-azure.yaml):

examples/kubernetes/tokens/kube-azure.yaml

```yaml
apiVersion: almaforge.com/v1

kind: Token

metadata:

  name: kube-agent

spec:

  roles:

    - system:kubernetes

  azure:

    allow:

      - subscription: '11111111-1111-1111-1111-111111111111'

        resourceGroups:

          - 'aks-rg'
```

******Terminal

```bash
alma apply -f kube-azure.yaml
```

Set `env.ALMA_JOIN_METHOD=azure` and `env.ALMA_CLIENT_ID=kube-azure` during install.

When the agent and control plane share a cluster or TokenReview API, the agent authenticates via its in-cluster `ServiceAccount` token:

******Terminal

```bash
alma apply -f - <<EOF
apiVersion: almaforge.com/v1
kind: Token
metadata:
  name: kube-agent
spec:
  services: [kubernetes, app, database]
  joinMethod: kubernetes
  kubernetes:
    type: in_cluster
    allow:
      - serviceAccount: "almaforge:almaforge-agent"
EOF
```

Set `env.ALMA_JOIN_METHOD=kubernetes` and `env.ALMA_CLIENT_ID=kube-agent` during install.

### Remote VM agent with kubeconfig[​](#remote-cluster "Direct link to Remote VM agent with kubeconfig")

When the agent cannot run as a pod inside the target cluster (for example, on isolated edge infrastructure or when managing multiple external clusters from a centralized bastion VM), install `almad` on a Linux VM and point it to the target cluster using a kubeconfig.

Files for this deployment pattern:

1. **Target Cluster RBAC:** Create a dedicated namespace and service account with impersonation permissions:

   * Apply [`01-namespace.yaml`](https://almaforge.com/examples/kubernetes/remote-agent/01-namespace.yaml)
   * Apply [`02-rbac.yaml`](https://almaforge.com/examples/kubernetes/remote-agent/02-rbac.yaml)

2. **Kubeconfig Template:** Generate a kubeconfig for the agent service account on the VM:
   * Template: [`03-kubeconfig.yaml`](https://almaforge.com/examples/kubernetes/remote-agent/03-kubeconfig.yaml)

3. **Environment Configuration:** Configure `/etc/almaforge/almad.env` on the agent VM:

   * Template: [`almad.env`](https://almaforge.com/examples/kubernetes/remote-agent/almad.env)
   * Set `ALMA_KUBERNETES_SERVICE=true` and `ALMA_KUBECONFIG=/etc/almaforge/kubeconfig.yaml`.

4. **Register the Target:** Register the cluster with the control plane:

   * Manifest: [`kubernetestarget.yaml`](https://almaforge.com/examples/kubernetes/remote-agent/kubernetestarget.yaml)
   * Apply with `alma apply -f kubernetestarget.yaml`.

### Isolated kubeconfig files[​](#isolated-kubeconfig-files "Direct link to Isolated kubeconfig files")

To keep work contexts separate without modifying your default `~/.kube/config`, specify an independent kubeconfig file:

******Terminal

```bash
alma kube login prod-cluster --kubeconfig=~/.kube/prod.yaml
KUBECONFIG=~/.kube/prod.yaml kubectl get pods
```

## Operations[​](#operations "Direct link to Operations")

### Upgrades[​](#upgrades "Direct link to Upgrades")

Upgrade the in-cluster agent using Helm. Leave `image.tag` unset so the agent version tracks the chart version:

******Terminal

```bash
helm repo update almaforge
helm upgrade almaforge-agent almaforge/almaforge-agent \
    --namespace almaforge -f agent-values.yaml --version [new-version] --wait
```

Because the chart runs two replicas by default with a `PodDisruptionBudget`, one replica updates while the other keeps serving without interrupting active traffic.

If an upgrade fails or misbehaves, roll back to the previous Helm revision:

******Terminal

```bash
helm -n almaforge rollback almaforge-agent --wait
```

### Uninstallation[​](#uninstallation "Direct link to Uninstallation")

To remove the in-cluster agent from the target cluster:

******Terminal

```bash
helm -n almaforge uninstall almaforge-agent
```

This removes the StatefulSet, ServiceAccount, ClusterRole, ClusterRoleBinding, Role, and NetworkPolicy. To wipe persistent process identity Secrets as well:

******Terminal

```bash
kubectl -n almaforge delete secret almaforge-agent-0-state almaforge-agent-1-state
```

## Troubleshooting[​](#troubleshooting "Direct link to Troubleshooting")

### `alma get kube` shows nothing[​](#alma-get-kube-shows-nothing "Direct link to alma-get-kube-shows-nothing")

1. Confirm agent pods are running:

   ******Terminal

   ```bash
   kubectl -n almaforge get pods -l app.kubernetes.io/component=agent
   ```

2. Inspect agent startup logs:

   ******Terminal

   ```bash
   kubectl -n almaforge logs statefulset/almaforge-agent
   ```

   Look for `Joining the cluster` or token authentication errors. If using a static token, confirm the token has not expired (`alma get token`).

### `kubectl` fails with `impersonate: user "..." cannot impersonate`[​](#kubectl-fails-with-impersonate-user--cannot-impersonate "Direct link to kubectl-fails-with-impersonate-user--cannot-impersonate")

The agent pod's `ServiceAccount` lacks RBAC permission to impersonate the target group or user. Verify that the chart's `ClusterRole` and `ClusterRoleBinding` were created:

******Terminal

```bash
kubectl get clusterrole almaforge-almaforge-agent
kubectl get clusterrolebinding almaforge-almaforge-agent
```

### `kubectl` commands return `forbidden`[​](#kubectl-commands-return-forbidden "Direct link to kubectl-commands-return-forbidden")

AlmaForge successfully authenticated the user and forwarded the request, but the target cluster's native RBAC denied the operation:

1. Inspect the groups mapped in the user's role:

   ******Terminal

   ```bash
   alma status
   ```

2. Confirm the target cluster has a binding for those exact groups:

   ******Terminal

   ```bash
   kubectl get clusterrolebindings -o yaml | grep -B 5 -A 10 "name: developers"
   ```

### GKE Autopilot: `cannot impersonate "system:masters"`[​](#gke-autopilot-cannot-impersonate-systemmasters "Direct link to gke-autopilot-cannot-impersonate-systemmasters")

GKE Autopilot blocks impersonation of the built-in `system:masters` group. Create a custom administrative group in your AlmaForge role (e.g. `cluster-admin-group`) and bind it to the `cluster-admin` ClusterRole in Kubernetes:

[`gke-autopilot-cluster-admin.yaml`](https://almaforge.com/examples/kubernetes/bindings/gke-autopilot-cluster-admin.yaml):

examples/kubernetes/bindings/gke-autopilot-cluster-admin.yaml

```yaml
# Workaround for GKE Autopilot, which blocks impersonation of the

# built-in `system:masters` group at admission. Bind a regular group

# to `cluster-admin` and reference it from the AlmaForge Role's

# kubernetesGroups instead.

apiVersion: rbac.authorization.k8s.io/v1

kind: ClusterRoleBinding

metadata:

  name: almaforge-cluster-admin

roleRef:

  apiGroup: rbac.authorization.k8s.io

  kind: ClusterRole

  name: cluster-admin

subjects:

  - kind: Group

    name: almaforge-cluster-admin

    apiGroup: rbac.authorization.k8s.io
```

### Agent fails with `x509: certificate signed by unknown authority`[​](#agent-fails-with-x509-certificate-signed-by-unknown-authority "Direct link to agent-fails-with-x509-certificate-signed-by-unknown-authority")

If your AlmaForge control plane uses an internal enterprise CA or private certificates, the agent container will not trust the proxy endpoint by default. Supply your root CA bundle via a ConfigMap (e.g. distributed by `trust-manager`) or Secret:

******Terminal

```bash
helm upgrade almaforge-agent almaforge/almaforge-agent \
    --namespace almaforge \
    --set tls.caConfigMapName=internal-ca \
    --set tls.caKey=ca.crt \
    -f agent-values.yaml
```

## References[​](#references "Direct link to References")

* [Helm Values Reference](https://almaforge.com/reference/helm.md#agent-chart): Complete values documentation for the `almaforge-agent` chart.
* [Declarative Configuration](https://almaforge.com/reference/configuration.md): Schema reference for `KubernetesTarget`, `Role`, and `Token`.
* [Workload Identity](https://almaforge.com/workload-identity.md): Detailed setup for in-cluster, AWS IAM, GCP, and Azure join methods.
* [RBAC Reference](https://almaforge.com/rbac.md): Complete documentation on role templates, deny rules, and dynamic trait mapping.
* [Audit & Recording](https://almaforge.com/reference/audit.md): Event types, retention, and compliance policies.
