-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Bug: Creates unnecessary AWSLambdaVPCAccessExecutionRole role #3502
Comments
Thanks for opening this issue. Like you mentioned, it doesn't look like the |
Thanks for creating an issue. I can confirm that I can reproduce this issue. Unfortunately there's not much we can do because SAM does not resolve complex intrinsics and due to backward compatibility issue. A detailed explanation on why SAM doesn't resolve these intrinsics is explained here. AFAIK, resolving these intrinsics typically happens at a later stage after SAM Transform during CloudFormation create changeset step. During SAM transform, there is no way for us to figure out the value of this condition thus deciding to add the policy or not. If this behaviour is bothering you, I would recommend providing a custom iam role and policies to the lambda function. |
@GavinZZ What do you mean "...there's not much we can do"? 😀 This behaviour simply escalates privileges. It is a bug and you claim "we can't do anything about it"? Isn't it a program after all what ever it does (parses, transforms, etc... one-pass, two-pass, creates abstract syntax tree....)? “Statement”: [{
“Effect”: “Allow”,
“Action”: “iam:PassRole”,
“Resource”: “*”
}] } The rule of the least privileges (AWS's motto) are violated by AWS themselves? Thank you. 🙂 |
Hi @fade2black I understand that it is frustrating and I acknowledge it breaks the principle of least privilege. Please allow me to explain the reasoning a bit more in detail. This problem arises from a inconsiderate design issue when this is first implemented. There are are underlying issue that blocked us from fixing it. As described in my previous comment, SAM does not have the capability to figure out the value of However, we cannot proceed with this change as it could be a potentially backward incompatible changes, causing users' lambda function who rely on this behaviour to add the policy to no longer work. SAM promises to always guarantee backward compatibility and that's why we cannot proceed with this change. One additional workaround that I just think of is to rely on the use of
This would resolve the intrinsics into a static value and when SAM transform the template, it knows the exact value and would hence not add the policy. |
@GavinZZ Got you. Thanks! I will take this workaround into account. |
Closing this issue as it's not in a workable state due to backward compatibility issue. Feel free to open another issue if you have additional questions. |
|
Description:
SAM seems to add
AWSLambdaVPCAccessExecutionRole
simply because it detects theVpcConfig
without checking the condition.Steps to reproduce:
I create a simple hello-world lambda function as following:
and deploy it as following
Observed result:
When it successfully finishes deployment I go to my lambda function and check
Configuration
->VPC
. There is no associated security group or subnet. However, when I check the created role it contains two AWS Managed Policies:Expected result:
Because the condition under the
VpcConfig
section is always false, it does not associate the lambda with a subnet and a security group as expected. I also expect the sam not to add unnecessary permissionAWSLambdaVPCAccessExecutionRole
because I don't associate the lambda with any VPC. Nevertheless, it addsAWSLambdaVPCAccessExecutionRole
.While the extra privilege does not harm in this particular case, the intention was to remove the
VpcConfig
property usingIf
operator and hence prevent addingVPC Access
privileges.Additional environment details:
sam --version
: 1.105.0Project structure
🗂️
lib
⚙︎
samconfig.toml
❗️
template.yaml
lib
folderDockerfile
Gemfile
handler.rb
samconfig.toml
The text was updated successfully, but these errors were encountered: