Credential Management and Secret Rotation with AWS Secrets Manager
Create and rotate credentials for password management (for example, AWS Secrets Manager)
Credential Management and Secret Rotation with AWS Secrets Manager
This study guide covers the centralized management of sensitive information such as database credentials, API keys, and OAuth tokens using AWS Secrets Manager, focusing on the lifecycle of a secret from creation to automated rotation.
Learning Objectives
- Define the purpose and primary use cases for AWS Secrets Manager.
- Configure a new secret using key-value pairs and KMS encryption.
- Implement automated rotation for both native AWS services and custom applications.
- Distinguish between AWS Secrets Manager and Systems Manager Parameter Store.
- Architect cross-region secret replication for disaster recovery.
Key Terms & Glossary
- Secret: A protected resource containing sensitive data (e.g., JSON string with
usernameandpassword). - Rotation: The automated process of updating a secret's value at regular intervals to minimize the risk of compromise.
- KMS (Key Management Service): The underlying service Secrets Manager uses to encrypt secret values at rest.
- Resource-based Policy: A policy attached directly to a secret that defines who (which IAM roles or users) can access it.
- Replication: Copying a secret to other AWS Regions to support global applications and business continuity.
The "Big Idea"
In modern cloud architecture, hardcoding credentials is a critical security vulnerability. AWS Secrets Manager transforms credentials from "static strings in code" to "dynamic resources accessed via API." This allows security teams to change passwords frequently without ever touching the application code or restarting servers, significantly reducing the blast radius of a potential credential leak.
Formula / Concept Box
| Concept | Requirement / Rule |
|---|---|
| Encryption | All secrets MUST be encrypted at rest using a KMS key (AWS-managed or Customer-managed). |
| Rotation Window | Configured in days (e.g., 30, 60, 90). Managed via a Lambda function for non-native services. |
| Access Method | Applications call GetSecretValue using an IAM role with specific permissions. |
| Regional Scope | Secrets are regional by default but can be replicated to other regions. |
Hierarchical Outline
- I. Secret Creation & Storage
- Secret Types: Database credentials (RDS, Redshift, DocumentDB) or "Other" (API keys).
- Data Formats: Key-Value pairs (recommended) or Plaintext.
- Encryption: Integrated with AWS KMS; secrets are decrypted only in memory during retrieval.
- II. Access Control
- IAM Policies: Grant
secretsmanager:GetSecretValueto specific execution roles. - Resource Policies: Optional cross-account access control attached to the secret.
- IAM Policies: Grant
- III. Rotation Mechanism
- Native Rotation: Out-of-the-box support for RDS, Redshift, and DocumentDB.
- Custom Rotation: Uses AWS Lambda to update third-party APIs or on-premises DBs.
- IV. Global Availability
- Replication: Primary secrets can be replicated to secondary regions.
- Sync: Updates to the primary secret (including rotation) automatically propagate to replicas.
Visual Anchors
Application Secret Retrieval Flow
Secret Rotation Lifecycle
\begin{tikzpicture}[node distance=2cm, auto] \draw[->, thick] (0,0) arc (180:-150:1.5cm) node[midway, above] {Rotation Interval (e.g., 30 Days)}; \node (start) at (0,0) [draw, rectangle, rounded corners] {Active Secret}; \node (lambda) at (4,0) [draw, diamond, aspect=2] {Lambda Trigger}; \node (new) at (8,0) [draw, rectangle, rounded corners] {New Credentials}; \draw[->] (start) -- (lambda); \draw[->] (lambda) -- node {Update DB} (new); \draw[->] (new) -- +(0,-1.5) -| (start) node[pos=0.25, below] {Version Label Update}; \end{tikzpicture}
Definition-Example Pairs
- Definition: Native Rotation
- Example: Configuring Secrets Manager to automatically change an Amazon RDS for PostgreSQL password every 30 days without writing any custom code.
- Definition: Key-Value Secret
- Example: Storing a SendGrid API key with the Key as
SENDGRID_API_KEYand the Value asSG.x789...for easy programmatic retrieval.
- Example: Storing a SendGrid API key with the Key as
- Definition: Cross-Region Replication
- Example: An application running in
us-east-1andeu-west-1uses a single secret replicated to both regions to ensure local low-latency access and failover capability.
- Example: An application running in
Worked Examples
Creating a Secret for a Third-Party API
- Console Access: Navigate to Secrets Manager and select Store a new secret.
- Secret Type: Choose Other type of secret (since it's not a native AWS DB).
- Data Entry: Select Key/Value. Enter Key:
ApiKey, Value:EXAMPLE-SECRET-TOKEN-123. - Encryption: Select the default
aws/secretsmanagerKMS key. - Naming: Name it
production/payment-gateway/token. - Rotation: Disable automatic rotation (unless a custom Lambda is already prepared for this specific API).
- Review: Save the secret and note the Secret ARN for IAM policy configuration.
Checkpoint Questions
- What service must Secrets Manager interact with to ensure secrets are not stored in plaintext at rest?
- If you need to rotate a secret for an Oracle database running on an EC2 instance, what additional AWS service is required?
- True or False: Secrets Manager automatically updates the password in your application's
config.phpfile when rotation occurs. - Which feature allows a secret created in
us-east-1to be available inus-west-2for disaster recovery?
Comparison Tables
Secrets Manager vs. Systems Manager Parameter Store
| Feature | AWS Secrets Manager | SSM Parameter Store |
|---|---|---|
| Primary Use Case | Sensitive credentials/API keys | General configuration & secrets |
| Rotation | Native support & built-in templates | Requires custom EventBridge/Lambda |
| Cost | Per secret, per month (Higher) | Free (Standard), Per parameter (Advanced) |
| Encryption | Always encrypted (KMS) | Optional (Plaintext or KMS) |
| Cross-Region | Native replication | Manual copy required |
Muddy Points & Cross-Refs
- Secret Versions: Beginners often struggle with how Secrets Manager handles rotation without downtime. It uses version labels (e.g.,
AWSCURRENT,AWSPREVIOUS). The app always asks forAWSCURRENT. During rotation, a new version is created, and the label is swapped only after the database update is confirmed. - VPC Endpoints: If your application is in a private subnet without an IGW, you must configure an Interface VPC Endpoint for Secrets Manager to allow the app to reach the service.
- Cross-Ref: For more on how to authorize apps to read these secrets, see the IAM Policies & Roles study guide.