Skip to content

Secrets: KCSA practice questions

A Secret is an object that holds a small amount of sensitive data such as a password, token or key, so that the value does not have to be written into a Pod specification or baked into a container image. Secrets resemble ConfigMaps but are intended for confidential data.

By Ibrahim Yesilay · Published · Updated

Independent community practice, not affiliated with or endorsed by CNCF or The Linux Foundation.

What Secrets covers in KCSA

A Secret is an object that holds a small amount of sensitive data such as a password, token or key, so that the value does not have to be written into a Pod specification or baked into a container image. Secrets resemble ConfigMaps but are intended for confidential data. Because Secrets exist independently of the Pods that use them, there is less chance of exposing the value while Pods are created, viewed or edited, and the kubelet stores a mounted Secret in a tmpfs on the node so it is not written to durable storage. ConfigMaps are meant for non-confidential configuration and get none of this handling.

Kubernetes does not make Secret values secret by itself. The values in the data field are base64-encoded, which is an encoding, not encryption; anyone who can read the object can decode them. When writing manifests by hand, the stringData field accepts plain strings and is merged into data on write. Individual Secrets are limited to 1 MiB. Common kubectl forms are kubectl create secret generic with --from-literal or --from-file, and kubectl create secret tls with --cert and --key, which produces a Secret of type kubernetes.io/tls; for that type the API server checks that the required keys are present. Reading one value back means selecting its key with a jsonpath query and piping it through base64 -d.

By default, Secrets are stored unencrypted in etcd. Anyone with API access to a Secret, and anyone with access to etcd, can read it. Less obviously, anyone allowed to create a Pod in a namespace can read every Secret in that namespace by mounting it, including indirectly through the ability to create a Deployment. Granting list or watch on Secrets also exposes their contents, not just their names. A privileged securityContext does not by itself grant access to Secrets through the API; access is decided by authorization.

Encryption at rest is configured on the kube-apiserver with --encryption-provider-config, which points at an EncryptionConfiguration file listing resources and providers. The first provider in the list encrypts new writes, and the others are tried in order when reading. The identity provider stores plain text, so a configuration whose first provider is identity provides no encryption. Providers such as aesgcm, aescbc and secretbox use local keys, while kms delegates key management to an external service or hardware module. Existing Secrets are only encrypted once they are rewritten, for example with kubectl get secrets --all-namespaces -o json | kubectl replace -f -.

The good-practice checklist follows from this: enable encryption at rest, give least-privilege RBAC access (restrict list and watch to system components), restrict etcd access to administrators, mount Secrets only into the containers that need them, and consider an external secret store provider.

Key points

  • base64 in a Secret’s data field is encoding, not encryption.
  • Secrets sit unencrypted in etcd until encryption at rest is configured.
  • Permission to create Pods in a namespace implies the ability to read its Secrets.
  • identity as the first encryption provider means no encryption.
  • A Secret is capped at 1 MiB.

Three sample questions

13 KCSA questions on Secrets, 13 with explanations. How practice works

Question 1

Does setting 'privileged: true' on a Kubernetes pod grant it access to Kubernetes Secrets?

Select all that apply.

  1. A.Yes, it grants full access to all Secrets in the cluster
  2. B.No, it only elevates the pod's privileges on the host system but does not affect Secrets access
  3. C.Yes, but only to Secrets within the same namespace
  4. D.No, it explicitly prevents access to Secrets
  5. E.Access depends solely on RBAC permissions, regardless of privileged mode

Correct answers: B, E

Setting 'privileged: true' on a pod grants the container elevated privileges on the host system, such as access to devices and kernel capabilities, but it does not inherently grant access to Kubernetes Secrets. Access to Secrets is controlled by Kubernetes Role-Based Access Control (RBAC) policies and namespace scoping.

Sources: Kubernetes Official Documentation - Security Context, Kubernetes Official Documentation - Using RBAC Authorization

Question 2

Why is a ConfigMap not suitable for storing sensitive information such as secrets in Kubernetes?
  1. A.ConfigMaps cannot be mounted as volumes in pods
  2. B.ConfigMaps do not support key-value pairs
  3. C.Data stored in ConfigMaps is kept in plain text and not encrypted
  4. D.ConfigMaps are deprecated in recent Kubernetes versions
  5. E.ConfigMaps have strict size limitations that prevent storing secrets

Correct answer: C

ConfigMaps are designed to store non-sensitive configuration data as key-value pairs and store data in plain text within etcd. They do not provide encryption or access controls suitable for sensitive information. Secrets, on the other hand, are specifically designed to store sensitive data and can be encrypted at rest. ConfigMaps can be mounted as volumes and are not deprecated. While ConfigMaps have size limits, the primary reason they are unsuitable for secrets is the lack of security.

Sources: Kubernetes Official Documentation - ConfigMaps, Kubernetes Official Documentation - Secrets

Question 3

Which Kubernetes object is specifically designed to store sensitive information such as passwords, tokens, or keys?
  1. A.ConfigMap
  2. B.Secret
  3. C.Volume
  4. D.Pod Annotation
  5. E.Deployment

Correct answer: B

Kubernetes Secrets are intended to store sensitive data like passwords, OAuth tokens, and SSH keys securely. Unlike ConfigMaps, which store non-sensitive configuration data, Secrets provide mechanisms to protect this sensitive information, including base64 encoding and integration with encryption at rest. Volumes, Pod Annotations, and Deployments are not designed for securely storing sensitive data.

Sources: Kubernetes Official Documentation - Secrets, Kubernetes Best Practices - Managing Secrets

Practice this topic

Focus mode keeps every question on Secrets until you leave it. 10 free guest answers, then a free account; no credit card.

Or open KCSA practice across all topics.

Sources

The explanation above was checked against these official documents.