My AWS Notebook
Topics
CMK (Customer Master Key)
Data Keys
| Can view | Can manage | Used only for your AWS account
1. Customer managed CMK | Yes | Yes | Yes
2. AWS managed CMK | Yes | No | Yes
3. AWS owned CMK | No | No | No
aws/service-name
(e.g. aws/redshift
).GetKeyPolicy
operation.GenerateDataKey
creates a plaintext data key and an encrypted data key.
PlaintextDataKey
: The plaintext version is used to encrypt, and then discarded. It’s never stored in plaintext.CipherDataKey
: The encrypted version is stored along with the encrypted data; this is envelope encryption.GenerateDataKeyWithoutPlaintext
returns only an encrypted data key.
CMK -> encryption algorithm --> Encrypted data key & Plaintext data key
Plaintext data -> Plaintext data key + encryption algorithm -> Ciphertext
Encrypted data key -> CMK + decryption algorithm -> Plaintext data key
kms:GenerateDataKey
kms:Encrypt
kms:Decrypt
GenerateDataKey
GenerateDataKeyWithoutPlaintext
Encrypt
kms:ReEncrypt
ReEncrypt
encrypts data on the server side with a new CMK without exposing the plaintext of the data on the
client side. The data is first decrypted and then reencrypted.kms:DescribeKey
DescribeKey
allows your app to retrieve information about the CMKs.Master key -> encryption algorithm -> Data key -> encryption algorithm -> Data
(plaintext)
Envelope encryption offers several benefits:
Encrypt
, Decrypt
, ReEncrypt
, GenerateDataKey
, and
GenerateDataKeyWithoutPlaintext
) accept an encryption context."encryptionContext": {"aws:s3:arn": "arn:aws:s3:::bucket_name/file_name"},
CreateGrant
API request.{
"Sid": "xxx",
"Effect": "Allow",
"Principal": {"AWS": "arn:aws:iam::111122223333:root"},
"Action": "kms:*",
"Resource": "*"
}
{
"Sid": "Allow access for Key Administrators",
"Effect": "Allow",
"Principal": {"AWS": "arn:aws:iam::111122223333:user/KMSKeyAdmin"},
"Action": [
"kms:Create*",
"kms:Describe*",
"kms:Enable*",
"kms:List*",
"kms:Put*",
"kms:Update*",
"kms:Revoke*",
"kms:Disable*",
"kms:Get*",
"kms:Delete*",
"kms:ScheduleKeyDeletion",
"kms:CancelKeyDeletion"
],
"Resource": "*"
}
"Resource": [
"kms:Encrypt",
"kms:Decrypt",
"kms:ReEncrypt",
"kms:GenerateDataKey*",
"kms:DescribeKey"
],
"Resource": [
"arn:...<AccountB_ID>:key/<keyID>"
],
"Action": [
...
"kms:ScheduleKeyDeletion",
"kms:CancelKeyDeletion"
]
kms:CallerAccount
condition key to effectively
allow access to all identities in AWS account 111122223333
.kms:ViaService
) to further limit the permissions by only
allowing requests that come through Amazon EBS.
{
"Sid": "Allow access through EBS for all principals in the account that are authorized to use EBS",
"Effect": "Allow",
"Principal": {"AWS": "*"},
"Condition": {
"StringEquals": {
"kms:CallerAccount": "111122223333",
"kms:ViaService": "ec2.us-west-2.amazonaws.com"
}
},
"Action": [
"kms:Encrypt",
"kms:Decrypt",
"kms:ReEncrypt*",
"kms:GenerateDataKey*",
"kms:CreateGrant",
"kms:DescribeKey"
],
"Resource": "*"
}