IAM Grants still not quite right #2807
Labels
@aws-cdk/aws-iam
Related to AWS Identity and Access Management
effort/medium
Medium work item – several days of effort
feature-request
A feature should be added or improved.
in-progress
This issue is being actively worked on.
p1
The IAM policy statement support is still not quite right. Right now, there are 3 grant methods:
Grant.addToPrincipal()
.Grant.addToPrincipalOrResource()
-- note: ORGrant.addToPrincipalAndResource()
-- note: ANDAnd some of the mechanics are made possible by
IPrincipal.addToPolicy(): boolean
, which is supposed to returntrue
orfalse
based on whether or not it added the policy statement. The thinking here was that we can represent principals likemyResource.grantWrite(new ServicePrincipal('events.amazonaws.com'))
, and because itsaddToPolicy()
would returnfalse
, the statement would be added tomyResource
s resource policy.Behavior is supposedly:
Source: https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_identity-vs-resource.html
Grant.addToPrincipalOrResource()
tries to do the right thing, but mostly does so by accident. If it can't add the statement to the principal, it will add it to the resource.The latter case is probably not exercised a lot, and if due to a user's extensive experience with manual IAM configuration they weren't expecting it to work just as magically as the rest of the CDK, they would just add the resource permissions by hand and be none the wiser that we have a bug here. But I would argue that we have a bug nonetheless.
The fact is, the trigger for automatically adding to the resource policy is wrong. The current trigger is: "did we failed to add permissions to the identity?", but the trigger should be: "does the principal live in another account OR did we fail to add permissions?".
Then there is
Grant.addToPrincipalAndResource()
which is yet another crazy beast, and mostly designed to fit the use case of KMS. By default, most (all?) resources exhibit the "inside the same account a statement on either resource or identity is enough" rule, but KMS keys do not. They seem to require explicit statements on the key for every action.The text was updated successfully, but these errors were encountered: