logo
Infisical
Blog post 9 min read

What are Kubernetes Secrets?

Published on
Blog image

Every organization running Kubernetes faces the same critical challenge: how do you securely manage passwords, API keys, certificates, and other sensitive data without embedding them directly in your application code or container images? Kubernetes Secrets promise an elegant solution, but there’s a problem most teams only discover when it’s too late.

The Bottom Line up Front: Kubernetes Secrets provide essential credential management capabilities, but they’re stored unencrypted in etcd by default and can be accessed by anyone who can create Pods in a namespace. Real security requires an additional configuration and often interoperating with external tools.

The Promise and the Problem

When you first encounter Kubernetes Secrets, they seem like the perfect answer to credential management. Instead of hardcoding database passwords in your deployment YAML or baking API keys into container images, Secrets let you store sensitive data as separate objects that Pods can consume at runtime.

The appeal is immediate: clean separation of concerns, no more credentials scattered across configuration files, and built-in integration with the Kubernetes ecosystem. Secrets can be injected as environment variables, mounted as files, or used to authenticate with private container registries. Basically, security by design.

But here’s what the documentation doesn’t emphasize: Kubernetes Secrets are stored unencrypted in the API server’s underlying data store (etcd) by default. Anyone with API access can retrieve or modify a Secret, and anyone authorized to create a Pod in a namespace can read any Secret in that namespace.

This isn’t a bug, it’s the default behavior. The “security” in Kubernetes Secrets comes primarily from access control and operational practices, not from the storage mechanism itself. Understanding this distinction is crucial for building truly secure applications.

Consider the real-world implications: if an attacker gains access to your etcd database or compromises a Pod with overly broad permission, they can access every secret in your cluster. This has led to numerous high-profile breaches where organizations believed their credentials were secure simply because they were using Kubernetes Secrets.

Understanding the Mechanisms

To use Secrets effectively, you need to understand what’s actually happening under the hood. Kubernetes Secrets are objects that store key-value pairs, where the values are base64-encoded strings. This encoding is often mistaken for encryption, but base64 is simply a way to represent binary data as text. Anyone can decode it instantly.

When you create a Secret with a password like my-super-duper-secret-password, Kubernetes stores it as bXktc3VwZXItZHVwZXItc2VjcmV0LXBhc3N3b3Jk . This may look secure, but simply running echo "bXktc3VwZXItZHVwZXItc2VjcmV0LXBhc3N3b3Jk" | base64 -d in any terminal immediately reveals the original value.

Kubernetes provides several built-in Secret types for common use cases. **Opaque Secrets** are the default type for arbitrary user-defined data. TLS Secrets store certificates and private keys for HTTPS connections. Docker config Secrets hold container registry credentials. Basic authentication and SSH authentication Secrets store their respective credential types. Each type enforces specific data field requirements but follows the same underlying storage model.

The kubelet handles Secrets carefully during runtime, storing them in memory-only tmpfs (temporary file systems) and deleting them when Pods terminate. However, this runtime protection doesn’t address the fundamental underlying issue: the Secrets are sitting unencrypted in etcd, accessible to anyone with sufficient cluster permissions.

Secrets also have a 1MB size limit, designed to prevent memory exhaustion in the API server and kubelet. While the constraint rarely affects typical use cases like passwords or API keys, it can impact scenarios involving large certificates or configuration files.

Implementation Patterns

Kubernetes offers three primary ways to use Secrets in your applications, each suited to different use cases and security requirements.

Environmen**t Variables** provide the most straightforward integration path. You reference a Secret key using secretKeyRef in your Pod specification, and Kubernetes injects the value as an environment variable at runtime. This works well for applications expecting configuration through environment variables, but comes with security trade-offs: environment variables are visible to any process running in the container and may appear in process lists or logs.

Volume Mounts offer more granular controls by mounting Secret data as files in the container filesystem. Each Secret key becomes a separate file, with the key name as the filename and the decoded value as the file contents. This approach provides better security isolation since file access can be controlled with standard Unix permissions, and Secret updates are automatically propagated to mounted volumes.

ImagePullSecrets serve a specialized but critical function: authenticating with private container registries. When specified in a Pod’s imagePullSecrets field, the kubelet uses these credentials to pull container images before starting the Pod. This mechanism is essential for organizations using private registries but often overlooked in security assessments.

Creating Secrets supports multiple workflows that fit different operational models. The kubectl create secret command provides immediate, imperative creation for development and testing. Declarative YAML manifests enable version control and GitOps workflows, though they require pre-encoding sensitive values with base64. Tools like Kustomize can generate Secrets from files or literal values without manual encoding, making them popular for CI/CD pipelines.

Each approach has implications for secret rotation and lifecycle management. Secrets created imperatively with kubectl can be difficult to track and update consistently across environments. Declarative approaches provide better audibility but require careful handling of sensitive data in version control systems.

The Security Reality Check

The gap between perception and reality in Kubernetes Secret security creates significant risks for production environments. While Secrets provide operational benefits over hardcoded credentials, they introduce new attack vectors that many teams fail to address.

Default vulnerabilities stem from the unencrypted etcd storage. Any process with etcd access, including backup systems, monitoring tools, or compromised master nodes, can extract all cluster Secrets. Database dumps, snapshots, and log files may inadvertently contain sensitive data. This risk multiplies in managed Kubernetes services where multiple teams may have administrative access.

**RBAC limitations** create additional exposure. The Kubernetes permission model operates at the Secret object level, not individual keys within Secrets. A Pod that needs access to one piece of data in a Secret can read all data in that Secret. Service accounts with broad permissions can access Secrets across multiple namespaces, and the default service account in each namespace can be used to read Secrets if not properly restricted.

Namespace boundaries provide less isolation than commonly assumed. While Secrets are namespace-scoped, cluster-level permissions can override these boundaries. Network policies, admission controllers, and monitoring systems often require cross-namespace access that can inadvertently expose Secrets. The shared etcd backend means that compromise at the infrastructure level affects all namespaces simultaneously.

Attack scenarios in real environments often exploit these architectural decisions. Compromised Pods with overly broad service account permissions can access unrelated Secrets. Malicious container images can read mounted Secrets and exfiltrate them through network connections. Insider threats become more dangerous when a single compromise provides access to credentials across multiple applications and environments.

The performance implications of Secrets at scale reveal additional security considerations. Clusters with tens of thousands of Secret-to-Pod mounts experience significant load on the kube-apiserver. This has led some organizations to consolidate Secrets inappropriately, increasing the blast radius of potential compromises.

Production-Ready Secret Management

Securing Kubernetes Secrets for production requires a layered approach that addresses both configuration and architectural limitations.

Encryption at rest represents the most critical first step. Kubernetes supports encrypting Secret data in etcd using AES-256 or other algorithms, but this must be explicitly configured during cluster setup. The encryption keys themselves require careful management, they should be stored in hardware security models (HSMs) or external key management services, and never on the same systems as the encrypted data.

**Least-privilege access control** demands granular RBAC policies that restrict Secret access to only the Pods and users that absolutely require it. Service accounts should follow the principle of least privilege, with separate accounts for different applications and environments. Regular audits of Secret access patterns can reveal overly broad permissions or unusual access patterns that may indicate compromise.

External secret management has emerged as the preferred approach for enterprise environments. Tools like Infisical provide dedicated secret storage with features like automatic secret rotation, detailed audit logs, and integration with existing identity systems. The Kubernetes Secrets Store CSI Driver enables Pods to mount secrets from external providers without persisting them in etcd.

The External Secrets Operator represents a popular middle-ground approach, synchronizing secrets from external providers into Kubernetes Secrets while maintaining native integration patterns. This allows teams to leverage external secret management capabilities while preserving existing application integration code.

**Secret rotation** strategies become critical at scale. Manual rotation processes don’t scale and create opportunities for human error. Automated rotation requires coordination between secret generation, distribution, and application restart patterns. Short-lived secrets reduce exposure windows but require more sophisticated refresh mechanisms.

Monitoring and auditing provide essential visibility into secret usage patterns. Kubernetes audit logs should capture Secret access events, but the high volume of events requires careful filtering and analysis. Anomaly detection can identify unusual access patterns, such as Secrets being read by unexpected service accounts or at unusual times.

For multi-environment deployments, separate secret management boundaries become essential. Development, staging, and productions environments should use completely separate secret stores and access control systems. This prevents accidental cross-environment access and limits the impact of compromises in lower-security environments.

Building a Secret Strategy

Effective Kubernetes secret management requires matching your approach to your organization’s security requirements, operational maturity, and scale.

For development and testing environments, native Kubernetes Secrets with basic RBAC controls may suffice. Focus on establishing good practices around secret creation and access patterns that will scale to production. Avoid putting productions credentials in development clusters, even if they’re “properly secured”.

For production environments, external secret management integration is typically necessary to meet enterprise security requirements. Start with encryption at rest for native Secrets, implement comprehensive RBAC policies, and plan migration to external providers. Consider compliance requirements early. Many regulatory frameworks require specific audit trails and access controls that native Secrets can’t provide.

Implementation priorities should focus on the highest-risk scenarios first. Container registry credentials and database passwords represent common high-value targets. TLS certificates for ingress controllers affect availability and user trust. API keys for external services may provide access to customer data or billing systems.

The path forward isn’t about avoiding Kubernetes Secrets, they remain an essential part of the container orchestration ecosystem. Instead, success comes from understanding their limitations, implementing appropriate safeguards, and choosing the right tools for your security requirements.

Kubernetes Secrets solve real operational problems around credential distribution and lifecycle management. However, treating them as a complete security solution creates dangerous gaps in your defense strategy. By understanding both their capabilities and limitations, you can build secret management practices that provide genuine security without sacrificing operational efficiency.

The stakes are too high to rely on defaults. Your applications, your data, and your customers depend on getting this right.

avatar

Mathew Pregasen

Technical Writer

Starting with Infisical is simple, fast, and free.
Full Infisical Logo

PRODUCT

Secret Management

Secret Scanning

Share Secret

Pricing

Security

RESOURCES

Blog

Infisical vs Vault

Careers

Hiring

Forum

Open Source Friends

Customers

Company Handbook

Trust Center

LEGAL

Terms of Service

Privacy Policy

Subprocessors

Service Level Agreement

CONTACT

Team Email

Sales

Support