The scope of secrets
Secret management covers where the credentials an application needs are stored, who can access them, and how they are changed. OWASP includes API keys, database credentials, IAM permissions, SSH keys, and certificates in this scope. This information may be present in plain text in application code or configuration files.
According to OWASP, sharing the same secret among multiple services makes it harder to determine where a leak or unauthorized access began. Centralizing secret management covers the management of storage, access, auditing, and rotation.
A user who can read or update a secret can cause it to leak either directly or through the system they use. OWASP therefore states that not everyone should have access to all secrets and that the Least Privilege principle should be applied. To do this, the management system must be able to define detailed access rules for each object and component.
Environment variables and container risk
OWASP lists the use of environment variables as one way to deliver secrets to an application in a Docker container. However, environment variables are generally accessible to all processes. They can also appear in logs or system dumps. OWASP does not recommend using environment variables unless other methods are not possible.
It is also possible to provide secrets directly in Docker container configuration. However, OWASP states that secrets should not be hardcoded using Docker ENV or Docker ARG commands. These values can easily leak along with container definitions. In the method described by OWASP, the orchestrator replaces the environment variable value, which is not hardcoded, with the actual secret.
In another method that uses files, the secret is stored in a configuration or secret file and attached to the environment where the application runs as a mounted volume. OWASP states that the orchestrator should make this attachment when needed, rather than including it in the container definition. Including the file in the container definition can cause the secret to leak along with the definition.
In another method described by OWASP, a sidecar application or container retrieves the secret directly from a secrets manager service. This method allows dynamically generated secrets to be used without concerns about their being visible through the file system or the Docker container's environment variables.
Application access through a sidecar
OWASP describes a Kubernetes setup in which a Pod contains the main application container and a sidecar container. The sidecar authenticates with the secrets manager, retrieves the secret, and writes it to a shared in-memory volume. The main application container then reads the information from this volume.
In this setup, the sidecar can refresh the secret regularly. The application container can read it from the shared volume without being directly tied to the details of the secret management solution. OWASP gives the use of a Kubernetes Service Account as an example of a method for the sidecar to authenticate with the secrets manager.
OWASP also describes a short-lived sidecar method. In this method, the sidecar retrieves secrets through a remote endpoint and places them in a shared volume attached to the main container. It terminates after retrieving the information. The containers in the Pod can use the information through this volume without being aware of the secrets manager.
If the orchestrator stores secrets internally, OWASP states that the storage infrastructure should be encrypted and its keys managed. OWASP also states that secrets should be exposed to the communication mechanisms between the container and the deployment representation, and not through external access mechanisms shared between deployments or orchestrators.
Access, lifetime, and logs
According to OWASP, a newly created secret should have sufficient cryptographic strength for its intended use. It should be granted only the minimum privileges required for the necessary use or role. Credentials must also be transmitted securely; OWASP states that secrets should not be transmitted in plain text.
The lifecycle of secrets consists of creation, rotation, revocation, and expiration. A secret that is no longer needed or may have been compromised must be revoked to limit access. OWASP also states that a specific validity period should be defined for secrets where possible.