Sub topic 3
Encrypting backups with KMS keys
This chapter explains how AWS Backup uses AWS Key Management Service (AWS KMS) keys to encrypt recovery points. It covers choosing a key for a vault, the key policy the backup role needs, and what happens to encryption when you copy or restore. It assumes you can create and read IAM roles and policies, run the AWS CLI, and understand what a backup vault is from the previous chapter.
How a vault uses its key
Every backup vault has an encryption key, which you set when you create the vault. Recovery points stored in the vault are protected with it. You can pick one of two kinds of key:
- The AWS managed key for AWS Backup (alias
aws/backup). AWS Backup uses it if you don't name a key. You cannot edit its policy or share it with other accounts. - A customer managed key. You create it in KMS, write its key policy, and can rotate, disable, or schedule it for deletion.
The key is fixed for the life of the vault. You cannot change it later. To move to a different key, create a new vault with that key and point your backup rules at the new vault. Existing recovery points stay in the old vault.
Use a customer managed key when you need cross-account copies of some resource types, separation of duties between key administrators and backup operators, or CloudTrail records of each key use that you can tie to your own key.
Which key encrypts which backup
The vault key does not encrypt every backup. How a backup is encrypted depends on how the source service stores it.
| Resource type | What encrypts the recovery point |
|---|---|
| Fully managed by AWS Backup, such as Amazon S3 and DynamoDB with advanced features | The vault's KMS key. AWS Backup applies it independently of the source. |
| Snapshot-based, such as Amazon EBS and Amazon RDS | The same key as the source resource. If the source is unencrypted, the backup is unencrypted. |
The exact grouping varies by service and changes over time. Check the "Feature availability by resource" table in the AWS Backup documentation before you rely on it.
The second row surprises many teams. An unencrypted EBS volume stays unencrypted when backed up, even in a vault with a customer managed key. To get encrypted backups of those resources, encrypt the source. You can turn on EBS encryption by default per Region.
Creating a customer managed key for a vault
The key policy decides who can use the key. The backup service role must be allowed to use it, or backup jobs fail with access errors. Save this as key-policy.json. Replace 123456789012 with your account ID and adjust the role name if you use a custom role.
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "EnableAccountAdministration",
"Effect": "Allow",
"Principal": { "AWS": "arn:aws:iam::123456789012:root" },
"Action": "kms:*",
"Resource": "*"
},
{
"Sid": "AllowBackupRoleToUseKey",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::123456789012:role/service-role/AWSBackupDefaultServiceRole"
},
"Action": [
"kms:Encrypt",
"kms:Decrypt",
"kms:ReEncrypt*",
"kms:GenerateDataKey*",
"kms:DescribeKey"
],
"Resource": "*"
},
{
"Sid": "AllowBackupRoleToCreateGrants",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::123456789012:role/service-role/AWSBackupDefaultServiceRole"
},
"Action": "kms:CreateGrant",
"Resource": "*",
"Condition": {
"Bool": { "kms:GrantIsForAWSResource": "true" }
}
}
]
}The first statement lets IAM policies in the account manage the key. Without it, only the principals named in the key policy have access. Leaving it out can lock administrators out of the key.
Next, create the key and an alias, then create the vault with the key's ARN.
KEY_ARN=$(aws kms create-key \
--description "AWS Backup vault key" \
--policy file://key-policy.json \
--query KeyMetadata.Arn \
--output text)
aws kms create-alias \
--alias-name alias/app-backup-key \
--target-key-id "$KEY_ARN"
aws backup create-backup-vault \
--backup-vault-name app-vault \
--encryption-key-arn "$KEY_ARN"
aws backup describe-backup-vault \
--backup-vault-name app-vault \
--query EncryptionKeyArnThe last command should print the ARN of your key. If you create a vault without --encryption-key-arn, describe-backup-vault shows the ARN of the AWS managed key for AWS Backup instead.
Copies and restores
Copies and restores use KMS in ways that depend on where the data goes.
- Cross-Region copy. A key from the source Region cannot be used in another Region. The copy is encrypted with the destination vault's key, so the destination vault needs its own key.
- Cross-account copy. The destination vault's key must allow the destination account to use it. For snapshot-based resources such as EBS and RDS, the source backup must be encrypted with a customer managed key that you share with the destination account. A backup encrypted with an AWS managed key cannot be shared, so the copy fails.
- Restore. The restore role needs permission on the key that protects the recovery point. For snapshot-based resources you can usually pick a different key for the restored resource. Check the restore metadata for the available options.
Cross-account and cross-Region copies are covered in a later chapter. When you plan them, decide on keys first.
Failure modes
Most KMS problems appear as failed jobs or restores, not as errors at vault creation time.
- The backup role is missing from the key policy. Backup jobs fail with a KMS access error. Add the role to the key policy as shown above.
- The key is disabled. Existing recovery points cannot be decrypted, and new backups to the vault fail. Re-enable the key to recover.
- The key is deleted. KMS deletes a key only after a waiting period of 7 to 30 days. After that, every recovery point protected by that key is permanently unreadable. AWS Backup cannot recover them.
- A key policy is edited to remove access. Restores fail even though backups exist. Test restores after any policy change.
Checking your setup
Before relying on a vault, run these checks:
- Run
aws backup describe-backup-vaultand confirmEncryptionKeyArnis the key you intended. - Run
aws kms get-key-policy --key-id <key-arn> --policy-name defaultand confirm the backup role is listed. - Run an on-demand backup of a small resource and confirm the job reaches
COMPLETED. - Restore that backup into a test resource.
Step 4 is the one teams skip. A backup that has never been restored has not been tested, and key access problems usually show up only at restore time.
Exercise
You create a vault with a customer managed key and back up an unencrypted EBS volume into it. Is the recovery point encrypted with the vault's key? What should you change to get an encrypted backup?
Show answer
No. EBS backups are snapshot-based, so the recovery point uses the source volume's encryption state, and an unencrypted volume gives an unencrypted recovery point. To get an encrypted backup, encrypt the source volume (for example by turning on EBS encryption by default and recreating the volume from an encrypted copy of its snapshot), then back it up again.
Exercise
A backup job into a new vault with a customer managed key fails with a KMS access error. Name the first thing to check and where to fix it.
Show answer
Check the key policy. The AWS Backup service role (for example AWSBackupDefaultServiceRole) must be allowed to use the key, including GenerateDataKey, Decrypt and CreateGrant. Add those permissions in the key's key policy.