prowler: Many false positives for check awslambda_function_not_publicly_accessible
Steps to Reproduce
Ahoy! I am running prowler periodically on AWS. Since the latest version (Prowler 4.3.5) i am getting a lot of false positives on check awslambda_function_not_publicly_accessible.
From my understanding, the code is missing a check whether a condition is set in the resource based policy.
Here’s a redacted example policy that i have in place for a lambda-script:
{
"Version": "2012-10-17",
"Id": "default",
"Statement": [
{
"Sid": "awslambda-myLambdaScript-LambdaInvokePermission",
"Effect": "Allow",
"Principal": {
"Service": "ses.amazonaws.com"
},
"Action": "lambda:InvokeFunction",
"Resource": "arn:aws:lambda:<REGION>:<ACCOUNT-ID>:function:myLambdaScript",
"Condition": {
"StringEquals": {
"AWS:SourceAccount": "<ACCOUNT-ID>"
}
}
}
]
}
Notice that there’s a condition set to mitigate access from public. This condition allows SES to only invoke this function from within the account.
But still this policy would get flagged as failed check, stating:
Lambda function myLambdaFunction has a policy resource-based policy with public access.
Neither am i a python expert, nor a prowler-developer, but shouldn’t a condition statement get taken into consideration to determine whether a function is publicly accessible or not?
Anyway - I have multiple of such Resource-based policy documents and all of these get flagged as publicly accessible, when they are in fact not.
Could you double check and help me out verifying whether it’s a false positive // the check’s code is wrong?
Cheers. 😃
Expected behavior
The check awslambda_function_not_publicly_accessible should not fail when the Resource-based policy document contains a Condition which restricts access, like:
"Condition": {
"StringEquals": {
"AWS:SourceAccount": "<ACCOUNT-ID>"
}
}
Actual Result with Screenshots or Logs
When using a Condition, the check would still fail and state:
Lambda function myLambdaFunction has a policy resource-based policy with public access.
How did you install Prowler?
From pip package (pip install prowler)
Environment Resource
- Fargate Task
OS used
Container source image: docker.io/library/python:3.12-slim
cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
Prowler version
4.3.5
Pip version
24.2
Context
No response
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 3
- Comments: 24 (22 by maintainers)
Heyho @puchy22 , thanks for taking care and for your thorough analysis of my request, highly appreciated! 😃
I don’t know whether adjusting the severity from
CriticaltoMediumsounds like a good approach. As a user and in my context: I have set up a daily scan of multiple AWS accounts. I would get a notification for all new andcriticalfailed scans reported by prowler. Decreasing the severity would mean that i won’t get notified on new public lambda scripts.If the solution you came up with does not mitigate false positives given my policy-example (where the lambda script definitely is not public, but public in the same source aws account though), i would have to mute the whole scan which is bad. I can’t exclude lambda scripts by name because there are tons of thousands that i would have to check.
I really value that check and it made a lot of sense, until the false positives started. 😅
I’ll definitely check out the new variant once it became available, until then i will stay on version
4.2.4.Don’t thank me for using prowler. You are the heroes here for actively maintaining an awesome tool and keeping it open-source, making the world a more secure place. Thanks so much for your work and efforts! 😃
You guys bow to no-one!
@kagahd @chbiel
Regarding the policies you shared it will be quite easy to improve the check’s behaviour as I was mentioning earlier. The key point here is to set that if the policy has a
Conditionblock the AWS Lambda Function will not be flagged as aFAILunless the policy has an*. So, for your policy examples:Secrets Manager + Lambda
The following policy will flag the Lambda as
PASSusing theis_condition_block_restrictivefunction, either the audited account is set or another cross-account, in that case settingis_cross_account_allowed = True.CloudWatch Events + Lambda
The following policy will flag the Lambda as
PASSusing theis_condition_block_restrictivefunction, either the audited account is set or another cross-account, in that case settingis_cross_account_allowed = True.S3 + Lambda
The following policy will flag the Lambda as
PASSusing theis_condition_block_restrictivefunction. In this case theis_condition_block_restrictivewill need to handle the case where the ARN does not contains an AWS Account Number.API Gateway + Lambda
The following policy will flag the Lambda as
PASSusing theis_condition_block_restrictivefunction, either the audited account is set or another cross-account, in that case settingis_cross_account_allowed = True.Please, let us know what do you think about these use cases? The idea is to implement the fix and add the above as tests.
To-Do
is_condition_block_restrictivefunction withis_cross_account_allowed = Trueto theawslambda_function_not_publicly_accessiblecheck.is_condition_block_restrictiveto handle S3 ARNs which does not contains the AWS Account Number.We have exactly the same problem and therefore disabled the check, hopefully only temporarily. We consider to customize this check to take into account appropriate
conditionstatements in the resource-based policy document. However, we’d prefer to use prowler’s standard checks instead customized ones.Hey! @pr3l14t0r thanks for the report, we are evaluating this issue with the team and we will reach you with a solution!
You are right @kagahd! Thanks for noticing it 😄 I have made the needed changes for solving that here.
Hi @puchy22, thanks for the code changes! However, I think the code is prone for false negatives which prowler v4.2.3 handled still correctly. For example, the following policy would not be detected as public because only the first statement is checked. The first statement is “not public” because the condition statement contains the own AWS account number. However, the second statement is “public” but the function
is_policy_publicreturned alreadyFalseafter evaluation of the first statement. This should be fixed.That’s great! Thank you for the insight, we will work on this next week.