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

  1. 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)

Most upvoted comments

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 Critical to Medium sounds 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 and critical failed 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.

Thanks again for your report and for using Prowler! 🚀

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 Condition block the AWS Lambda Function will not be flagged as a FAIL unless the policy has an *. So, for your policy examples:

Secrets Manager + Lambda

The following policy will flag the Lambda as PASS using the is_condition_block_restrictive function, either the audited account is set or another cross-account, in that case setting is_cross_account_allowed = True.

"Principal": {
        "Service": "secretsmanager.amazonaws.com"
},
"Condition": {
        "StringEquals": {
          "AWS:SourceAccount": "000000000000"
        }
}

CloudWatch Events + Lambda

The following policy will flag the Lambda as PASS using the is_condition_block_restrictive function, either the audited account is set or another cross-account, in that case setting is_cross_account_allowed = True.

"Principal": {
        "Service": "events.amazonaws.com"
},
"Condition": {
        "ArnLike": {
          "AWS:SourceArn": "arn:aws:events:eu-central-1:000000000000:rule/..."
        }
      }

S3 + Lambda

The following policy will flag the Lambda as PASS using the is_condition_block_restrictive function. In this case the is_condition_block_restrictive will need to handle the case where the ARN does not contains an AWS Account Number.

"Principal": {
        "Service": "s3.amazonaws.com"
},
"Condition": {
        "ArnLike": {
          "AWS:SourceArn": "arn:aws:s3:::mybucket"
        }
}

API Gateway + Lambda

The following policy will flag the Lambda as PASS using the is_condition_block_restrictive function, either the audited account is set or another cross-account, in that case setting is_cross_account_allowed = True.

"Principal": {
        "Service": "apigateway.amazonaws.com"
},
"Condition": {
        "ArnLike":{
                   "AWS:SourceArn": "arn:aws:execute-api:eu-central-1:123456789012:abcdefghi/*/GET/\{proxy+}"
        }
      }

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

  • Call the is_condition_block_restrictive function with is_cross_account_allowed = True to the awslambda_function_not_publicly_accessible check.
  • Improve the is_condition_block_restrictive to 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 condition statements 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_public returned already False after evaluation of the first statement. This should be fixed.

{
  "Version": "2012-10-17",
  "Id": "default",
  "Statement": [
    {
      "Sid": "AllowExecutionFromAPIGateway",
      "Effect": "Allow",
      "Principal": {
        "Service": "apigateway.amazonaws.com"
      },
      "Action": "lambda:InvokeFunction",
      "Resource": "arn:aws:lambda:eu-central-1:123456789012:function:foo",
      "Condition": {
        "ArnLike": {
          "AWS:SourceArn": "arn:aws:execute-api:eu-central-1:123456789012:bar/*/GET/{proxy+}"
        }
      }
    },
    {
      "Sid": "FunctionURLAllowPublicAccess",
      "Effect": "Allow",
      "Principal": "*",
      "Action": "lambda:InvokeFunctionUrl",
      "Resource": "arn:aws:lambda:eu-central-1:123456789012:function:foo",
      "Condition": {
        "StringEquals": {
          "lambda:FunctionUrlAuthType": "NONE"
        }
      }
    }
  ]
}

Hi @jfagoagas, I think your suggestion would remove a lot of false positives which would make the check useful for us again. However, as @puchy22 pointed out, the check may still produce false negatives (but not more than before) because of transitive dependencies which the check cannot verify. In my AllowExecutionFromAPIGateway example above, if the APIGateway is publicly accessible, then the Lambda function is also publicly accessible. However, if a Lambda function must be publicly accessible, then it’s common and good practice to put an APIGateway or an ALB etc. as a layer of defense in front of the Lambda to avoid making the Lambda directly publicly accessible. Furthermore, prowler would alert the publicly accessible APIGateway or ALB anyway as long as prowler is run against the account they are running on. So I think your suggestion is a good solution. I agree also with the two points in your To-Do block.

That’s great! Thank you for the insight, we will work on this next week.