Kubernetes
This guide extends the Quickstart to use a real Kubernetes cluster instead of the mock provider. By the end you will have submitted, approved, and executed a kubectl command using a temporary RBAC binding that jitsudo manages.
How jitsudo Maps to Kubernetes RBAC
Section titled “How jitsudo Maps to Kubernetes RBAC”Before starting, it helps to understand how jitsudo’s abstract concepts map to Kubernetes:
| jitsudo concept | Kubernetes equivalent |
|---|---|
--role | A ClusterRole name that must already exist in the cluster |
--scope | A namespace (creates a RoleBinding) or * (creates a ClusterRoleBinding) |
| Grant issued | jitsudo creates a RoleBinding or ClusterRoleBinding for the requester’s identity |
| Grant expired/revoked | jitsudo deletes the RoleBinding or ClusterRoleBinding |
What You’ll Need
Section titled “What You’ll Need”- A working jitsudo local environment (from the Quickstart)
- A Kubernetes cluster with
kubectlconfigured andcluster-adminaccess - A
kindorminikubecluster works perfectly for this guide
Step 1: Create a Sandbox Namespace
Section titled “Step 1: Create a Sandbox Namespace”kubectl create namespace jitsudo-sandboxStep 2: Create a Target ClusterRole
Section titled “Step 2: Create a Target ClusterRole”jitsudo’s Kubernetes provider assumes the ClusterRole already exists — it creates and deletes RoleBinding objects, it does not create ClusterRole objects. Create the sandbox role:
kubectl apply -f - <<EOFapiVersion: rbac.authorization.k8s.io/v1kind: ClusterRolemetadata: name: jitsudo-sandbox-viewerrules: - apiGroups: [""] resources: ["pods", "services", "configmaps"] verbs: ["get", "list", "watch"]EOFStep 3: Create a Service Account for jitsudod
Section titled “Step 3: Create a Service Account for jitsudod”jitsudod needs a service account with permission to create and delete RoleBinding and ClusterRoleBinding objects:
kubectl apply -f - <<EOFapiVersion: v1kind: ServiceAccountmetadata: name: jitsudo-control-plane namespace: jitsudo-system---apiVersion: rbac.authorization.k8s.io/v1kind: ClusterRolemetadata: name: jitsudo-rbac-managerrules: - apiGroups: ["rbac.authorization.k8s.io"] resources: ["rolebindings", "clusterrolebindings"] verbs: ["get", "list", "create", "delete"]---apiVersion: rbac.authorization.k8s.io/v1kind: ClusterRoleBindingmetadata: name: jitsudo-rbac-managerroleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: jitsudo-rbac-managersubjects: - kind: ServiceAccount name: jitsudo-control-plane namespace: jitsudo-systemEOFStep 4: Configure jitsudod for Kubernetes
Section titled “Step 4: Configure jitsudod for Kubernetes”For local development, generate a kubeconfig for the jitsudo service account:
# Get the service account tokenTOKEN=$(kubectl create token jitsudo-control-plane \ --namespace jitsudo-system \ --duration 24h)
# Get the cluster CA and serverCLUSTER_CA=$(kubectl config view --raw \ -o jsonpath='{.clusters[0].cluster.certificate-authority-data}')CLUSTER_SERVER=$(kubectl config view \ -o jsonpath='{.clusters[0].cluster.server}')
# Write a kubeconfig for jitsudodcat > jitsudo-kubeconfig.yaml << EOFapiVersion: v1kind: Configclusters: - name: sandbox cluster: certificate-authority-data: ${CLUSTER_CA} server: ${CLUSTER_SERVER}contexts: - name: jitsudo context: cluster: sandbox user: jitsudocurrent-context: jitsudousers: - name: jitsudo user: token: ${TOKEN}EOFAdd the Kubernetes provider block to your jitsudod.yaml:
providers: kubernetes: kubeconfig: "./jitsudo-kubeconfig.yaml" max_duration: "2h"Restart jitsudod with make docker-up (or your equivalent).
Step 5: Apply an Eligibility Policy
Section titled “Step 5: Apply an Eligibility Policy”cat > k8s-eligibility.rego << 'EOF'package jitsudo.eligibility
import future.keywords.if
default allow = falsedefault reason = "not authorized"
allow if { input.user.groups[_] == "sre" input.request.provider == "kubernetes" input.request.role == "jitsudo-sandbox-viewer" input.request.resource_scope == "jitsudo-sandbox" input.request.duration_seconds <= 3600}
reason = "allowed" if { allow }EOF
jitsudo policy apply -f k8s-eligibility.rego \ --type eligibility \ --name k8s-sandbox-eligibilityStep 6: Submit a Real Kubernetes Request
Section titled “Step 6: Submit a Real Kubernetes Request”jitsudo request \ --provider kubernetes \ --role jitsudo-sandbox-viewer \ --scope jitsudo-sandbox \ --duration 30m \ --reason "Testing real Kubernetes provider - sandbox"The --scope value is the namespace. For a cluster-scoped binding, use --scope *.
You should see:
✓ Request submitted (ID: req_01...)⏳ Awaiting approvalStep 7: Approve the Request
Section titled “Step 7: Approve the Request”In a second terminal:
jitsudo approve req_01...Step 8: Verify the RoleBinding Was Created
Section titled “Step 8: Verify the RoleBinding Was Created”# Confirm jitsudo created the RoleBindingkubectl get rolebindings -n jitsudo-sandbox
# Inspect itkubectl describe rolebinding -n jitsudo-sandbox \ $(kubectl get rolebindings -n jitsudo-sandbox -o name | grep jitsudo)You will see a RoleBinding created by jitsudo’s service account, binding your user identity to jitsudo-sandbox-viewer in the jitsudo-sandbox namespace.
Step 9: Execute with Real Kubernetes Credentials
Section titled “Step 9: Execute with Real Kubernetes Credentials”# List pods in the sandbox namespace using the elevated bindingjitsudo exec req_01... -- kubectl get pods -n jitsudo-sandboxThe exec command injects KUBECONFIG pointing to a temporary kubeconfig that authenticates as your user identity. The RoleBinding grants get, list, and watch on pods, services, and configmaps in the sandbox namespace.
Step 10: Verify the Audit Log
Section titled “Step 10: Verify the Audit Log”jitsudo audit --request req_01...You should see request.created, request.approved, grant.issued. When the TTL expires and the sweeper runs, grant.revoked will appear and the RoleBinding will be deleted.
Step 11: Test Early Revocation
Section titled “Step 11: Test Early Revocation”jitsudo revoke req_01...Verify the RoleBinding is gone:
kubectl get rolebindings -n jitsudo-sandbox# Should return: No resources found in jitsudo-sandbox namespace.Verify access is revoked:
jitsudo exec req_01... -- kubectl get pods -n jitsudo-sandbox# Should fail: ForbiddenCleanup
Section titled “Cleanup”kubectl delete namespace jitsudo-sandboxkubectl delete clusterrole jitsudo-sandbox-viewer jitsudo-rbac-managerkubectl delete clusterrolebinding jitsudo-rbac-managerkubectl delete serviceaccount jitsudo-control-plane -n jitsudo-systemrm jitsudo-kubeconfig.yamlNext Steps
Section titled “Next Steps”- See the full Kubernetes Provider guide for production configuration, including in-cluster service account auth, namespace restrictions, and RBAC design for multi-tenant clusters
- See Security Hardening before deploying to production