-
Notifications
You must be signed in to change notification settings - Fork 57
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::KeyPolicy is desired #322
Comments
The suggested workaround for this at the moment is to set up the key policy to allow blanket permissions to anyone in the account, but that seems less than desirable for something as sensitive as encryption keys:
https://docs.aws.amazon.com/kms/latest/developerguide/key-policies.html KMS team thoughtfully built in the restriction that users need to be very explicit about access permissions to sensitive objects (changing behavior from every other AWS service on purpose), only for their efforts to be undone because the restrictions are so cumbersome to work with in practice that people don't bother and just enable all access again. |
Hi! We studied this issue in depth at my organization and converged on the following approach. We always create role stacks first, KMS CMK stacks second, and all other resources subsequently based on dependency order. This design not only permits us to import role arns into key policies, but we can also layer in role policies that specify the KMS keys as well because multiple role policies can be created separate resources:
We further build on this model by layering in additional inline role policies on resources created later. For example, consider how we might provide read access to a CF-created role to an S3 bucket using SSE-KMS encryption with a KMS CMK with both role and resource policies:
Note that resource policies reference roles as AWS principals, whereas policies reference roles via the The general pattern:
|
Found a use case where a |
Yes please. |
Pretty please. It makes no sense that AWS::KMS::KeyPolicy resource type doesn't exist. |
I too have the circular dependency problem. I read all the comments and, more importantly, tried to grok @acdebaca 's response in the context of what I was trying to do. Must have scratched a hole in my chin, trying so hard to understand - and to no avail. My view of the problem is simple: if I can do it in the console, I should be able to do it via CloudFormation. I figured out what I needed to do in the console, then wrote the equivalent in CloudFormation YAML - which resulted in a circular dependency. Then I went to Former2, which accesses your AWS account and produces somewhat-usable YAML to describe the architectural bits you select. Funny, that - it too produced something with a circular dependency. Simplification of what I was doing:
There's the circle -- I took what the OP @rix0rrr was saying as essentially asking for a way to point the That all said, I found another spot to point a dependency in the other direction. I removed the
And voila, the circle broken. Later I decided to move "grant Role permission to use Key" from Hopefully this helps someone. Cheers. |
New use-case
|
My use case: I want to produce a script to migrate the content of a kms encrypted bucket from one source account to a target account. I would like to have a cdk stack that is only deployed when a migration occurs (and destroyed after it finishes) and that is capable of adding the required permissions for the target account to run CopyObject via Boto3 on the source account bucket. The stack should manage S3 permissions on existing buckets (via BucketPolicy) and KMS permissions on existing keys, but the latter seems impossible right now, and would be easily solved having a KeyPolicy which can be used by the stack dedicated to the temproary migration resources. |
Yep, (possibly not, but throwing in my 2p) another use case:
Having this resource allows me to break up the ordering the same way I do with IAM::Role and IAM::Policy. |
I'll add another current use case, but I guess it's basically the generalization of this issue.
I don't want anyone (role) touching the key, only specific principals, AND It comes down to necessity AND sufficiency. Possessing the role should be necessary to access the key, and sufficient to do so. If I drop the key policy, no one can touch it; if I generalize, then everyone can touch it. If I generalize the role policy, then it can touch too many keys. If we're going to have this two-sided approach (policy on key, and policy on role, both must match up), then we should not have circular dependency be an issue. Ditto to jpr5's comment--if something can be done in console, there should be a way to do it in CloudFormation. Adding to that, common things should be easy. As security becomes a bigger concern and more people are actually paying attention to IAM and key policies, this particular problem should get rectified. |
I seem to have the same issue.
But that already results in a circular dependency. |
@twixr For that specific case you don't have to give the SNS Topic permissions to use the key, but the producers / consumers of that topic, so you would:
|
@benbridts thanks, but is it possible to attach a role to a SNS Topic, I thought it wasn't possible. Edit: Ah I misread, so the permission to encrypt should be granted to the resource that publishes to the topic? |
Indeed. If this fails, you might be missing the delegation to IAM on the KMS key itself (in contrast with s3 bucket policies, for KMS you need permissions in both the Resource policy and Principal policy) |
AWS::KMS::Key
supports configuring a resource policy as a property on the object, but not as its own resource. Given that by default, keys must have a statement both in the key resource policy as well as on the IAM identity policy to allow an operation such asiam:Encrypt
, this makes it impossible to create aKey
with restrictive permissions in Stack 1, and aRole
in Stack 2 that can use that key.This is because at the time of
Key
creation (Stack 1), when we're setting the key policy, we won't know the name of theRole
yet that will be created in Stack 2, so we can't properly reference it.What we would like to be able to write is this:
Compare:
AWS::S3::BucketPolicy
,AWS::SQS::QueuePolicy
, etc, which encapsulate the operation of adding to a resource's policy, so that this operation can be done in a cross-stack fashion.5. Helpful links
A grant must be present in both the key policy and the identity's IAM policy. Source:
https://docs.aws.amazon.com/kms/latest/developerguide/control-access-overview.html#managing-access
6. Category (required) - Will help with tagging and be easier to find by other users to +1
The text was updated successfully, but these errors were encountered: