15.2 Cryptographic Controls & Key Management with AWS KMS & ACM
Key Takeaways
- AWS KMS manages three distinct key tiers: AWS owned keys (internal, free, invisible), AWS managed keys (service-default, free, immutable key policy, automatic 1-year rotation), and Customer Managed Keys (CMKs; full control, customizable policies, configurable 90-to-2560-day or on-demand rotation, cross-account sharing).
- Key Policies represent the fundamental access control boundary for KMS keys; IAM policies cannot grant access to a KMS key unless the key policy explicitly delegates permission to the root principal (arn:aws:iam::account-id:root).
- Envelope encryption handles arbitrary-size application data without exceeding the KMS Encrypt plaintext limit of 4,096 bytes: KMS protects a data-encryption key, while the client encrypts the payload locally and stores the encrypted data key with the ciphertext.
- AWS Certificate Manager (ACM) provisions public SSL/TLS certificates with seamless, zero-touch automated renewal via DNS validation (CNAME records), whereas AWS Private CA enables centralized issuance and management of private certificates for microservice mutual TLS (mTLS) and internal VPC workloads.
AWS KMS Cryptographic Architecture & Key Tiers
AWS Key Management Service (AWS KMS) provides centralized, hardware security module (HSM)-backed cryptographic key generation and management validated under FIPS 140-2 Cryptographic Module Validation Program (FIPS 140-3 Level 3 for modern HSMs). Understanding the operational tiers of KMS keys is vital for DevOps engineers designing data protection pipelines.
KMS Key Categories Comparison
| Dimension | AWS Owned Keys | AWS Managed Keys | Customer Managed Keys (CMKs) |
|---|---|---|---|
| Naming Convention | Internal AWS identifier | aws/service-name (e.g., aws/s3, aws/ebs) | Custom alias (e.g., alias/prod-payment-key) |
| Visibility in Account | Invisible in KMS console/CLI | Visible in KMS console/CLI | Fully visible and manageable in console/CLI |
| Key Policy Modification | Cannot view or modify | Can view; cannot modify key policy | Full control to edit key policies and grants |
| Key Rotation | Managed internally by AWS | Automatically rotated every 1 year (365 days) | Configurable automatic rotation (90 to 2560 days, default 365 days) or manual on-demand |
| Cross-Account Access | Unsupported | Unsupported (restricted to originating account) | Fully supported via cross-account key policies |
| Pricing | Free | Free to create; pay per API call | $1.00/month per key + API request costs |
| Cryptographic Types | Symmetric only | Symmetric only | Symmetric, Asymmetric (RSA/ECC), and HMAC |
KMS Key Policies, IAM Policies & Access Control
Unlike most AWS services where IAM policies alone can grant access, AWS KMS enforces a strict hierarchical authorization model: The Key Policy is the primary access control document. IAM policies are completely powerless unless the Key Policy explicitly delegates authority.
The Critical Root Principal Delegation Statement
For an IAM identity policy (attached to a role, user, or group) to grant permissions to a KMS key, the Key Policy must contain the following default delegation statement:
{
"Sid": "Enable IAM User Permissions",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::111122223333:root"
},
"Action": "kms:*",
"Resource": "*"
}
[!WARNING] DOP-C02 Exam Critical Warning: In this context,
arn:aws:iam::111122223333:rootdoes not refer to the root user account credentials; it represents the AWS Account entity. This statement delegates access control to the account's IAM service. If this statement is removed or omitted and no other IAM principal is explicitly allowed in the Key Policy, the key becomes orphaned: no IAM policy in the account can grant access, and only the AWS account root user credentials can restore the Key Policy.
Key Policies vs. KMS Grants
While Key Policies provide static access definitions, KMS Grants offer dynamic, programmatic, and fine-grained access delegation without requiring updates to the JSON Key Policy.
- Use Cases for Grants: Used extensively by AWS services (e.g., Amazon EBS when attaching an encrypted volume to an EC2 instance, or Amazon RDS creating read replicas across regions). Grants can be scoped with an
EncryptionContextEqualscondition and revoked viakms:RevokeGrantor retired viakms:RetireGrant. - Operational Advantage: Prevents hitting Key Policy character limits (maximum 32 KB) when dozens of microservices or automated deployment workers require temporary cryptographic rights.
Key Rotation Mechanics: Automatic vs. On-Demand
AWS KMS provides two mechanisms for rotating the backing cryptographic key material of Customer Managed Keys.
1. Automatic Key Rotation
When automatic rotation is enabled on a symmetric CMK:
- AWS KMS automatically creates a new version of the underlying cryptographic key material on the specified schedule (configurable between 90 and 2560 days; defaults to 365 days).
- The Key ID, Key ARN, Key Policy, and Aliases remain unchanged.
- KMS retains all historical backing key material indefinitely. When an application calls
kms:Encrypt, KMS uses the latest key material version. When an application callskms:Decrypton legacy data encrypted years earlier, KMS detects the backing key version stored in the ciphertext metadata and transparently decrypts it. - Zero operational overhead: No re-encryption pipelines, database migrations, or application configuration updates are needed.
2. Manual / On-Demand Key Rotation
- Used when automatic rotation is unsupported (e.g., asymmetric keys) or when an organization must rotate keys immediately following a security incident.
- The engineer generates a completely new CMK with a new Key ID and ARN.
- The engineer updates the Key Alias (
alias/app-key) to point to the new Key ID. - Previous CMKs must be preserved indefinitely to decrypt legacy ciphertext unless all historical datasets are re-encrypted using the new key.
Cross-Account KMS Key Sharing Pattern
Sharing KMS keys across AWS accounts is a standard requirement in multi-account enterprise architectures (e.g., CI/CD account deploying encrypted resources to production, or centralized S3 data lakes).
Two-Sided Authorization Architecture
Cross-account KMS access requires explicit permission on both sides of the trust boundary:
Account A (Key Owner: 111122223333) Account B (Consumer: 444455556666)
┌──────────────────────────────────────┐ ┌──────────────────────────────────────┐
│ KMS Customer Managed Key │ │ IAM Role: AppDeploymentRole │
│ │ │ │
│ Key Policy: │ │ Attached IAM Policy: │
│ { │ │ { │
│ "Effect": "Allow", │ │ "Effect": "Allow", │
│ "Principal": { │◄────┼───│ "Action": [ │
│ "AWS": "arn:aws:iam::4444..." │ │ │ "kms:Encrypt", │
│ }, │ │ │ "kms:Decrypt", │
│ "Action": [ │ │ │ "kms:GenerateDataKey" │
│ "kms:Encrypt", │ │ │ ], │
│ "kms:Decrypt", │ │ │ "Resource": "arn:aws:kms:..." │
│ "kms:GenerateDataKey" │ │ │ } │
│ ], │ │ } │
│ "Resource": "*" │ └──────────────────────────────────────┘
│ } │
└──────────────────────────────────────┘
- Account A (KMS Owner): The KMS Key Policy must explicitly declare Account B (or the specific IAM role ARN in Account B) as a trusted principal for
kms:Decrypt,kms:GenerateDataKey, andkms:DescribeKey. - Account B (Workload Account): The IAM Role executing the operation must have an attached identity policy explicitly allowing
kms:Decryptandkms:GenerateDataKeytargeting the Key ARN in Account A. - S3 Bucket Considerations: If writing cross-account to S3 with KMS encryption, the writer needs
kms:GenerateDataKeyon the key ands3:PutObjecton the bucket. The bucket policy must permit the upload, and object ownership must be set toBucketOwnerEnforcedto ensure the bucket owner can read the uploaded objects.
Envelope Encryption Deep Dive
The KMS Encrypt API accepts plaintext of up to 4,096 bytes. For symmetric ciphertext, the Decrypt API accepts a ciphertext blob of up to 6,144 bytes because the blob includes KMS metadata in addition to the encrypted plaintext. To encrypt multi-megabyte or gigabyte files (e.g., EBS volumes, S3 objects, database snapshots), AWS uses Envelope Encryption.
The Envelope Encryption Lifecycle
- Key Generation: The client application calls
kms:GenerateDataKeyspecifying the Customer Master Key (CMK) ARN and desired key spec (AES_256). - KMS Response: KMS returns two representations of a newly generated symmetric key:
- Plaintext Data Key: 256-bit symmetric key.
- Encrypted Data Key (Ciphertext): The data key encrypted under the CMK.
- Local Payload Encryption: The application uses the Plaintext Data Key to encrypt the payload locally using an algorithm like AES-GCM or AES-CBC in memory.
- Memory Purge: The application immediately zeroes out and purges the Plaintext Data Key from memory.
- Storage: The application stores the Encrypted Data Key adjacent to the ciphertext (e.g., in S3 object user metadata headers or a database metadata column).
- Decryption Phase: To decrypt, the application extracts the Encrypted Data Key and passes it to
kms:Decrypt. KMS decrypts the data key using the CMK and returns the Plaintext Data Key. The application decrypts the data locally, then immediately wipes the plaintext key from memory.
[ Application ] ──> kms:GenerateDataKey(CMK) ──> [ AWS KMS HSM ]
│ │
│◄── Plaintext Data Key + Encrypted Data Key ────┘
▼
[ Encrypt Payload Locally with Plaintext Data Key ]
│
├──> [ Zero Out Plaintext Data Key from RAM ]
▼
[ Store: Payload Ciphertext + Encrypted Data Key in S3/EBS ]
AWS Certificate Manager (ACM) & AWS Private CA
Securing data in transit requires managing SSL/TLS certificates across microservices, load balancers, and public entry points.
ACM Public Certificates: DNS vs. Email Validation
| Feature | DNS Validation | Email Validation |
|---|---|---|
| Mechanism | Adds a specific CNAME record containing a unique hash to the domain's DNS zone | Sends automated approval emails to up to eight addresses: the three WHOIS contacts plus five common administrative mailboxes (admin@, administrator@, hostmaster@, postmaster@, webmaster@) |
| Automated Renewal | Fully automated and perpetual as long as the CNAME record exists and the cert is in use | Manual approval required annually via email link within a 45-day window |
| Automation Support | Fully orchestratable via AWS Route 53 or external DNS APIs via Terraform/CloudFormation | Requires manual human intervention or fragile mailbox scraping scripts |
| Exam Recommendation | Always recommended for automated production CI/CD environments | Legacy; avoid for automated infrastructure |
ACM Regional Constraints
- CloudFront Distributions: To attach an ACM certificate to an Amazon CloudFront distribution, the certificate must be created in the
us-east-1(N. Virginia) region. - Application Load Balancers & API Gateways: ACM certificates must be created in the same AWS Region as the load balancer or regional API Gateway.
AWS Private CA for Internal Microservices
Standard ACM public certificates are bound to integrated AWS services (ALB, CloudFront, API Gateway) and their private keys cannot be retrieved; ACM also offers an opt-in exportable public certificate option, selected at request time and separately priced, whose private key can be downloaded with a passphrase for use on EC2, on-premises, or multi-cloud hosts. For internal, non-public trust chains, AWS Private CA enables organizations to build a private hierarchical Public Key Infrastructure (PKI):
- Issues private certificates with exportable private keys for internal EC2 instances, containers running on Amazon ECS/EKS, and supported service meshes (for example, Istio).
- Supports mutual TLS (mTLS) authentication for zero-trust microservice architectures.
- Automates renewal via IAM roles and Systems Manager agents without exposing endpoints to public internet DNS validation.
AWS CloudHSM vs. AWS KMS
Both services protect cryptographic key material with hardware security modules, but they assign control and operations differently:
| Decision Point | AWS KMS | AWS CloudHSM |
|---|---|---|
| Service model | Managed key service with AWS service integrations, key policies, grants, and audited API operations | Dedicated single-tenant HSM instances in a customer-controlled cluster |
| Interfaces | KMS APIs and integrated-service encryption | Standard cryptographic interfaces such as PKCS #11, JCE, and Microsoft CNG |
| Operations | AWS operates the HSM fleet; the customer manages keys, policies, and usage | The customer manages cluster users, backups, high availability, client configuration, and crypto workloads |
| Typical choice | Default for envelope encryption and AWS resource encryption | Requirements for dedicated HSM control, custom cryptographic applications, or supported compliance constraints that KMS alone cannot meet |
A KMS custom key store backed by CloudHSM combines KMS APIs and integrations with key material in a CloudHSM cluster that the customer controls. That extra control also adds failure modes: KMS cryptographic operations using the custom key store depend on a healthy, connected CloudHSM cluster. On the exam, do not choose CloudHSM merely because a question says “encryption”; identify a dedicated-HSM, direct-interface, or key-custody requirement that justifies its cost and operational burden.
A CI/CD deployment pipeline in Account A (Application Account) needs to deploy an AWS Lambda function that writes encrypted telemetry files to an Amazon S3 bucket located in Account B (Security & Archive Account). The S3 bucket is encrypted using a Customer Managed Key (CMK) hosted in Account B. Despite the Lambda execution role in Account A having full s3:PutObject permissions on the bucket and the S3 bucket policy explicitly allowing the Lambda role ARN from Account A, the Lambda function fails with an Access Denied error when executing s3:PutObject. What is the root cause and the required resolution?
A financial services company manages sensitive customer records in an Amazon Aurora PostgreSQL database. Compliance regulations mandate that data encryption keys must be rotated at least once every 12 months, but existing data encrypted under previous key versions must remain readable without manual re-encryption pipelines or database downtime. The company also requires that key rotation cannot change the KMS Key ARN used by database connection strings and infrastructure-as-code templates. How should the DevOps engineer configure KMS to meet these compliance requirements?
An organization hosts public APIs across multiple AWS Regions using Application Load Balancers and an Amazon CloudFront distribution. The DevOps team needs to provision SSL/TLS certificates that support automatic renewal without administrative overhead or operational outages caused by expired certificates. The organization's domain names are registered with a third-party DNS provider, but DNS records can be automated via API. How should the DevOps engineer implement certificate provisioning and deployment?