Xoxoftware - XOXO Creative Studio | Web & Mobile App Development | Fred Cheung | Hong Kong
AWSSecurity

AWS KMS and CloudHSM

Key management — customer-managed keys, envelope encryption, key rotation, and CloudHSM for hardware-based cryptographic operations.

Overview

AWS Key Management Service (KMS) is a managed service for creating and controlling encryption keys — it integrates natively with most AWS services to encrypt data at rest and in transit. AWS CloudHSM provides dedicated Hardware Security Modules (HSMs) for workloads requiring single-tenant, hardware-validated key storage.

AspectKMSCloudHSM
ManagementFully managed (shared multi-tenant HSMs)Dedicated single-tenant HSM appliances
Key storageAWS-managed HSMs (FIPS 140-2 Level 3)Customer-managed HSMs (FIPS 140-2 Level 3)
Key controlAWS manages HSM, customer manages keysCustomer has exclusive control of HSMs + keys
IntegrationNative with 100+ AWS servicesManual integration (PKCS#11, JCE, OpenSSL)
Use caseStandard encryption needsRegulatory compliance requiring single-tenant HSMs

Core Concepts

ConceptDescription
Customer Master Key (CMK)The primary key resource in KMS; can be symmetric (AES-256) or asymmetric (RSA, ECC)
AWS Managed KeyCreated and managed by AWS for specific services (e.g., aws/s3); auto-rotated yearly
Customer Managed KeyCreated and managed by the customer; configurable rotation, policies, grants
Data KeyA key generated by KMS for encrypting actual data (used in envelope encryption)
Envelope EncryptionEncrypt data with a data key, then encrypt the data key with a CMK
Key PolicyResource-based policy controlling who can use or manage a KMS key
GrantTemporary, limited permission to use a KMS key without modifying the key policy
Key RotationAutomatic annual rotation of the backing key material (key ID and ARN remain the same)
AliasA friendly name (alias/my-key) that points to a CMK ARN
Key Material OriginWhere the backing key comes from: AWS_KMS (default), EXTERNAL (imported), or AWS_CLOUDHSM

How Envelope Encryption Works

1. Application calls KMS → GenerateDataKey
2. KMS returns:
   ├── Plaintext Data Key (use to encrypt data, then discard)
   └── Encrypted Data Key (encrypted with CMK — store alongside encrypted data)

3. To decrypt:
   ├── Send Encrypted Data Key to KMS → Decrypt
   ├── KMS returns Plaintext Data Key
   └── Use Plaintext Data Key to decrypt the data

SAA/SAP Tip: Envelope encryption is how AWS services encrypt large data. KMS cannot directly encrypt data larger than 4 KB. For larger data, always use GenerateDataKey to get a data key, encrypt locally, and send only the encrypted data key to KMS.


KMS Key Types

Key TypeCreated ByRotationDeletableCost
AWS Owned KeyAWSAWS-managedNoFree
AWS Managed KeyAWSAuto (every year)NoFree (API charges)
Customer Managed KeyCustomerOptional (configurable)Yes$1/month + API fees
Imported Key MaterialCustomerManual onlyYes$1/month + API fees

Exam Trap: AWS managed keys (aws/s3, aws/ebs) are free but cannot have their key policy customised. For cross-account encryption or custom access controls, a Customer Managed Key is required.


Key Policies and Access Control

Access to KMS keys requires both:

  1. The key policy must allow the action (attached to the key itself)
  2. The caller must have IAM permissions to perform the KMS action

Without a key policy allowing access, even an IAM admin policy will not grant KMS access (unless the key policy explicitly enables IAM-based access).

Cross-Account Key Sharing

  1. Key policy in Account A grants kms:* to Account B's root
  2. IAM policy in Account B grants the specific user kms:Decrypt for the key ARN
  3. Both must be in place for cross-account decryption

AWS CloudHSM

CloudHSM provides dedicated, single-tenant HSM appliances within a VPC.

FeatureDescription
DeploymentCloudHSM cluster across 2+ AZs for HA
AccessVia ENI in the VPC; applications connect using standard crypto APIs
Key ownershipCustomer exclusively — AWS has no access to keys
ComplianceFIPS 140-2 Level 3 validated
IntegrationCustom via PKCS#11, JCE, OpenSSL; can back KMS as custom key store
Use casesSSL/TLS offloading, CA signing, Oracle TDE, regulatory compliance

SAA/SAP Tip: CloudHSM is the answer when the question mentions "single-tenant HSM," "customer-controlled hardware keys," "FIPS 140-2 Level 3 validated with customer key control," or "SSL offloading at the HSM level."


KMS vs CloudHSM

CriteriaKMSCloudHSM
TenancyMulti-tenant (shared HSM infra)Single-tenant (dedicated HSMs)
Key managementAWS manages HSM; customer manages keysCustomer manages everything
Symmetric algorithmsAES-256-GCMAES, 3DES, and more
Asymmetric algorithmsRSA, ECCRSA, ECC, DSA
Integration effortLow (native AWS service integration)High (custom crypto library integration)
Price$1/key/month + API calls$1.50/hour per HSM ($1,080/month)
ComplianceFIPS 140-2 Level 3 (AWS-managed)FIPS 140-2 Level 3 (customer-managed)

Common Use Cases

  • Data-at-rest encryption — S3, EBS, RDS, DynamoDB, and 100+ services encrypt with KMS keys natively.
  • Envelope encryption — Applications encrypt large datasets locally using data keys from KMS.
  • Cross-account data sharing — Share encrypted S3 objects or EBS snapshots by granting cross-account key access.
  • Digital signing — Asymmetric KMS keys for code signing, JWT signing, or document verification.
  • SSL/TLS offloading — CloudHSM stores private keys for TLS termination at the HSM level.
  • Regulatory compliance — CloudHSM for industries requiring customer-controlled, single-tenant key storage.

SAA/SAP Exam Tips

SAA/SAP Tip: When sharing encrypted resources cross-account (e.g., AMIs, EBS snapshots, S3 objects), the KMS key policy must grant the target account access. Without this, the receiving account cannot decrypt — even with the resource itself shared.

Exam Trap: Deleting a KMS key is scheduled with a waiting period of 7–30 days. Once deleted, all data encrypted with that key becomes permanently unrecoverable. The exam tests awareness of this irreversible consequence.

SAA/SAP Tip: KMS supports automatic key rotation (annually) for customer managed symmetric keys. The key ID and ARN do not change — old ciphertext is still decryptable because KMS retains previous backing key material.


Cross-Cloud Equivalents

ProviderService / SolutionNotes
AWSAWS KMS + CloudHSMBaseline
AzureAzure Key Vault + Azure Dedicated HSMKey Vault = KMS; Dedicated HSM = CloudHSM
GCPGoogle Cloud KMS + Cloud HSMSimilar separation of managed vs dedicated
On-PremisesHashiCorp Vault, Thales Luna HSM, nCipherSoftware or hardware key management

Pricing Model

KMS

DimensionUnitNotes
Customer managed keys$1/key/monthAWS managed keys are free
API requests$0.03 per 10,000Encrypt, Decrypt, GenerateDataKey, etc.
Asymmetric operations$0.10–$0.15 per 10,000RSA and ECC operations cost more

CloudHSM

DimensionUnitNotes
HSM instancePer hour~$1.50/hr per HSM; minimum 2 for HA

Built by Fred Cheung @CookedRicer · Powered by Fumadocs & Github Copilot

On this page