
Secure Your EKS Workloads: A Guide to Using the AWS Secrets Manager Agent
Managing secrets like database credentials, API keys, and access tokens is a critical security challenge in any application environment. In the dynamic world of container orchestration with Amazon EKS (Elastic Kubernetes Service), this challenge is magnified. Storing sensitive information directly in container images or Kubernetes manifests is a significant security risk, and while native Kubernetes Secrets offer an improvement, they often fall short of stringent enterprise security requirements.
A more robust and secure solution is to integrate Amazon EKS with AWS Secrets Manager. This approach provides a centralized, auditable, and highly secure repository for your application’s secrets. To bridge the gap between your EKS pods and Secrets Manager, AWS provides a powerful tool: the AWS Secrets Manager Agent. This client-side caching agent simplifies and secures access to secrets, enhancing your overall security posture.
The Problem with Traditional Secret Management in Kubernetes
Before diving into the solution, it’s important to understand the limitations of common practices:
- Hardcoding Secrets: Placing secrets in configuration files or environment variables within a container image is extremely insecure. Anyone with access to the image or the source code repository can expose them.
- Native Kubernetes Secrets: While better than hardcoding, Kubernetes Secrets are often just Base64-encoded strings stored in etcd. Without additional layers of security like encryption at rest for etcd, they can be easily decoded if a user gains access to the cluster’s underlying data store. Managing rotation and access control at scale can also become complex.
These challenges create a clear need for a dedicated secrets management service that integrates seamlessly with the Kubernetes workflow.
How the AWS Secrets Manager Agent Enhances Security
The AWS Secrets Manager agent is a lightweight tool designed to run alongside your applications in an EKS cluster. Its primary role is to fetch secrets from AWS Secrets Manager and make them available locally to your application containers. This model offers several significant advantages.
- Centralized and Secure Storage: Your secrets are never stored in your EKS cluster’s configuration. They reside in AWS Secrets Manager, which provides fine-grained access control through IAM policies, encryption using AWS KMS, and detailed audit trails via AWS CloudTrail.
- Automatic Secret Rotation: The agent is designed to work with the automatic rotation capabilities of Secrets Manager. When a secret is rotated in the backend, the agent automatically retrieves the latest version and updates its local cache, ensuring your applications use the most current credentials without requiring a restart or redeployment.
- Reduced Latency and Increased Resilience: By caching secrets locally (either in-memory or on-disk), the agent eliminates the need for your application to make an API call to Secrets Manager every time it needs a credential. This improves application performance and makes it more resilient to temporary network issues or API throttling.
- Lower Costs: Caching dramatically reduces the number of API calls made to the Secrets Manager service. Since you are billed per API call, using the agent can lead to significant cost savings, especially for applications that frequently access secrets.
The Core Mechanism: IAM Roles for Service Accounts (IRSA)
The magic that allows your pods to securely authenticate with AWS Secrets Manager is IAM Roles for Service Accounts (IRSA). This feature is a security best practice for granting AWS permissions to applications running on EKS.
Instead of storing long-lived AWS access keys inside your cluster, IRSA works by:
- Associating an IAM Role with a Kubernetes Service Account.
- Your pod uses this Service Account, which allows it to assume the associated IAM Role.
- The pod receives temporary, short-lived security credentials from the AWS Security Token Service (STS).
This process ensures that your application pods have precisely the permissions they need to access specific secrets in Secrets Manager, and nothing more. The credentials are automatically rotated, eliminating the security risk of static keys.
Deployment Strategies: Sidecar vs. DaemonSet
You can deploy the AWS Secrets Manager agent in your EKS cluster using two primary patterns, each suited for different use cases.
1. The Sidecar Model
In this model, the agent container runs alongside your application container within the same pod.
- Pros: It provides strong isolation, as the agent is dedicated to a single application pod. This is the simplest and most secure pattern for most applications.
- Cons: It can lead to higher resource consumption across the cluster, as every application pod that needs secrets will have its own agent container running.
2. The DaemonSet Model
In this model, a single instance of the agent runs on each node in your EKS cluster. It serves requests for secrets from all pods running on that particular node.
- Pros: This is a more resource-efficient approach, as it avoids the overhead of running an agent for every pod. It’s ideal for environments with a high density of pods per node.
- Cons: It requires more complex configuration to handle requests from multiple pods and lacks the strict isolation of the sidecar model.
Actionable Security Tips for Implementation
When integrating the AWS Secrets Manager agent, follow these security best practices to maximize your cluster’s security posture.
- Adhere to the Principle of Least Privilege: Create highly specific IAM roles for each application. The policy should only grant
secretsmanager:GetSecretValuepermission and restrict it to the specific ARN (Amazon Resource Name) of the secret(s) the application requires. - Enable and Enforce Secret Rotation: Use the built-in rotation capabilities of AWS Secrets Manager for all sensitive credentials, such as database passwords. Configure a rotation schedule that aligns with your organization’s compliance and security policies.
- Monitor All Access: Regularly review AWS CloudTrail logs to audit which IAM roles (and therefore, which pods) are accessing your secrets. Set up CloudWatch Alarms to be notified of any unexpected or anomalous activity.
- Secure the Local Cache: If you configure the agent to cache secrets to a file on a shared volume, ensure that the file permissions are properly restricted so that only the intended application container can read it.
By moving away from less secure practices and adopting the AWS Secrets Manager agent with IRSA, you can build a far more secure, resilient, and operationally efficient environment for your applications on Amazon EKS. This approach not only solves the immediate challenge of secret management but also establishes a scalable foundation for modern, cloud-native security.
Source: https://aws.amazon.com/blogs/security/using-aws-secrets-manager-agent-with-amazon-eks/


