In-Cluster Workload Identity with Okustera & Terraform
Pod IAM Workload Identity is an optional zero-trust security feature. By default, Okustera runs in Standard Mode, allowing in-cluster automation and CI/CD pipelines to authenticate using scoped API tokens or application credentials stored in Kubernetes Secrets.
- Standard Mode (Default): In-cluster GitOps runners and pods authenticate using scoped Okustera API tokens mounted via Kubernetes Secrets.
- Enforced Mode (Optional): In-cluster pods project short-lived, cryptographically signed Kubernetes ServiceAccount tokens that are verified against cluster JWKS and evaluated against declarative
okustera_iam_rolepolicies.
This guide explains both approaches: authenticating in Standard Mode (recommended for most workloads) and authenticating in Enforced Mode (for strict zero-trust environments).
Architecture: Standard Mode vs. Enforced Mode
| Dimension | Standard Mode (Default) | Enforced Mode (Pod IAM) |
|---|---|---|
| Authentication Primitive | Scoped API Token mounted via Kubernetes Secret | Projected ServiceAccount JWT (okustera-platform audience) |
| Credential Lifecycle | Managed and rotated by tenant secret policies | Automatically rotated every hour by Kubernetes |
| Policy Definition | Standard tenant RBAC roles (admin, member, reader) | Fine-grained okustera_iam_role path & HTTP method policies |
Approach A: Standard Mode Authentication (Recommended)
In Standard Mode, you provision a scoped Personal Access Token (PAT) in the Okustera Cloud Portal, store it in a Kubernetes Secret, and inject it into your CI/CD runner pod:
1. Create a Kubernetes Secret with Your Scoped Token
apiVersion: v1
kind: Secret
metadata:
name: okustera-ci-credentials
namespace: gitlab-runners
type: Opaque
stringData:
OKUSTERA_ENDPOINT: "https://api.okustera.com/api/v1"
OKUSTERA_TENANT_ID: "tenant-production"
OKUSTERA_API_TOKEN: "<SCOPED_API_TOKEN>"
2. CI/CD Runner Pod Configuration (Standard Mode)
apiVersion: batch/v1
kind: Job
metadata:
name: terraform-apply-production
namespace: gitlab-runners
spec:
template:
spec:
serviceAccountName: default
restartPolicy: Never
containers:
- name: terraform
image: hashicorp/terraform:1.6.0
command: ["terraform", "apply", "-auto-approve"]
envFrom:
- secretRef:
name: okustera-ci-credentials
Approach B: Enforced Mode Authentication (Zero-Trust Workload Identity)
When Enforced Mode is enabled for your cluster, follow these steps to configure passwordless, zero-trust pod token authentication.
Why Avoid Static Credentials in GitOps?
Traditionally, running Terraform in CI/CD requires injecting a static token (OKUSTERA_API_TOKEN) into pipeline variables or secrets:
- Static secrets risk exposure through CI logs or compromised build artifacts.
- Static secrets require manual rotation schedules.
- Broadly scoped tokens can grant more access than a single pipeline requires.
The Workload Identity Solution
With Pod-Level IAM Role Isolation, Kubernetes acts as the identity provider:
- Every Kubernetes Pod running under a
ServiceAccountprojects a cryptographically signed JSON Web Token (JWT) issued by the cluster API server. - The JWT includes the pod's identity (
sub: system:serviceaccount:<namespace>:<sa>), audience (okustera-platform), and short expiry (1 hour). - The Okustera Terraform Provider automatically reads this projected token file (
/var/run/secrets/okustera/token). - When Terraform calls the Okustera API (
https://api.okustera.com/api/v1/*), the platform API Gateway validates the JWT signature against the cluster's JWKS endpoint. - The gateway resolves the pod's bound IAM role and verifies that its policy permits the requested API operation before forwarding the request.
Step-by-Step Setup
Step 1: Declare the IAM Role for Terraform in Okustera
Create an IAM Role defining which API endpoints this Terraform runner is allowed to manage:
resource "okustera_iam_role" "terraform_deployer" {
name = "terraform-deployer"
description = "Permissions for GitOps Terraform runner to deploy app stack"
endpoint_policies = [
{
effect = "Allow"
paths = [
"/api/v1/dbaas/*",
"/api/v1/storage/*",
"/api/v1/functions/*",
"/api/v1/apisix/*"
]
methods = ["GET", "POST", "PUT", "DELETE"]
},
{
effect = "Deny"
paths = [
"/api/v1/billing/payment-methods*",
"/api/v1/iam/roles/admin*"
]
methods = ["*"]
}
]
}
Step 2: Bind the ServiceAccount to the IAM Role
Bind the Kubernetes ServiceAccount used by your CI/CD runner pod:
resource "okustera_pod_identity_binding" "ci_runner_binding" {
namespace = "gitlab-runners"
service_account = "terraform-worker-sa"
role_name = okustera_iam_role.terraform_deployer.name
}
Step 3: Configure the Runner Pod Manifest
In your CI runner or Kubernetes Job manifest, project the ServiceAccount token:
apiVersion: batch/v1
kind: Job
metadata:
name: terraform-apply-production
namespace: gitlab-runners
spec:
template:
metadata:
annotations:
okustera.io/iam-role: "terraform-deployer"
spec:
serviceAccountName: terraform-worker-sa
restartPolicy: Never
containers:
- name: terraform
image: hashicorp/terraform:1.6.0
command: ["terraform", "apply", "-auto-approve"]
volumeMounts:
- name: okustera-token
mountPath: /var/run/secrets/okustera
readOnly: true
env:
- name: OKUSTERA_ENDPOINT
value: "https://api.okustera.com/api/v1"
- name: OKUSTERA_TOKEN_FILE
value: "/var/run/secrets/okustera/token"
volumes:
- name: okustera-token
projected:
sources:
- serviceAccountToken:
path: token
audience: "okustera-platform"
expirationSeconds: 3600
Step 4: Configure the Provider Block
In your application's main.tf, enable workload_identity:
provider "okustera" {
endpoint = "https://api.okustera.com/api/v1"
workload_identity = {
enabled = true
}
}
The provider automatically reads the projected token from /var/run/secrets/okustera/token (or the path specified in OKUSTERA_TOKEN_FILE), reloads it dynamically as Kubernetes rotates it, and authenticates each API call automatically.