KMS: Passing in admins
when creating key allows actions = kms:* for account root
#24624
Replies: 4 comments
-
Hi @ecs-jnguyen , its mentioned in the Readme doc for the KMS that you need to set FeatureFlag , please see the excerpt below-
With that being said, could you please check if you have followed the same. Thanks |
Beta Was this translation helpful? Give feedback.
-
Thank you that answers my question! Under the other information part of my post I noticed some behavior around using an IRole vs an IPrincipal with the add grant methods. Do you know if this behavior is intended?
|
Beta Was this translation helpful? Give feedback.
-
Hi @ecs-jnguyen When you grant access to an IAM role with const roleFromName = iam.Role.fromRoleName(this, 'existing-role', 'my-existing-role');
new kms.Key(this, 'Key', {
admins: [roleFromName],
}) However, if you grant to an IAM principal with const roleFromArn = new iam.ArnPrincipal('arn:aws:iam::123456789012:role/TheRole');
new kms.Key(this, 'Key', {
admins: [roleFromArn],
}) Please note IAM role and key policy are different, No AWS principal, including the account root user or key creator, has any permissions to a KMS key unless they are explicitly allowed, and never denied, in a key policy, IAM policy, or grant. See key policies in AWS KMS for more details. You can try those properties and run I hope this helps clarify. |
Beta Was this translation helpful? Give feedback.
-
As this is not a relevant bug or feature request, I am converting this to discussion. Let me know if you have any further questions. |
Beta Was this translation helpful? Give feedback.
-
Describe the bug
When I am passing in the
admins
parameter to the kms key, I still see the default key policy that allowsAction: kms:*
for the account root.Expected Behavior
I expect for there to only be 1 statement that only allows my specified role (
TheRole
) to have access to the kms keyCurrent Behavior
Currently this is the cloudformation template that is generated. You can see the first statement allows
kms:*
for the account root. The second admin policy is redundant because the first one allows everything for the root.Reproduction Steps
Possible Solution
When we specify
admins
during the kms key creation we should remove the default policy.Additional Information/Context
No response
CDK CLI Version
2.67.0
Framework Version
No response
Node.js Version
v19.1.0
OS
mac
Language
Python
Language Version
python (3.10)
Other information
Another thing I noticed is that if I use
ArnPrincipal("my role arn")
it add "my role arn" into the key policy. However if I useaws_iam.Role.from_role_name(..., "my role name")
, it will create anAWS::IAM::Policy
and associate it to the role. I wasn't sure if this behavior should have its own issue or not.Beta Was this translation helpful? Give feedback.
All reactions