Are Kubernetes Secrets Safe?

Are Kubernetes Secrets Safe? Kubernetes Secrets offer a way to store and manage sensitive information. However, it is crucial to understand their limitations and how to properly protect them. Let’s explore their features and examine how the

Source comparison and review notes
  • Automated pair-review warning (AI bilingual content review): Both describe etcd/API access together with Kubernetes RBAC; Kubernetes RBAC governs Kubernetes API access, while direct etcd access uses separate datastore controls, so the access-control wording is imprecise.

Kubernetes Secrets offer a way to store and manage sensitive information. However, it is crucial to understand their limitations and how to properly protect them. Let’s explore their features and examine how they work based on official documentation from Kubernetes and cloud providers.

What are Secret Objects?

A Secret in Kubernetes is an object that stores sensitive data such as passwords, tokens, or SSH keys. This resource allows sensitive information to be passed to Pods or containers without exposing it in the application code. These values can be accessed through volume mounts or environment variables.

Types of Secrets

The default type of Secret is Opaque, used when no specific type is provided. When creating a secret using kubectl, the "generic" subcommand is used to specify the Opaque type.

Bash
kubectl create secret generic empty-secret

Other types of Kubernetes Secrets include:

Plain text
Opaque
kubernetes.io/service-account-token
kubernetes.io/dockercfg
~/.dockercfg
kubernetes.io/dockerconfigjson
~/.docker/config.json
kubernetes.io/basic-auth
kubernetes.io/ssh-auth
kubernetes.io/tls
bootstrap.kubernetes.io/token

Secrets vs. ConfigMaps

While ConfigMaps are designed to store non-sensitive data, Secrets are meant to store sensitive information. It’s essential to use Secrets for confidential data like credentials, rather than ConfigMaps.

So, Are They Safe?

By default, the values of Kubernetes Secrets are encoded (in base64) but not encrypted. Secrets are stored in etcd, Kubernetes' key-value database, in an encoded format. However, encoding is not encryption, meaning that anyone with access to the etcd API and necessary permissions can easily decode Secrets using a simple base64 command.

Bash
echo <encoded_secret> | base64 --decode

Base64 encoding adds an additional layer of confidentiality but does not provide true encryption or security.

Best Practices for Managing Secrets in Kubernetes

Several best practices help improve the security of Kubernetes Secrets, often complementing the overall security of the cluster.

Encryption at Rest

While etcd does not encrypt Secrets by default, you can enable encryption at rest for stored data. This adds an extra security layer by ensuring that sensitive data is encrypted before it’s written to disk.

For more information: Encrypting Confidential Data at Rest | Kubernetes

Configure Least-Privilege Access to Secrets

Plan your access control using Kubernetes Role-Based Access Control (RBAC) to minimize access to Secrets:

  • Components: Limit access to only the most privileged components. Only grant “watch” or “list” permissions if absolutely necessary.
  • Users: Restrict “get,” “watch,” and “list” permissions to Secrets. Only cluster administrators should have access to etcd, including read-only access.

Use Third-Party Tools

Kubernetes recommends using third-party tools for Secret management, such as integrating with Secret Managers offered by cloud providers.

Avoid Sharing Secrets in Source Control

Never hardcode Secret values in source code management (SCM) systems or expose them in application manifests. Always reference Secrets from external sources using secure files or environment variables in your deployment pipelines.

How Do Cloud Providers Handle Secrets?

Let’s review the security features and integrations provided by Azure Kubernetes Service (AKS) and Google Kubernetes Engine (GKE) for managing Secrets.

Encryption at Rest

Both GKE and AKS offer encryption at rest for Secrets stored in etcd by default. Additionally, both platforms allow the use of customer-managed keys (KMS) for encryption:

GKE also allows CMEK (Customer-Managed Encryption Keys) for application-level encryption.

Cloud Secrets Manager Integration

Both platforms offer integration with their native secret management services.

GKE: Secret Manager Integration

GKE integrates with Google Cloud Secret Manager via the Secret Manager Add-on:

  • Secret Manager Add-on for GKE

AKS: Azure KeyVault Integration

AKS integrates with Azure Key Vault using the Secrets Store CSI Driver:

Both integrations utilize the Secrets Store CSI Driver, allowing Kubernetes to mount secrets stored in external secret management systems directly into Pods.


Written by Mateo Di Loreto

Thanks for reading. The learning continues in the next article.