Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(kms): change default key policy to align with KMS best practices (under feature flag) #11918

Merged
merged 7 commits into from
Dec 9, 2020

Conversation

njlynch
Copy link
Contributor

@njlynch njlynch commented Dec 7, 2020

In #5575, a new flag (trustAccountIdentities) was introduced which -- when set
-- changes the default key policy from a custom key admin policy to one that
grants all access to the key to the root account user. This key policy matches
the default policy when a key is created via the KMS APIs or console.

For backwards-compatibility reasons, the default for trustAccountIdentities
had to be set to false. Without the flag explicitly set, the default key
policy is one that (a) doesn't match the KMS-recommended admin policy and (b)
doesn't explicitly enable IAM principal policies to acccess the key. This means
that all usage operations (e.g., Encrypt, GenerateDataKey) must be added to both
the key policy and to the principal policy.

This change introduces a new feature flag to flip the default behavior of the
trustAccountIdentities flag, so new keys created will have the sane defaults
matching the KMS recommended best practices.

As a related change, this feature flag also changes the behavior when a user
passes in policy when creating a Key. Without the feature flag set, the policy
is always appended to the default key policy. With the feature flag set, the
policy will override the default key policy, enabling users to opt-out of the
default key policy to introduce a more restrictive policy if desired. This also
matches the KMS API behavior, where a policy provided by the user will override
the defaults.

Marking this PR as requires-two-approvers to ensure this PR gets an
appropriately-critical review.

BREAKING CHANGE: change the default value of trustAccountIdentities to true,
which will result in the key getting the KMS-recommended default key
policy. This is enabled through the '@aws-cdk/aws-kms:defaultKeyPolicies'
feature flag.

fixes #8977
fixes #10575
fixes #11309


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@njlynch njlynch added the pr/requires-two-approvers This PR is critical (e.g., security, broadly-impacting) and requires 2 approvers to be merged. label Dec 7, 2020
@njlynch njlynch requested review from skinny85, rix0rrr and a team December 7, 2020 18:14
@njlynch njlynch self-assigned this Dec 7, 2020
@gitpod-io
Copy link

gitpod-io bot commented Dec 7, 2020

@github-actions github-actions bot added the @aws-cdk/aws-kms Related to AWS Key Management label Dec 7, 2020
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Dec 7, 2020
… (under feature flag)

In #5575, a new flag (`trustAccountIdentities`) was introduced which -- when set
-- changes the default key policy from a custom key admin policy to one that
grants all access to the key to the root account user. This key policy matches
the default policy when a key is created via the KMS APIs or console.

For backwards-compatibility reasons, the default for `trustAccountIdentities`
had to be set to `false`. Without the flag explicitly set, the default key
policy is one that (a) doesn't match the KMS-recommended admin policy and (b)
doesn't explicitly enable IAM principal policies to acccess the key. This means
that all usage operations (e.g., Encrypt, GenerateDataKey) must be added to both
the key policy and to the principal policy.

This change introduces a new feature flag to flip the default behavior of the
`trustAccountIdentities` flag, so new keys created will have the sane defaults
matching the KMS recommended best practices.

As a related change, this feature flag also changes the behavior when a user
passes in `policy` when creating a Key. Without the feature flag set, the policy
is always appended to the default key policy. With the feature flag set, the
policy will *override* the default key policy, enabling users to opt-out of the
default key policy to introduce a more restrictive policy if desired. This also
matches the KMS API behavior, where a policy provided by the user will override
the defaults.

Marking this PR as `requires-two-approvers` to ensure this PR gets an
appropriately-critical review.

BREAKING CHANGE: change the default value of trustAccountIdentities to true,
which will result in the key getting the KMS-recommended default key
policy. This is enabled through the '@aws-cdk/aws-kms:defaultKeyPolicies'
feature flag.

fixes #8977
fixes #10575
fixes #11309
@njlynch
Copy link
Contributor Author

njlynch commented Dec 7, 2020

Note that the PR is broken up into 2 commits: the first is the set of changes to KMS; the second is all of the (integ) tests that were updated due to the change in ordering of the KMS actions for the (old) default admin policy. I could have coded around this, but I really wanted perms.ts to have the ordering of actions exactly as they appear in documentation, for the sake of easy comparisons in the future. I am open to arguments to revert this part of the PR for the sake of a cleaner diff though.

Copy link
Contributor

@skinny85 skinny85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still feel like I would avoid the feature flag here, and change the default policy (I wouldn't change the append/override behavior though), since it seems like it's so broken. I'm not holding the PR on changing that though.

A few comments, mainly around naming (things which I didn't "grok" when looking at the code on the first pass).

Also, since we're in the area already, is this a good time to handle #4381 ?

packages/@aws-cdk/aws-kms/lib/key.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-kms/lib/key.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-kms/lib/key.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-kms/lib/key.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-kms/lib/key.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-kms/lib/perms.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-kms/lib/key.ts Show resolved Hide resolved
packages/@aws-cdk/aws-kms/lib/key.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-kms/lib/key.ts Outdated Show resolved Hide resolved
@njlynch
Copy link
Contributor Author

njlynch commented Dec 8, 2020

Also, since we're in the area already, is this a good time to handle #4381 ?

@skinny85 - The only difference I'm seeing is that S3/DynamoDB KEY_READ_ACTIONS includes kms:DescribeKey, whereas grantDecrypt doesn't. I can just add that to grantDecrypt/DECRYPT_ACTIONS, but (a) it's not clear if it's actually needed in most cases, and (b) it would cause a resource update for all existing usages. Not sure if it's worth it, to be honest, especially because none of the existing usages in S3/DynamoDB would be a simple replacement of the existing code with key.grantDecrypt; there's a lot of custom stuff in there that I'm not sure I want to couple into this change.

That being said, if you (and others) think it's okay to make that change without a feature flag, I'm happy enough to do it as a separate PR right after this one. Just don't want to unnecessarily muddy the waters here.

@njlynch njlynch requested a review from rix0rrr December 8, 2020 14:48
Copy link
Contributor

@skinny85 skinny85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! A few minor comments.

packages/@aws-cdk/aws-kms/README.md Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-kms/README.md Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-kms/README.md Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-kms/README.md Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-kms/README.md Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-kms/lib/key.ts Show resolved Hide resolved
@njlynch njlynch requested a review from skinny85 December 9, 2020 10:23
@mergify
Copy link
Contributor

mergify bot commented Dec 9, 2020

Thank you for contributing! Your pull request will be automatically updated and merged (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: bf36a36
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify
Copy link
Contributor

mergify bot commented Dec 9, 2020

Thank you for contributing! Your pull request will be automatically updated and merged (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit ff695da into master Dec 9, 2020
@mergify mergify bot deleted the njlynch/kms-key-policies branch December 9, 2020 19:21
flochaz pushed a commit to flochaz/aws-cdk that referenced this pull request Jan 5, 2021
… (under feature flag) (aws#11918)

In aws#5575, a new flag (`trustAccountIdentities`) was introduced which -- when set
-- changes the default key policy from a custom key admin policy to one that
grants all access to the key to the root account user. This key policy matches
the default policy when a key is created via the KMS APIs or console.

For backwards-compatibility reasons, the default for `trustAccountIdentities`
had to be set to `false`. Without the flag explicitly set, the default key
policy is one that (a) doesn't match the KMS-recommended admin policy and (b)
doesn't explicitly enable IAM principal policies to acccess the key. This means
that all usage operations (e.g., Encrypt, GenerateDataKey) must be added to both
the key policy and to the principal policy.

This change introduces a new feature flag to flip the default behavior of the
`trustAccountIdentities` flag, so new keys created will have the sane defaults
matching the KMS recommended best practices.

As a related change, this feature flag also changes the behavior when a user
passes in `policy` when creating a Key. Without the feature flag set, the policy
is always appended to the default key policy. With the feature flag set, the
policy will *override* the default key policy, enabling users to opt-out of the
default key policy to introduce a more restrictive policy if desired. This also
matches the KMS API behavior, where a policy provided by the user will override
the defaults.

Marking this PR as `requires-two-approvers` to ensure this PR gets an
appropriately-critical review.

BREAKING CHANGE: change the default value of trustAccountIdentities to true,
which will result in the key getting the KMS-recommended default key
policy. This is enabled through the '@aws-cdk/aws-kms:defaultKeyPolicies'
feature flag.

fixes aws#8977
fixes aws#10575
fixes aws#11309

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
@aws-cdk/aws-kms Related to AWS Key Management contribution/core This is a PR that came from AWS. pr/requires-two-approvers This PR is critical (e.g., security, broadly-impacting) and requires 2 approvers to be merged.
Projects
None yet
5 participants