Posted by Joyce Ling
December 19, 2024
In Kubernetes environments, securing sensitive data such as API keys, passwords, and credentials is crucial. Kubernetes secrets management, which stores and handles this information, plays a key role in maintaining the security and integrity of applications and services. However, traditional methods of managing Kubernetes secrets often fall short in meeting security and compliance needs, especially in multi-cloud and hybrid environments.
These limitations include weak encryption capabilities, insufficient access controls, and challenges in auditing and monitoring secret access. Organizations also face complications with data residency and sovereignty, especially as Kubernetes clusters are spread across multiple regions. Together, these issues can expose secrets to unauthorized users or systems, compromising the overall security posture.
Key Challenges Using Kubernetes Secrets
Limited Encryption Capabilities in Kubernetes
By default, Kubernetes secrets are encoded in Base64, but this encoding is not a form of encryption. Base64 encoding is easily reversible and does not provide any real security benefits. For example, consider the following YAML file that defines a Kubernetes secret:
apiVersion: v1
kind: Secret
metadata:
name: example-secret
type: Opaque
data:
password: cGFzc3dvcmQ= # Base64 encoded "password"
In this example, the `password` field is Base64-encoded, so if an attacker gains access to the Kubernetes API or etcd (where secrets are stored), they can easily decode the Base64 data to retrieve the plaintext password.
To enhance security, Kubernetes supports encryption at rest for secrets. This requires configuring an encryption provider in the Kubernetes API server configuration. Here’s a sample configuration for enabling encryption at rest using AES-CBC:
apiVersion: apiserver.config.k8s.io/v1
kind: EncryptionConfig
resources:
- resources:
- secrets
providers:
- aescbc:
keys:
- name: key1
secret: <32-byte-base64-encoded-key>
- identity: {}
However, this is just one small part of the whole long process of achieving proper management of secrets at rest using native Kubernetes tools. And doing this at scale, with multiple clusters in a variety of environments, would require a lot of time and patience, not to mention ensuring mistakes aren’t made in the process.
Insufficient Access Controls in Kubernetes
Kubernetes’ native access control mechanisms for secrets are limited to role-based access control (RBAC) and can be insufficient for fine-grained control. For instance, a Kubernetes Role can be configured to grant access to secrets, but it might not provide the necessary restrictions to limit access to specific secrets or operations.
Here’s an example of a Kubernetes Role that allows reading secrets:
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: secret-reader
rules:
- apiGroups: [""]
resources: ["secrets"]
verbs: ["get", "list"]
In this case, any user or service account with the role can access all secrets within the namespace. This broad access increases the risk of exposing sensitive data to unintended users or services.
Challenges for Large Organizations
Managing numerous roles for different teams, environments, and applications can result in role overload. Defining custom access for each user creates a “role explosion,” which becomes increasingly difficult to manage and audit. Additionally, maintaining the necessary bindings (RoleBindings and ClusterRoleBindings) for each role adds complexity, and errors in this process can lead to unauthorized access.
Decentralized Access Control
Kubernetes RBAC decentralizes access control with namespace-scoped policies by default, adding further complexity. Managing access across multiple clusters and namespaces becomes cumbersome. The lack of a centralized RBAC management system makes consistent policy enforcement difficult.
The Risk of Over-Permissioning
Without centralized control and granular access, organizations may create overly broad roles to simplify management. This can result in unintended access to secrets, leading to security gaps. Furthermore, coordinating between teams to define roles can lead to inconsistent policies and missed audits.
Audit and Monitoring of Secret Access in Kubernetes
Kubernetes does not natively provide detailed audit logging specifically for secret access. This makes it difficult to monitor who accessed or modified secrets. In multi-cloud environments, this lack of detailed audit trails can hinder the ability to conduct thorough compliance audits and track access to sensitive data.
Each cloud provider offers its own monitoring and logging solutions, such as AWS CloudTrail, Google Cloud Audit Logs, and Azure Monitor. Integrating these tools to track access to Kubernetes secrets uniformly across environments is complex and often incomplete, leading to potential blind spots.
Data Residency and Sovereignty Compliance in Kubernetes
Kubernetes clusters in multi-cloud and hybrid environments might be spread across different geographical regions, each with its own data residency and sovereignty laws. Ensuring that secrets are stored and accessed in compliance with these regulations is a challenge, especially when secrets must remain within specific regions.
Managing secrets consistently across clusters while adhering to data residency requirements can be difficult. You might need to replicate secrets across clusters for applications to function correctly. However, organizations have to replicate carefully to avoid compliance violations.
To address all these limitations for Kubernetes secrets, organizations often employ external secret management solutions that provide more sophisticated encryption and access control features.
Use an External Secrets Manager for Kubernetes Secrets Management
An external secrets manager (ESM) like Akeyless helps secure secrets across multi-cloud and hybrid Kubernetes deployments in large organizations. ESMs can provide centralized, scalable, and secure management of sensitive data. Here’s how external secrets managers address the challenges posed by Kubernetes secrets.
Centralized Secrets Management
Secret Managers provide a single, central repository for managing secrets, keys, and certificates across multiple Kubernetes clusters, clouds, and on-premises environments. This centralization simplifies managing access policies, reduces administrative overhead, and ensures consistent security controls across all environments.
Organizations can also define unified access control policies that apply consistently across all deployments, regardless of the underlying infrastructure. This eliminates the complexity of managing multiple, decentralized RBAC policies in Kubernetes and provides a single source of truth for secrets management across the organization.
Enhanced Security and Encryption
External managers use advanced encryption methods, such as AES-256 and FIPS 140-2 compliant encryption modules, to protect secrets both at rest and in transit. Unlike native Kubernetes secrets, which may have limited encryption capabilities, Akeyless and other secrets managers fully protect secrets with strong cryptography.
Secret Managers operate under a zero-trust model, ensuring that organizations don’t expose sensitive data to unauthorized users. Akeyless specifically employs a patented Distributed Fragments Cryptography (DFC) solution to securely generate and manage encryption keys as fragments without storing the entire key in any single location at any time, significantly reducing the risk of unauthorized access.
Granular Access Controls and Auditing
External Secret Managers have highly granular access control policies, tailored to specific users, roles, applications, or services. You can manage policies centrally and apply them consistently across multiple clusters and environments. This ensures that only authorized identities have access to specific secrets. This relieves Kubernetes admins of having to create role-based access controls inside of Kubernetes in order to retrieve secrets.
They also provide detailed auditing and monitoring capabilities. This enables organizations to track who accessed which secrets, when, and for what purpose. This is essential for meeting compliance requirements, conducting security audits, and maintaining visibility over secrets usage across all environments.
Seamless Secrets Injection for Kubernetes and CI/CD Pipelines
Another important aspect is integrating seamlessly with Kubernetes. This allows pods to securely retrieve secrets without storing them in the cluster, but rather, injects them at runtime. This reduces the attack surface by eliminating the need to store secrets directly in Kubernetes.
Secret Managers also integrate with CI/CD tools and workflows, enabling secure, automated delivery of secrets to applications at runtime. This integration helps maintain secure development practices and it doesn’t expose secrets in code repositories or build systems.
Scalability and Flexibility Across Environments
External Secret Managers like Akeyless are cloud-agnostic and support multiple cloud providers (AWS, Azure, GCP) and on-premises deployments. This provides consistent secrets management across diverse environments. Consistency is crucial for large organizations operating in a hybrid or multi-cloud architecture.
They also have the ability to generate dynamic, just-in-time credentials (e.g., database credentials, RDP, infra, and more) on demand. They can also automatically revoke credentials after a certain period of time. This reduces the risk of credential leaks and limits the exposure window of secrets, enhancing overall security posture.
Reduced Management Complexity
Automated rotation of secrets and privileged credentials is another essential aspect of Secrets Management. Having the ability to automatically rotate a privileged credential within a specific time period reduces the risk of stale and potentially compromised secrets. This automated management reduces the burden on security and DevOps teams, allowing them to focus on higher-priority tasks.
And, by providing a centralized and fine-grained access control mechanism, they minimize the need for creating numerous Kubernetes roles and bindings. This reduces the complexity associated with managing a large number of roles and policies across different clusters.
Akeyless and Kubernetes: A Match Made in Secrets Heaven
The Akeyless Kubernetes plugin allows containerized applications to leverage Akeyless as a deeply integrated secrets management platform. Akeyless offers Static, Dynamic, and Rotated secrets, along with Certificates working with Kubernetes. Here’s a breakdown of the available integrations:
Akeyless K8s Secrets Injector
This plugin injects secrets directly into Kubernetes Pods as environment variables during runtime. It can inject static, dynamic, and rotated secrets into a pod as well as certificates.
The basic idea is to have the Akeyless plugin service deployed, via Helm, in a namespace in your cluster. From there, you can use Environment Variables, File Injection, or a Sidecar to inject the secrets.
Below is an example of using an environment variable to inject a secret using kubectl apply.
apiVersion: apps/v1
kind: Deployment
metadata:
name: test
spec:
replicas: 1
selector:
matchLabels:
app: hello-secrets
template:
metadata:
labels:
app: hello-secrets
annotations:
akeyless/enabled: "true"
spec:
containers:
- name: alpine
image: alpine
command:
- "sh"
- "-c"
- "echo $MY_SECRET && echo going to sleep... && sleep 10000"
env:
- name: MY_SECRET
value: akeyless:/K8s/my_k8s_secret
K8s External Secret Operator (ESO)
This operator facilitates injecting secrets from Akeyless directly into a Kubernetes secret store and ensuring secret synchronization.
apiVersion: external-secrets.io/v1
kind: Secret
metadata:
name: my-external-secret
spec:
secretStoreRef:
name: akeyless
kind: SecretStore
target:
name: my-k8s-secret
source:
kind: Akeyless
name: my-akeyless-secret
K8s Secrets Store Container Storage Interface (CSI): This driver enables Kubernetes to interact with Akeyless as a secrets store. It allows storing and retrieving secrets using the standard Kubernetes API.
apiVersion: csi.storage.k8s.io/v1
kind: CSIStorageClass
metadata:
name: akeyless-csi
provisioner: akeyless.csi.io
K8s External Key Management Service (KMS): This service empowers Kubernetes to utilize Akeyless as a key management service. It enables encryption and decryption of secrets stored within Kubernetes.
apiVersion: kms.k8s.io/v1alpha1
kind: CMSClusterConfig
metadata:
name: akeyless-kms
spec:
endpoint: https://your-akeyless-gateway-url
token: your-akeyless-gateway-token
K8s Cert Manager: This manager simplifies certificate management within Kubernetes. You can use it to issue, renew, and revoke certificates from Akeyless.
yaml
apiVersion: cert-manager.io/v1
kind: Issuer
metadata:
name: akeyless-issuer
spec:
issuerKind: Akeyless
issuerConfig:
name: my-akeyless-issuer
By integrating Akeyless with Kubernetes, you can centralize and secure your secrets management process, enhancing security and streamlining access control for your containerized applications.
Ready to see it for yourself? Get a custom demo of Akeyless to address all your Kubernetes secrets management use cases.