Skip to content

Instantly share code, notes, and snippets.

@jdowning
Created January 15, 2020 17:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdowning/8d146cd238de828141e81b458dc546f0 to your computer and use it in GitHub Desktop.
Save jdowning/8d146cd238de828141e81b458dc546f0 to your computer and use it in GitHub Desktop.
Parameterized KMS Key Policy

Set variables to use in template:

# note: these are example values
export AWS_ACCOUNT_ID=012345678901         
export HEROKU_DATA_ACCOUNT_ID=098765432109

Use the key policy with the variables:

envsubst < key_policy.json
{"Id":"KMS-policy","Version":"2012-10-17","Statement":[{"Sid":"EnableIAMUserPermissions","Effect":"Allow","Principal":{"AWS":"arn:aws:iam::${AWS_ACCOUNT_ID}:root"},"Action":"kms:*","Resource":"*"},{"Sid":"Allowuseofthekey","Effect":"Allow","Principal":{"AWS":"arn:aws:iam::${HEROKU_DATA_ACCOUNT_ID}:root"},"Action":["kms:Encrypt","kms:Decrypt","kms:ReEncrypt*","kms:GenerateDataKey*","kms:DescribeKey"],"Resource":"*"},{"Sid":"Allowattachmentofpersistentresources","Effect":"Allow","Principal":{"AWS":"arn:aws:iam::${HEROKU_DATA_ACCOUNT_ID}:root"},"Action":["kms:CreateGrant","kms:ListGrants","kms:RevokeGrant"],"Resource":"*","Condition":{"Bool":{"kms:GrantIsForAWSResource":"true"}}}]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment