Repository navigation
Workload Identity and Secrets
Last reviewed: 2026-11-28 (bound-token RBAC behaviour observed in k8s-admission lab CI run 46226561778; encryption at rest, external secret stores and cloud workload identity are from vendor and project documentation and were not tested here)
Prerequisites: Kubernetes security Β· Kubernetes admission, RBAC & network policy Β· Conditional access & workload identities.
Explain how Kubernetes workloads prove who they are, how to keep their credentials short-lived, and how to protect Secret objects at rest and outside the cluster.
Covers bound ServiceAccount tokens, encryption of Secrets in etcd, external secret stores (External Secrets Operator and the Secrets Store CSI Driver), and the managed workload identity features of EKS, GKE and AKS.
Let a reader remove long-lived credentials from Pods, encrypt Secrets at rest with a key held outside etcd, and map a Pod's identity to a cloud role with the narrowest possible trust.
- Reviewing how a workload authenticates to the API server or to a cloud provider
- Enabling or auditing Secret encryption at rest
- Choosing between native Secrets and an external secret store
- ServiceAccount Tokens
- Secrets At Rest
- External Secret Stores
- Cloud Workload Identity
- Review Checklist
- See also
Since v1.22 the kubelet mounts a short-lived, automatically rotating token from the TokenRequest API as a projected volume (service accounts). Older Secret-based tokens "don't expire and don't rotate" and are not recommended. Automatic generation of them was switched off by the LegacyServiceAccountTokenNoAutoGeneration feature gate, which went GA in v1.26 and was later removed (the feature-gate reference lists it as stable from v1.26 to v1.28).
Controls:
-
Do not mount a token the workload does not use. Set
automountServiceAccountToken: falseon the ServiceAccount or the Pod; the Pod setting wins. The lab's ServiceAccount and Pods all set it. -
Request a token for a specific audience and lifetime when a workload talks to something other than the API server (configure service accounts):
volumes: - name: vault-token projected: sources: - serviceAccountToken: path: vault-token expirationSeconds: 7200 audience: vault
-
Issue short tokens by hand only for tests. The lab used
kubectl create token lab-reader -n k8s-lab-rbac --duration 10mand called the API with it:list podssucceeded andlist secretswasForbidden.kubectl create tokencan also bind a token to an object with--bound-object-kind,--bound-object-nameand--bound-object-uid, so it stops working when that object is deleted. -
Scope RBAC per ServiceAccount. A token is only as dangerous as the roles bound to it. See RBAC design.
A Secret is base64-encoded, not encrypted. Unless the API server is started with --encryption-provider-config, it stores resources in etcd in plain text. From Encrypting confidential data at rest:
| Provider | Notes from the docs |
|---|---|
identity |
The default. It "does not encrypt stored data and provides no additional confidentiality protection" |
aescbc, aesgcm, secretbox
|
Local keys in the config file. Protects against an etcd compromise but "fails to protect against a host compromise", because the keys sit on the control plane host |
kms v1 |
Deprecated since v1.28 |
kms v2 |
Envelope encryption: a per-resource data key, wrapped by a key encryption key held in an external KMS. An attacker needs etcd and the KMS |
The first provider in the list encrypts new writes; on reads, each provider that matches the stored data attempts decryption in order. The documented example for a self-managed control plane:
apiVersion: apiserver.config.k8s.io/v1
kind: EncryptionConfiguration
resources:
- resources:
- secrets
providers:
- aescbc:
keys:
- name: key1
secret: <BASE 64 ENCODED SECRET> # head -c 32 /dev/urandom | base64
- identity: {} # fallback that allows reading unencrypted secrets during migrationEnabling encryption does not rewrite what is already stored. The docs give this command, run as an administrator that can read and write all Secrets:
kubectl get secrets --all-namespaces -o json | kubectl replace -f -The docs verify the result by reading the raw etcd value and checking it starts with k8s:enc:aescbc:v1:. Restrict the config file so only the user running kube-apiserver can read it. Managed services (EKS, GKE, AKS) expose their own envelope-encryption settings; check the provider's documentation rather than editing API server flags.
Note
Encryption at rest was not configured or tested in the repository's kind lab. kind does not document an encryption setup.
Keeping the source of truth in a dedicated secret manager gives you rotation, access logs and revocation that Kubernetes Secrets lack.
| Project | Latest release (2026-11-28) | Model |
|---|---|---|
| External Secrets Operator | v2.15.0 | Controller that syncs values from an external store into Kubernetes Secrets. CNCF Sandbox project |
| Secrets Store CSI Driver | v1.6.2 | "A subproject of Kubernetes SIG Auth". Mounts secrets into Pods as a volume through a SecretProviderClass; provider plugins exist for AWS, Azure, GCP and Vault |
Trade-off: a synced Kubernetes Secret still lands in etcd (so still needs encryption at rest and tight RBAC), while a CSI mount delivers the value as a file; the driver's README lists optional "sync with Kubernetes Secrets", which puts the value back in etcd if you turn it on. Either way, the operator or driver's own identity to the secret store becomes a high-value credential. Give it workload identity, not a static key.
Each managed Kubernetes service maps a ServiceAccount to a cloud identity using a projected token. None of these were tested in this repository.
| Service | Feature | How the trust is expressed | Notes from vendor docs |
|---|---|---|---|
| Amazon EKS | EKS Pod Identity | An association of an IAM role with a namespace and ServiceAccount; role trust principal "Service": "pods.eks.amazonaws.com"
|
Agent DaemonSet uses host networking on 169.254.170.23 (IPv4) and [fd00:ec2::23] (IPv6). Not available on Fargate, Windows, Outposts, EKS Anywhere or self-managed clusters on EC2 |
| Amazon EKS | IAM roles for service accounts (IRSA) | IAM OIDC provider plus sts:AssumeRoleWithWebIdentity; trust conditions on <provider>:sub = system:serviceaccount:<ns>:<sa> and <provider>:aud = sts.amazonaws.com
|
ServiceAccount annotation eks.amazonaws.com/role-arn
|
| Google GKE | Workload Identity Federation for GKE | IAM principal principal://iam.googleapis.com/projects/PROJECT_NUMBER/locations/global/workloadIdentityPools/PROJECT_ID.svc.id.goog/subject/ns/NAMESPACE/sa/SERVICEACCOUNT
|
Pods with hostNetwork: true do not use it. Enabling it grants no IAM permissions by itself |
| Azure AKS | Microsoft Entra Workload ID | Federated identity credential on a managed identity (max 20 per identity); audience api://AzureADTokenExchange
|
ServiceAccount annotation azure.workload.identity/client-id, Pod label azure.workload.identity/use: "true". Read the token path from AZURE_FEDERATED_TOKEN_FILE; pod-managed identity is something to migrate away from |
The IRSA annotation, as documented by AWS (placeholder account ID from the AWS docs):
kubectl annotate serviceaccount -n "$namespace" "$service_account" \
eks.amazonaws.com/role-arn=arn:aws:iam::111122223333:role/my-roleReview the cloud side the same way as GitHub Actions OIDC: the sub must name one namespace and ServiceAccount, never a wildcard that admits every workload. The AWS IRSA page shows that StringLike with * lets every ServiceAccount in a namespace assume the role. The Cloud identity guide covers trust-policy review in more depth.
Warning
Workload identity narrows which credentials a Pod should use. It does not by itself stop a Pod from reaching node-level credentials, such as an instance metadata endpoint, if the platform and network policy allow it. Check what a Pod can reach as well.
- Pods that do not call the API server set
automountServiceAccountToken: false. - No legacy
kubernetes.io/service-account-tokenSecrets remain in use. - Projected tokens for external services set
audienceand a shortexpirationSeconds. - Secret encryption at rest is enabled with a KMS-backed provider, and existing Secrets were rewritten after enabling it.
- RBAC on
secretsis limited to the workloads and operators that need it. - Cloud trust policies pin namespace and ServiceAccount exactly.
- External secret operators authenticate with workload identity, not static keys.
- Kubernetes admission, RBAC & network policy: role design and the bound-token lab cases
- Conditional access & workload identities: federation trust for GitHub Actions and clouds
- CI/CD threat model & GitHub Actions: secrets handling in pipelines
- Container runtime detection: alerting on Secret access
- README.md - Container & Kubernetes Security section index
- kubernetes.md - Secrets and attack paths
- ../Cloud/README.md - Cloud security (EKS/AKS/GKE)
β¬ οΈ Back to Master Index | π― Role Navigation | Legal Notice
π Source: ContainerSecurity/workload-identity-and-secrets.md | βοΈ Suggest an edit | β¬
οΈ Back to Container Security
- πΊοΈ Browse by Topic
- π All Repository Files
- π§ Learning Paths
- π Master Guide
- π€ Glossary
- βοΈ Legal & Disclaimer
π Foundations & Learning
π‘οΈ Defense & Investigations
- Incident Response
- Open Source Intelligence (OSINT)
- Reverse Engineering
- Operations Security (OPSEC)
- Compliance
βοΈ Platforms & Infrastructure
π‘ Hardware, Wireless & Field Projects
- PNWC Cyberdeck
- Hardware Testing
- Hardware Hacking
- Software-Defined Radio
- Wardriving
- uConsole
- Space Security
π§° Assessment & Field Reference
π¦ Downloads & Project Resources
ποΈ Additional Topics