KMS, Secrets Manager and Certificate Manager
Overview
Encryption is only useful if you can manage the keys. AWS KMS creates and controls cryptographic keys and integrates with almost every AWS service. AWS Secrets Manager stores and automatically rotates secrets such as database passwords, and AWS Certificate Manager (ACM) provisions and renews TLS certificates.
Consider a bank. KMS is the vault that keeps the master keys and never lets them leave; Secrets Manager is the clerk who changes the combination of the safe-deposit boxes regularly; ACM is the office that issues and renews ID badges before they expire.
The operational questions are practical: "Why can't this role decrypt?", "How do I rotate a database password without downtime?", "Why did my certificate not renew?". This lesson targets those.
Key Concepts
- KMS key types: AWS owned, AWS managed (aws/s3, aws/ebs; rotated yearly automatically, cannot edit policy) and customer managed (you control policy, rotation, deletion).
- Access to a KMS key requires the key policy to allow (directly or by enabling IAM policies); IAM alone is not enough unless the key policy delegates to IAM.
- Envelope encryption: KMS generates a data key; the data is encrypted locally and the data key is stored encrypted next to it. Direct Encrypt is limited to 4 KB.
- Automatic rotation of customer managed symmetric keys (default yearly, configurable 90-2560 days) keeps the same key ID/ARN; old key material is retained for decryption.
- Key deletion has a mandatory waiting period of 7-30 days; during it the key is unusable and can be cancelled. Disabling a key is reversible.
- Multi-Region keys share key material across Regions for cross-Region decrypt (DR, global tables).
- Secrets Manager stores secrets (KMS-encrypted), supports rotation via Lambda, cross-Region replication and resource policies.
- ACM public certificates are free for integrated services (ALB, CloudFront, API Gateway); DNS validation enables automatic renewal; certificates cannot be installed directly on EC2.
Detailed Notes
Why can't it decrypt? (checklist)
- Key policy allows the principal (or allows the account root, which enables IAM policies).
- Identity policy grants
kms:Decrypt/kms:GenerateDataKeyon the key ARN. - Key is Enabled and not pending deletion.
- Correct Region (and multi-Region key replica exists).
- Cross-account: key policy trusts the other account and the other account's identity policy allows the key.
- Service use: service principal or grants (e.g. EBS, RDS) and encryption context conditions.
Key policy statement enabling IAM policies:
{
"Sid": "EnableIAMPolicies",
"Effect": "Allow",
"Principal": { "AWS": "arn:aws:iam::111122223333:root" },
"Action": "kms:*",
"Resource": "*"
}
Common KMS CLI
aws kms create-key --description "app data" --key-usage ENCRYPT_DECRYPT
aws kms create-alias --alias-name alias/app --target-key-id <KEY_ID>
aws kms enable-key-rotation --key-id <KEY_ID> --rotation-period-in-days 365
aws kms schedule-key-deletion --key-id <KEY_ID> --pending-window-in-days 30
aws kms generate-data-key --key-id alias/app --key-spec AES_256
Key comparison
| Aspect | AWS managed | Customer managed |
|---|---|---|
| Policy editable | No | Yes |
| Rotation | Every year, automatic | Optional, configurable |
| Cross-account use | Not possible | Possible |
| Cost | Free storage | Monthly per key + requests |
| CloudTrail audit | Yes | Yes |
Encrypting an existing unencrypted EBS volume or RDS instance requires creating an encrypted copy: snapshot -> copy snapshot with encryption -> restore. Enable EBS encryption by default in the Region to avoid unencrypted volumes.
Secrets Manager rotation
aws secretsmanager create-secret --name prod/db --secret-string '{"username":"app","password":"initial"}'
aws secretsmanager rotate-secret --secret-id prod/db \
--rotation-lambda-arn arn:aws:lambda:us-east-1:111122223333:function:SecretsManagerRDSMySQLRotation \
--rotation-rules AutomaticallyAfterDays=30
aws secretsmanager get-secret-value --secret-id prod/db --query SecretString --output text
For RDS you can use managed rotation (ManageMasterUserPassword), which needs no Lambda you maintain. Rotation uses a four-step process (createSecret, setSecret, testSecret, finishSecret) with version stages AWSCURRENT / AWSPENDING / AWSPREVIOUS. The rotation Lambda needs network access to both the database and the Secrets Manager endpoint (use a VPC endpoint).
ACM
| Topic | Detail |
|---|---|
| Validation | DNS (CNAME; auto-renews while record exists) or email |
| Region | CloudFront certificates must be in us-east-1; ALB certs in the ALB's Region |
| Renewal failure | DNS validation record removed, domain not in use, or certificate not in use by a service |
| Imported certs | Not auto-renewed; monitor expiry (EventBridge ACM Certificate Approaching Expiration, Config rule ACM_CERTIFICATE_EXPIRATION_CHECK) |
| Private CA | AWS Private CA issues private certificates for internal workloads |
aws acm request-certificate --domain-name app.example.com --validation-method DNS \
--subject-alternative-names www.example.com
aws acm describe-certificate --certificate-arn <ARN> --query Certificate.DomainValidationOptions
Secrets: where to store what
| Need | Choice |
|---|---|
| Rotated DB credentials | Secrets Manager |
| Plain config / feature flags | Parameter Store |
| Encrypt data at rest | KMS CMK |
| Public TLS for ALB/CloudFront | ACM |
| Item | Operational fact |
|---|---|
| AWS managed key rotation | Automatic, about every year, not configurable |
| Customer managed key rotation | Optional automatic rotation (configurable period); old key material kept for decryption; manual rotation means a new key and alias switch |
| Key deletion | Mandatory 7-30 day waiting period; disable first to test impact |
| Imported key material | You manage expiry and rotation |
| Multi-Region keys | Same key ID in several Regions for DR and global apps |
| Grants | Temporary delegated use of a key by AWS services |
| Secrets Manager rotation | Lambda-based schedule; managed rotation for RDS |
| ACM | Free public certificates for integrated services, auto-renew if DNS validation record stays in place |
aws kms enable-key-rotation --key-id alias/app-data
aws kms schedule-key-deletion --key-id <id> --pending-window-in-days 30
aws secretsmanager rotate-secret --secret-id prod/db --rotation-lambda-arn <arn> --rotation-rules AutomaticallyAfterDays=30
aws acm describe-certificate --certificate-arn <arn> --query Certificate.[Status,RenewalSummary]
Certificates for CloudFront must be in us-east-1; certificates for ALB must be in the load balancer's Region. Use CloudTrail to see Decrypt calls when diagnosing key use, and aws:SourceVpce/kms:ViaService conditions to scope key usage.
Real World Example
Scenario – an application suddenly cannot read encrypted files. After a security clean-up, S3 reads from a Lambda function fail with AccessDeniedException ... kms:Decrypt. The ops engineer checks the customer managed key and finds a tidied key policy no longer allowed the account root, so IAM policies no longer applied to the key.
They restore the "enable IAM policies" statement, add least-privilege kms:Decrypt to the Lambda role, and create an alarm on KMS AccessDenied CloudTrail events. Database credentials move to Secrets Manager with 30-day managed rotation, eliminating a long-lived password in environment variables.
Architecture Diagram
- 1The application's role requests the secret from Secrets Manager.
- 2Secrets Manager uses a KMS key, authorised by the key policy, to decrypt it.
- 3A rotation Lambda periodically changes the password in RDS and the secret together.
- 4ACM-managed certificates on the ALB renew automatically via DNS validation.
Best Practices
- ✓Use customer managed keys where you need audit, cross-account use or custom rotation; enable rotation.
- ✓Keep a key policy statement that enables IAM policies, and avoid giving
kms:*broadly. - ✓Store credentials in Secrets Manager with rotation; never hard-code or put them in user data.
- ✓Use ACM with DNS validation and monitor imported certificate expiry.
- ✓Turn on EBS and S3 default encryption and enforce with Config rules / SCP.
Common Interview Questions
Exam Tips
SOA-C03 focus
- Automatic password rotation -> Secrets Manager; simple config/params -> Parameter Store.
- KMS key policy must allow access; key deletion waits 7-30 days.
- CloudFront certificates must be requested in us-east-1.
- Encrypt existing EBS/RDS -> snapshot, copy with encryption, restore.
Chapter quiz
Security and Compliance Operations · 10 questions
1.A user's IAM policy allows s3:GetObject on a bucket, but requests are denied. The account belongs to an organization. Which is a possible cause?
2.Which service continuously scans EC2 instances, ECR images and Lambda functions for software vulnerabilities (CVEs)?
3.A company wants to guarantee that no account in an OU can disable CloudTrail, even administrators in those accounts. What should they use?
4.A database password must be rotated every 30 days automatically with no application downtime. Which service is most suitable?
5.A Lambda function receives AccessDeniedException for kms:Decrypt on a customer managed key in the same account. The Lambda role policy allows kms:Decrypt on the key. What should be checked next?
6.A user has an identity policy allowing s3:GetObject, but the request is denied. An SCP on the OU does not mention S3. What else could explain the denial?
7.Which service continuously finds S3 buckets and IAM roles shared with principals outside the organization?
8.An organization wants to block all actions outside two approved Regions for member accounts, while exempting global services. Which approach is correct?
9.A GuardDuty finding must automatically isolate the affected instance by swapping its security group. What is the best low-code design?
10.A KMS customer managed key is no longer needed. What is the safest way to delete it?
0 of 10 answered
Finished this lesson?
0 of 46 lessons done · 0% of the course

