fix(lambda): grantInvoke fails for imported IAM identities #9957
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We used to erroneously assume that IAM identities imported into
the same Stack object (imported Roles specifically) would always
belong to the same account as the resources in the stack, and so
try to add
Invoke
permissions to the identity policy, whichwould silently fail.
In a recent change, we started recognizing the account of the
Role properly and so now we detect that we must actually ALSO
add permission to the Lambda itself (resource policies).
Unfortunately the Lambda IAM-to-Lambda-Permissions translator had a list
of special recognized classes that did not include imported Roles, and
so this would fail.
Add another case where we try a more generic fallback by parsing
the policy principal. This should catch most simple principals
that Lambda Permissions supports.
Fixes #9883.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license