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

[aws-kms] CMK keys grant root user too much privileges (GenerateDataKey) vs what is recommended to administer the key #11309

Closed
matdumsa opened this issue Nov 5, 2020 · 2 comments · Fixed by #11918
Assignees
Labels
@aws-cdk/aws-kms Related to AWS Key Management bug This issue is a bug. effort/medium Medium work item – several days of effort p1

Comments

@matdumsa
Copy link
Contributor

matdumsa commented Nov 5, 2020

During issue #3458 and commit #3459 it seems we introduced a permission for CDK-created CMK keys that deviates from the best practice and the spirit of the CMK official documentation.

I call for that commit to be reverted and the documentation updated instead. The issue lays in adding GenerateDataKey to the permissions for the root user on these keys to allow S3.PUT for administrators of the account.

Reproduction Steps

new s3.Bucket(this, 'MyBucket', {
encryption: s3.BucketEncryption.KMS,
removalPolicy: cdk.RemovalPolicy.DESTROY
});

What did you expect to happen?

As documented in the code and in https://aws.amazon.com/premiumsupport/knowledge-center/update-key-policy-future/ we want the admin users of our AWS account to be able to administer the key but we don't necessarily want them to be able to use it for security reasons. Imagine for example an HR system with payroll information where we only want a given role to encrypt/decrypt using the key and not the administrator of the account.

What actually happened?

Admins get the permission to GenerateDataKey but not to Decrypt it, the asymmetry introduced means that an admin would be able to do .PUT in a properly configured S3 bucket but not .GET and can create confusion.

Environment

  • CLI Version : 1.65.0
  • Framework Version: monocdk: 1.69.0
  • Node.js Version: v12.16.0
  • OS : OS X 10.15.7
  • Language (Version): TypeScript 3.9.7

Other

when a CMK key is present s3.grantWrite and s3.grantRead are doing the right thing (they grant access to the bucket and to the underlying key). We simply need to modify the documentation on the Key object to say that by default administrators can administer but not use the key for encrypt/decrypt operations and that it should be explicitly granted as described here https://docs.aws.amazon.com/kms/latest/developerguide/key-policies.html#key-policy-default-allow-root-enable-iam

If you are an amazon employee you can refer to said confusion created by this bug at https://tiny.amazon.com/i1glis6y/tcorpamazV269


This is 🐛 Bug Report

@matdumsa matdumsa added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Nov 5, 2020
@github-actions github-actions bot added the @aws-cdk/aws-kms Related to AWS Key Management label Nov 5, 2020
@njlynch njlynch added effort/medium Medium work item – several days of effort p1 labels Nov 13, 2020
@njlynch
Copy link
Contributor

njlynch commented Nov 13, 2020

See #8977 for a closely related issue.

The KMS default key permissions as-is need a bit of love; as mentioned, GenerateDataKey probably shouldn't be there by default. Then again, the whole allowAccountToAdmin method doesn't quite do what people think it does, and isn't a terribly useful permissions boundary. (It allows PutKeyPolicy, which means an admin can grant themselves any other permissions they want, so artificially limited permissions on top of that isn't adding a lot of security.)

A bit of thought is needed here to find the right new default permissions boundaries, how to provide power users a bit more control of the policy, and how to gracefully deprecate the existing behavior. This is something I've already given some thought, but I confess I don't have a complete design yet.

@SomayaB SomayaB removed the needs-triage This issue or PR still needs to be triaged. label Nov 16, 2020
njlynch added a commit that referenced this issue 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 added a commit that referenced this issue 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
@mergify mergify bot closed this as completed in #11918 Dec 9, 2020
mergify bot pushed a commit that referenced this issue Dec 9, 2020
… (under feature flag) (#11918)

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*
@github-actions
Copy link

github-actions bot commented Dec 9, 2020

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

flochaz pushed a commit to flochaz/aws-cdk that referenced this issue 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 bug This issue is a bug. effort/medium Medium work item – several days of effort p1
Projects
None yet
3 participants