⎈ k8s knowledge compiler

Secrets [page]deterministic

conceptssecurity

A Secret is an object that contains a small amount of sensitive data such as a password, a token, or a key. Such information might otherwise be put in a [pod](#gloss:pod) specification or in a [container image](#gloss:image). Using a Secret means that you don't need to include confidential data in your application code.

Because Secrets can be created independently of the Pods that use them, there is less risk of the Secret (and its data) being exposed during the workflow of creating, viewing, and editing Pods. Kubernetes, and applications that run in your cluster, can also take additional precautions with Secrets, such as avoiding writing sensitive data to nonvolatile storage.

Secrets are similar to [ConfigMaps](#gloss:configmap) but are specifically intended to hold confidential data.

> Caution: Kubernetes Secrets are, by default, stored unencrypted in the API server's underlying data store (etcd). Anyone with API access can retrieve or modify a Secret, and so can anyone with access to etcd. Additionally, anyone who is authorized to create a Pod in a namespace can use that access to read any Secret in that namespace; this includes indirect access such as the ability to create a Deployment.

In order to safely use Secrets, take at least the following steps:

1. [Enable Encryption at Rest](/docs/tasks/administer-cluster/encrypt-data/) for Secrets. 1. [Enable or configure RBAC rules](/docs/reference/access-authn-authz/authorization/) with least-privilege access to Secrets. 1. Restrict Secret access to specific containers. 1. [Consider using external Secret store providers](https://secrets-store-csi-driver.sigs.k8s.io/concepts.html#provider-for-the-secrets-store-csi-driver).

For more guidelines to manage and improve the security of your Secrets, refer to [Good practices for Kubernetes Secrets](/docs/concepts/security/secrets-good-practices).

See [Information security for Secrets](#information-security-for-secrets) for more details.

## Uses for Secrets

You can use Secrets for purposes such as the following:

  • [Set environment variables for a container](/docs/tasks/inject-data-application/distribute-credentials-secure/#define-container-environment-variables-using-secret-data).
  • [Provide credentials such as SSH keys or passwords to Pods](/docs/tasks/inject-data-application/distribute-credentials-secure/#provide-prod-test-creds).
  • [Allow the kubelet to pull container images from private registries](/docs/tasks/configure-pod-container/pull-image-private-registry/).

The Kubernetes control plane also uses Secrets; for example, [bootstrap token Secrets](#bootstrap-token-secrets) are a mechanism to help automate node registration.

### Use case: dotfiles in a secret volume

You can make your data "hidden" by defining a key that begins with a dot. This key represents a dotfile or "hidden" file. For example, when the following Secret is mounted into a volume, `secret-volume`, the volume will contain a single file, called `.secret-file`, and the `dotfile-test-container` will have this file present at the path `/etc/secret-volume/.secret-file`.

> Note: Files beginning with dot characters are hidden from the output of `ls -l`; you must use `ls -la` to see them when listing directory contents.

### Use case: Secret visible to one container in a Pod

Consider a program that needs to handle HTTP requests, do some complex business logic, and then sign some messages with an HMAC. Because it has complex application logic, there might be an unnoticed remote file reading exploit in the server, which could expose the private key to an attacker.

This could be divided into two processes in two containers: a frontend container which handles user interaction and business logic, but which cannot see the private key; and a signer container that can see the private key, and responds to simple signing requests from the frontend (for example, over localhost networking).

With this partitioned approach, an attacker now has to tr …(trimmed)

Sources

concepts/configuration/secret.md · doc — “Secrets”

Related (25)

references Pod — pod conf=1
references Image — container image conf=1
references ConfigMap — ConfigMaps conf=1
references Operator pattern — operator conf=1
references ServiceAccount — ServiceAccount conf=1
references Controller — controller conf=1
references Container Environment Variables — environment variables conf=1
references Static Pod — static Pods conf=1
part_of Uses for Secrets — describes conf=1
part_of Types of Secret {#secret-types} — describes conf=1
part_of Working with Secrets — describes conf=1
part_of Immutable Secrets {#secret-immutable} — describes conf=1
part_of Information security for Secrets — describes conf=1
part_of {{% heading "whatsnext" %}} — describes conf=1
part_of Use case: dotfiles in a secret volume — describes conf=1
part_of Alternatives to Secrets — describes conf=1
part_of Opaque Secrets — describes conf=1
part_of ServiceAccount token Secrets — describes conf=1
part_of Docker config Secrets — describes conf=1
part_of Basic authentication Secret — describes conf=1
part_of SSH authentication Secrets — describes conf=1
part_of TLS Secrets — describes conf=1
part_of Bootstrap token Secrets — describes conf=1
part_of Creating a Secret — describes conf=1

← all Docs