ServiceAccount Token Projection Hardening Prompt
Harden Kubernetes ServiceAccount tokens — bounded projected tokens, disabling automount, audience scoping, and migrating off legacy non-expiring secret-based tokens.
- Target user
- Security-minded platform engineers locking down pod identity
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT
The prompt
You are a Kubernetes security engineer who has migrated clusters off legacy ServiceAccount secrets to bounded, audience-scoped projected tokens without breaking workloads. I will provide: - Cluster version and whether `BoundServiceAccountTokenVolume` defaults are in effect - Which workloads call the Kubernetes API vs external services (cloud IAM, Vault, mesh) - Current ServiceAccount/RBAC setup and any long-lived token Secrets in use - Pain points (over-privileged pods, leaked tokens, audit findings, third-party tools reading the default token) Work through this systematically: 1. **Audit the surface** — find pods that automount the default SA token but never call the API; list legacy `type: kubernetes.io/service-account-token` Secrets (non-expiring) still present; identify which SAs are actually used. Give the `kubectl`/jq commands. 2. **Disable needless automount** — set `automountServiceAccountToken: false` on the ServiceAccount (or per-pod) for workloads that don't talk to the API server. Explain the precedence between SA-level and pod-level settings. 3. **Projected, bounded tokens** — explain `serviceAccountToken` projected volumes with `expirationSeconds` and `audience`; how kubelet auto-rotates them; why the default API token is now short-lived and audience-bound, and what breaks for clients that cached the old token. 4. **Audience scoping** — issue separate tokens per audience (e.g., `vault`, `sts.amazonaws.com`) so a token stolen for one service can't be replayed against the API server. Show the projected-volume config and the matching TokenReview audience check. 5. **Kill legacy secrets** — safely delete the old non-expiring token Secrets, after confirming nothing reads them; explain `LegacyServiceAccountTokenCleanUp` and how to find tokens that haven't been used. 6. **Least-privilege RBAC** — pair token hardening with a scoped Role/RoleBinding per SA; never bind workloads to `cluster-admin` or broad `get secrets`. 7. **External identity** — when to drop in-cluster tokens entirely in favor of workload identity / OIDC federation (IRSA, GKE WI, SPIFFE). Output as: (a) an audit command set, (b) the hardened ServiceAccount + pod spec (automount off / projected token on), (c) audience-scoped token volume examples, (d) a phased migration off legacy secrets with rollback, (e) a policy (Kyverno/Gatekeeper or admission rule) to prevent regressions. Be explicit about what breaks for in-cluster clients when tokens become short-lived and audience-bound.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
Kubernetes RBAC Least-Privilege Role Scaffolding Prompt
Build a minimal Role/ClusterRole from an application's actual API access needs, starting from observed audit/verb usage instead of copying an over-broad cluster-admin binding.
-
Kubernetes RBAC Audit Prompt
Audit Kubernetes Role, ClusterRole, RoleBinding, and ClusterRoleBinding for excessive permissions, stale bindings, and dangerous wildcards.
-
Kubernetes Encryption-at-Rest KMS Provider Design Prompt
Design and roll out etcd encryption-at-rest with an EncryptionConfiguration and a KMS v2 provider — provider ordering, key rotation, and re-encrypting existing Secrets without downtime.
-
Ingress-NGINX Rate Limiting & Hardening Prompt
Design per-route rate limiting, connection limits, and abuse controls on ingress-nginx using annotations — including the memcached shared-state caveat, whitelist CIDRs, and how limits interact across replicas.
More Kubernetes & Helm prompts & error guides
Browse every Kubernetes & Helm prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.