DataService 08 of 139 controls
AWS KMS security hardening
Harden AWS KMS: key policies that separate admins from users, narrow conditions, audited grants, rotation, and guardrails against key deletion.
On this page
- Baseline controls
- How KMS authorization works
- The default key policy and the root principal statement
- Separate key administrators from key users
- Condition keys that narrow key usage
- Grants
- Cross-account access
- Key rotation
- Protect keys from deletion and disabling
- Multi-Region keys: use them deliberately
- Logging and detection
- Common mistakes
- References
AWS Key Management Service (KMS) holds the keys behind almost every encrypted resource in AWS: S3 objects, EBS volumes, RDS snapshots, Secrets Manager secrets and CloudTrail logs can all use KMS keys, and the key policy decides who can decrypt them. That makes KMS both a control and a target. A bucket policy that looks tight is irrelevant if the key behind it lets the whole organization call kms:Decrypt, and the attacks that matter are not about breaking cryptography. Attackers with stolen credentials re-encrypt data with a KMS key in an account they control and then delete or disable it, a ransomware technique documented by Rhino Security Labs; they schedule deletion of your own keys to destroy data; or they ride broad kms:* IAM permissions to decrypt anything they can copy. At defaults, KMS gives you a single-statement key policy that delegates everything to IAM, no rotation on keys you create, and no guardrail against deletion. This page covers how KMS authorization actually works, how to write key policies that separate administration from usage, the condition keys that narrow access, and the guardrails that keep keys from being disabled or deleted.
Baseline controls
- 0101Customer managed keys for sensitive data
AWS managed keys cannot be restricted, shared on your terms or separated by duty.
How to check:aws kms describe-key --key-id <key-id> --query KeyMetadata.KeyManager - 0202No IAM policy allows decrypt on all keys
kms:Decrypt on Resource * turns any compromised role into a reader of all ciphertext.
How to check:Console: Security Hub CSPM > Controls > KMS.1 and KMS.2Mapping: KMS.1, KMS.2 - 0303Key administrators separate from key users
A compromised admin session cannot read data, and workloads cannot change the key.
How to check:aws kms get-key-policy --key-id <key-id> --policy-name default - 0404Usage scoped with kms:ViaService or encryption context
Stolen role credentials cannot decrypt exfiltrated ciphertext outside the intended service.
How to check:aws kms get-key-policy --key-id <key-id> --policy-name default - 0505Grants audited, CreateGrant limited to AWS services
Grants are a hidden access path that never shows up in the key policy.
How to check:aws kms list-grants --key-id <key-arn> - 0606No public keys, cross-account access to named roles only
Granting an external account root lets any admin there delegate decrypt rights.
How to check:aws accessanalyzer list-findings-v2 --analyzer-arn <analyzer-arn>Mapping: KMS.5 - 0707Automatic rotation on symmetric keys
Limits the amount of data protected by one version of key material.
How to check:aws kms get-key-rotation-status --key-id <key-id>Mapping: KMS.4, CIS 4.6 - 0808Key deletion and disabling blocked outside break glass
Deleting a key destroys every piece of data encrypted under it, irreversibly.
How to check:aws kms describe-key --key-id <key-id> --query KeyMetadata.KeyStateMapping: KMS.3 - 0909Multi-Region keys created only by an approved role
One weak replica key policy exposes ciphertext from every Region.
How to check:aws kms describe-key --key-id <key-id> --query KeyMetadata.MultiRegion
How KMS authorization works
KMS differs from most AWS services: the key policy is the primary access control. An IAM policy alone never grants access to a KMS key. A principal can use a key only if one of these is true:
- The key policy grants the principal access directly.
- The key policy contains the statement that delegates to the account (the "root principal" statement), and an IAM policy grants the principal access.
- A grant on the key gives the principal access for specific operations.
SCPs and RCPs still apply on top of this, and an explicit deny anywhere wins.
AWS managed versus customer managed keys
AWS managed keys (aliases starting with aws/, such as aws/s3 or aws/rds) are created by services on your behalf. Their policies cannot be edited: any principal in the account that can use the service can use the key through it. They cannot be shared across accounts, which also means snapshots encrypted with them cannot be shared. If you need cross-account access, a custom key policy, separation of duties or the ability to revoke access, use customer managed keys for anything sensitive. Check which kind a resource uses with aws kms describe-key and look at KeyManager (AWS or CUSTOMER).
The default key policy and the root principal statement
When you create a key without specifying a policy, KMS attaches a default policy with one statement:
{
"Sid": "Enable IAM User Permissions",
"Effect": "Allow",
"Principal": { "AWS": "arn:aws:iam::111122223333:root" },
"Action": "kms:*",
"Resource": "*"
}
This does not give the root user special access. It means "the account is allowed to delegate access to this key through IAM policies". Without it, only principals named in the key policy can use or manage the key.
Keep this statement. You can remove it, but if the remaining principals in the policy are then deleted, the key becomes unmanageable until AWS Support intervenes. What you should avoid is relying on it as your only control while handing out broad IAM permissions such as kms:* or kms:Decrypt on Resource: "*". Security Hub CSPM flags exactly that: KMS.1 for customer managed IAM policies and KMS.2 for inline policies that allow decryption on all keys. Write IAM policies that list specific key ARNs and, if needed, add explicit deny statements in the key policy for actions you never want delegated.
Separate key administrators from key users
The most important structural rule: people who manage the key should not be able to decrypt data with it, and workloads that encrypt data should not be able to change the key. A practical key policy for a customer managed key that protects application data:
{
"Version": "2012-10-17",
"Id": "app-data-key",
"Statement": [
{
"Sid": "EnableIAMDelegation",
"Effect": "Allow",
"Principal": { "AWS": "arn:aws:iam::111122223333:root" },
"Action": "kms:*",
"Resource": "*"
},
{
"Sid": "KeyAdministrators",
"Effect": "Allow",
"Principal": { "AWS": "arn:aws:iam::111122223333:role/KmsKeyAdmin" },
"Action": [
"kms:Create*",
"kms:Describe*",
"kms:Enable*",
"kms:List*",
"kms:Put*",
"kms:Update*",
"kms:Revoke*",
"kms:Disable*",
"kms:Get*",
"kms:Delete*",
"kms:TagResource",
"kms:UntagResource",
"kms:ScheduleKeyDeletion",
"kms:CancelKeyDeletion",
"kms:RotateKeyOnDemand"
],
"Resource": "*"
},
{
"Sid": "KeyUsersViaS3Only",
"Effect": "Allow",
"Principal": { "AWS": "arn:aws:iam::111122223333:role/app-backend" },
"Action": [
"kms:Encrypt",
"kms:Decrypt",
"kms:ReEncrypt*",
"kms:GenerateDataKey*",
"kms:DescribeKey"
],
"Resource": "*",
"Condition": {
"StringEquals": {
"kms:ViaService": "s3.eu-west-1.amazonaws.com",
"kms:CallerAccount": "111122223333"
}
}
}
]
}
Notes on this structure:
Resourceis always"*"in a key policy because the policy is attached to exactly one key.- The admin role has no
kms:Decryptorkms:GenerateDataKey. A compromised admin session can schedule deletion (which you will guard against below) but cannot read data. - The workload role can only use the key through S3 in one Region, which blocks someone holding the role's credentials from calling
kms:Decryptdirectly on ciphertext they exfiltrated elsewhere.
Verify
Dump every key policy in an account for review:
aws kms list-keys --query 'Keys[].KeyId' --output text | tr '\t' '\n' | while read k; do
echo "== $k"
aws kms get-key-policy --key-id "$k" --policy-name default --output text
done
Look for principals that appear in both the administrator and user statements, kms:* granted to anything other than the account root, and "Principal": {"AWS": "*"} without a restrictive condition.
Condition keys that narrow key usage
kms:ViaService limits use of the key to requests made on your behalf by a specific AWS service, in the format service.region.amazonaws.com. Common values: s3.<region>.amazonaws.com, ec2.<region>.amazonaws.com for EBS, rds.<region>.amazonaws.com, secretsmanager.<region>.amazonaws.com.
kms:CallerAccount limits use to principals in a given account. Combined with kms:ViaService, it is the standard way to say "any principal in this account, but only through this service", which is how AWS managed keys are written.
kms:EncryptionContext:<key> and kms:EncryptionContextKeys require a specific encryption context. Encryption context is a set of non-secret key-value pairs bound to the ciphertext as additional authenticated data. Decryption fails unless the exact same context is supplied, and every call is logged in CloudTrail with the context. Many services set it automatically: S3 uses the bucket or object ARN as aws:s3:arn, and Secrets Manager uses SecretARN. You can restrict a key to one bucket:
"Condition": {
"StringEquals": {
"kms:EncryptionContext:aws:s3:arn": "arn:aws:s3:::prod-invoices"
}
}
If you use S3 Bucket Keys, the context is the bucket ARN rather than the object ARN, so write the condition against the bucket. The bucket side of the configuration is on the S3 page.
kms:GrantIsForAWSResource restricts kms:CreateGrant to grants that an integrated AWS service creates for you. Services such as EBS and RDS need grants to use your key in the background, and this condition stops a principal from creating arbitrary grants for itself or a third party.
Grants
Grants are a second, dynamic authorization path. A grant gives a grantee principal permission to use the key for listed operations, and it does not appear in the key policy. Audit them regularly and retire the ones nobody can explain:
aws kms list-grants --key-id arn:aws:kms:eu-west-1:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab
aws kms retire-grant --key-id <key-arn> --grant-id <grant-id>
Only principals with kms:CreateGrant can create grants, so treat that permission like kms:Decrypt in reviews and pair it with kms:GrantIsForAWSResource wherever a service is the consumer. A grant created by an attacker is a quiet persistence mechanism: it survives key policy reviews and IAM clean-ups.
Cross-account access
Cross-account use of a key needs both sides:
- The key policy in the key owner account allows the external role.
- An IAM policy in the external account grants that role access to the specific key ARN.
{
"Sid": "AllowLogArchiveReadOnlyDecrypt",
"Effect": "Allow",
"Principal": { "AWS": "arn:aws:iam::444455556666:role/LogAnalytics" },
"Action": ["kms:Decrypt", "kms:DescribeKey"],
"Resource": "*"
}
Name a specific role rather than the external account root where you can. If you grant the external account root, any administrator there can delegate decrypt rights to any of their principals. A policy with "Principal": "*" and no condition makes the key usable by anyone with an AWS account; Security Hub CSPM flags that as KMS.5.
IAM Access Analyzer reports KMS keys shared outside your zone of trust, so run an organization analyzer as described on the IAM page. To block keys from being used by principals outside the organization at all, a resource control policy with aws:PrincipalOrgID is the scalable answer, and an SCP with aws:ResourceOrgID on KMS actions stops your own principals from using keys that live outside your organization, which is the move behind the external-key ransomware technique. Both are on the Organizations page; test the SCP for AWS-owned keys and third-party integrations before you attach it broadly.
Key rotation
The CIS AWS Foundations Benchmark (4.6) requires rotation for customer created symmetric keys, and Security Hub CSPM checks it as control KMS.4.
aws kms enable-key-rotation \
--key-id 1234abcd-12ab-34cd-56ef-1234567890ab \
--rotation-period-in-days 365
aws kms get-key-rotation-status --key-id 1234abcd-12ab-34cd-56ef-1234567890ab
The rotation period accepts values from 90 to 2560 days and defaults to 365. You can also trigger an immediate rotation with aws kms rotate-key-on-demand, which is useful after a suspected exposure of a principal that held decrypt rights.
Rotation does not re-encrypt your existing data. It creates new key material for future encrypt operations, and KMS keeps every previous version so old ciphertext still decrypts. The key ID, ARN and policy stay the same, so rotation also does not fix an over-permissive key policy. Automatic rotation is not available for asymmetric keys, HMAC keys, keys with imported material, or keys in custom key stores.
Protect keys from deletion and disabling
Deleting a KMS key is destructive and irreversible: data encrypted under it is unrecoverable. KMS enforces a waiting period of 7 to 30 days (default 30) after ScheduleKeyDeletion. Always use the full 30 days for production keys, and know how to cancel:
aws kms schedule-key-deletion --key-id <key-id> --pending-window-in-days 30
aws kms cancel-key-deletion --key-id <key-id>
Security Hub CSPM control KMS.3 flags keys pending deletion. Prevent deletion in the first place with an SCP that allows only a break-glass role to schedule deletion, disable keys or change key policies:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "ProtectKmsKeys",
"Effect": "Deny",
"Action": [
"kms:ScheduleKeyDeletion",
"kms:DisableKey",
"kms:PutKeyPolicy"
],
"Resource": "*",
"Condition": {
"ArnNotLike": {
"aws:PrincipalArn": "arn:aws:iam::*:role/KmsBreakGlass"
}
}
}
]
}
Attach it to the workload OUs, not to the management account (SCPs do not apply there anyway), and make sure the break-glass role itself is protected by MFA and alerting.
Multi-Region keys: use them deliberately
Multi-Region keys share key material and key ID across Regions, so ciphertext produced in one Region can be decrypted in another. Each replica has its own key policy, and the policies are not synchronized. That makes them convenient for global DynamoDB tables or cross-Region disaster recovery, and it also means one weak replica policy exposes data from every Region.
Default to single-Region keys unless you have a concrete need to decrypt the same ciphertext in several Regions. Restrict kms:CreateKey with the kms:MultiRegion condition key so only an approved role can create multi-Region keys, restrict kms:ReplicateKey the same way, and review every replica policy as carefully as the primary.
Logging and detection
CloudTrail records KMS management operations and cryptographic operations (Decrypt, GenerateDataKey, Encrypt) as management events. Trails can exclude KMS events to save volume; do not do that on your organization trail, because those events are your record of who read what. The CloudTrail page covers the organization trail.
Alert on key lifecycle and policy changes with an EventBridge rule:
{
"source": ["aws.kms"],
"detail-type": ["AWS API Call via CloudTrail"],
"detail": {
"eventName": [
"ScheduleKeyDeletion",
"DisableKey",
"PutKeyPolicy",
"CreateGrant",
"ReplicateKey",
"ImportKeyMaterial"
]
}
}
CreateGrant is noisy because services create grants constantly; filter out events where userIdentity.invokedBy is an AWS service, and alert on the rest. The CIS benchmark also includes a CloudWatch metric filter and alarm for DisableKey and ScheduleKeyDeletion (CIS 5.7).
For data access, look for bursts of Decrypt calls from a principal that normally does not call KMS directly, Decrypt without the expected kms:ViaService pattern, and AccessDenied errors on KMS calls, which often mark an attacker probing what a stolen credential can reach. GuardDuty does not have KMS-specific finding types, but its IAM anomaly findings (for example Discovery:IAMUser/AnomalousBehavior) and credential exfiltration findings usually precede KMS abuse. Security Hub CSPM evaluates KMS.1 to KMS.5 continuously, see the Security Hub page.
Common mistakes
- Removing the root principal statement to "tighten" the policy. It is the safety net against a locked-out key. Keep it and tighten IAM instead.
- Granting
kms:*onResource: "*"in IAM. With the root principal statement in place, that single IAM policy gives the role every key in the account. List key ARNs explicitly. - Expecting rotation to re-encrypt data. Rotation only changes the material used for new encryptions. If a key policy was too broad, rotation does nothing about the ciphertext already exposed.
- One key for everything. A single shared key makes every key policy decision global. Use separate keys per data classification or application so you can revoke access to one without breaking the rest.
- Ignoring grants. Teams review key policies and IAM, then miss a grant created months ago that still allows decrypt. Include
list-grantsin every key review. - Short deletion windows. A 7-day window can expire during a holiday before anyone notices. Use 30 days and alert on
ScheduleKeyDeletion. - Sharing a key with an external account root. Any administrator in that account can then pass decrypt rights to anyone. Name the role.
References
- AWS KMS Developer Guide: Key policies
- AWS KMS Developer Guide: Default key policy
- AWS KMS condition keys
- AWS KMS Developer Guide: Encryption context
- AWS KMS Developer Guide: Grants
- AWS KMS Developer Guide: Rotating keys
- AWS KMS Developer Guide: Deleting keys
- AWS Prescriptive Guidance: AWS KMS best practices
- AWS Security Hub CSPM controls for AWS KMS
- Rhino Security Labs: S3 ransomware, attack vector
- Stratus Red Team: S3 ransomware through client-side encryption
- CIS Amazon Web Services Foundations Benchmark
- NIST SP 800-57 Part 1 Rev. 5: Recommendation for Key Management
- MITRE ATT&CK T1485: Data Destruction
Written by
Florian AmetteSecurity engineer writing practical, benchmark-aligned hardening baselines for AWS services, from the organization and identities to data, networks and workloads.