diff --git a/prowler/providers/aws/services/iam/lib/policy.py b/prowler/providers/aws/services/iam/lib/policy.py index 95af304b3f..98577c01c6 100644 --- a/prowler/providers/aws/services/iam/lib/policy.py +++ b/prowler/providers/aws/services/iam/lib/policy.py @@ -187,9 +187,14 @@ def is_policy_public( or ( # Check if function can be invoked by other AWS services ( ".amazonaws.com" in principal.get("Service", "") + or ".amazon.com" in principal.get("Service", "") or "*" in principal.get("Service", "") ) ) + and "secretsmanager.amazonaws.com" + not in principal.get( + "Service", "" + ) # AWS ensures that resources called by SecretsManager are executed in the same AWS account ) ) ) and ( @@ -276,6 +281,7 @@ def is_condition_block_restrictive( "aws:sourcearn", "aws:sourcevpc", "aws:sourcevpce", + "lambda:eventsourcetoken", # For Alexa Home functions, a token that the invoker must supply. ], "StringLike": [ "aws:sourceaccount", diff --git a/tests/providers/aws/services/iam/lib/policy_test.py b/tests/providers/aws/services/iam/lib/policy_test.py index 5b62dc61e3..89ff4de5e5 100644 --- a/tests/providers/aws/services/iam/lib/policy_test.py +++ b/tests/providers/aws/services/iam/lib/policy_test.py @@ -1867,6 +1867,39 @@ class Test_Policy: } assert is_policy_public(policy) + def test__is_policy_public_secrets_manager( + self, + ): + policy = { + "Statement": [ + { + "Sid": "test", + "Effect": "Allow", + "Principal": {"Service": "secretsmanager.amazonaws.com"}, + "Action": "lambda:GetFunction", + "Resource": "*", + } + ] + } + assert not is_policy_public(policy) + + def test__is_policy_public_alexa_condition( + self, + ): + policy = { + "Statement": [ + { + "Sid": "test", + "Effect": "Allow", + "Principal": {"Service": "alexa-connectedhome.amazon.com"}, + "Action": "lambda:GetFunction", + "Resource": "*", + "Condition": {"StringEquals": {"lambda:EventSourceToken": "test"}}, + } + ] + } + assert not is_policy_public(policy) + def test_check_admin_access(self): policy = { "Version": "2012-10-17",