SecurityKubernetes
Kubernetes Secrets: encryption at rest and who can read them
Secret values are base64-encoded strings, and Kubernetes stores them unencrypted in etcd by default. Encryption at rest protects that copy. Anyone who is allowed to create a pod in a namespace can still read every Secret in it.

What base64 does and does not do
The values for all keys in the data field of a Secret have to be base64-encoded strings. The Kubernetes documentation decodes the data of its example Secret, secret-tiger-docker, like this:
kubectl get secret secret-tiger-docker -o jsonpath='{.data.*}' | base64 -dThe same page describes a base64 value as obscured but not secret.
By default, Secrets are stored unencrypted in etcd, the API server's underlying data store. A Secret can be read or changed by anyone who has API access, and equally by anyone who can reach etcd.
Encryption at rest on self-managed clusters
The kube-apiserver process accepts the argument --encryption-provider-config, the path to an EncryptionConfiguration file. Each entry in the file names resources and an ordered list of providers. The first provider in the list encrypts resources written to storage. On a read, each provider that matches the stored data tries in order to decrypt it.
identitywrites resources as-is, with no encryption. It is the default.aescbc,aesgcmandsecretboxtake their key from the configuration file, so the key material is accessible from the control plane host. The documentation says a locally managed key protects against an etcd compromise and fails to protect against a host compromise. It does not recommendaescbc, and recommendsaesgcmonly with an automated key rotation scheme.kmsuses envelope encryption. Data is encrypted with a data encryption key, and that key is encrypted with a key encryption key that a remote KMS stores and manages. To reach the plain text, an attacker would need to compromise etcd and the KMS provider.
Kubernetes deprecated KMS v1 in v1.28 and turned it off by default in v1.29. KMS v2 is stable since v1.29, and Kubernetes recommends it.
apiVersion: apiserver.config.k8s.io/v1
kind: EncryptionConfiguration
resources:
- resources:
- secrets
providers:
- kms:
apiVersion: v2
name: myKmsPluginFoo
endpoint: unix:///tmp/socketfile-foo.sock
timeout: 3s
- identity: {}The kms entry comes from the documented KMS v2 example. Replace name and endpoint with the name and the socket of your own plugin. The endpoint is the listen address of the KMS plugin's gRPC server, a UNIX domain socket. The configuration should be identical on every control plane node.
Existing Secrets and how to verify
Data is encrypted when it is written to etcd. A Secret stored before the change stays unencrypted until it is next written. The documented command reads all Secrets and writes them back:
kubectl get secrets --all-namespaces -o json | kubectl replace -f -To verify, the documentation reads a Secret out of etcd with etcdctl. A value encrypted by the KMS v2 provider is prefixed with k8s:enc:kms:v2:.
The identity: {} entry at the end of the list allows unencrypted data to be read. Once all resources are encrypted, remove it. The API server then no longer honors unencrypted data.
What EKS, AKS and GKE do
- Amazon EKS: clusters that run Kubernetes 1.28 or higher get envelope encryption for all Kubernetes API data by default. EKS uses KMS v2 with an AWS owned key, and you have the option to bring your own customer managed key from AWS KMS.
- Azure AKS: Azure Storage encrypts all data at rest, and that encryption is always enabled. KMS provider encryption, with keys stored in Azure Key Vault, is an optional layer that encrypts Secrets before they are written to etcd.
- Google GKE: GKE encrypts customer content at rest by default, Secrets included. Application-layer secrets encryption adds a key that you manage in Cloud KMS. You enable it with the
--database-encryption-keyflag ofgcloud container clusters create,create-autoorupdate.
RBAC on Secrets
A Secret retrieved through the API is decrypted first.
A subject with list or watch on Secrets can read the data of every Secret in that namespace. The documentation says to restrict watch and list to the most privileged, system-level components, and to grant get only where a component's normal behavior requires it.
The resourceNames field restricts a rule to individual instances of a resource. This Role follows the documented ConfigMap example, with secrets as the resource:
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
namespace: default
name: secret-reader
rules:
- apiGroups: [""]
resources: ["secrets"]
resourceNames: ["db-user-pass"]
verbs: ["get"]Who else can read a Secret
- Anyone who is authorized to create a pod in the namespace. With that right a user can read every Secret in the namespace. Indirect routes count as well, the right to create a Deployment for one.
- Privileged containers. A container with
privileged: truehas access to every Secret in use on its node.
The documented way to isolate access to mounted Secrets is to use separate namespaces.
What to check in your cluster
- On your own control plane, look at the API server's arguments. With no
--encryption-provider-config, encryption at rest is not enabled. The same is true whenidentityis the first provider in the file. - Guard the KMS key. AKS documents that deleting the encryption key or the key vault makes the Secrets unrecoverable. EKS documents that deleting the customer managed key degrades the cluster beyond recovery.
- Follow the documented good practice for audit: write audit rules that raise an alert on specific events. One user reading several Secrets at the same time is the documented example.
Sources
- Secrets
- Encrypting Confidential Data at Rest
- Using a KMS provider for data encryption
- Good practices for Kubernetes Secrets
- Using RBAC Authorization
- Default envelope encryption for all Kubernetes API Data
- Data encryption at rest concepts for Azure Kubernetes Service (AKS)
- Encrypt secrets at the application layer
Want a second pair of eyes on yours? We do this work for a living.
More guides

Kubernetes RBAC: five rules for least privilege
Security · 2 min read
Groups over users, namespaces over clusters, and how to test what an account can do.

Secrets in GitOps: Sealed Secrets, SOPS or External Secrets Operator
GitOps · 4 min read
Sealed Secrets, SOPS and External Secrets Operator, with the documented facts for each side by side.

Kubernetes audit logs: what to record and what to look for
Security · 4 min read
Audit levels, an example policy, where managed clusters send the log, and what to search for.