Skip to content

Commit 71d7eeb

Browse files
authored
[Tuning] Public Lambda Policy Tuning (panther-labs#1501)
1 parent ae21133 commit 71d7eeb

File tree

2 files changed

+58
-3
lines changed

2 files changed

+58
-3
lines changed

policies/aws_lambda_policies/aws_lambda_public_access.py

+17-3
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,26 @@
44

55

66
def policy(resource):
7-
json_policy = json.loads(deep_get(resource, "Policy", "Policy"))
7+
json_policy = json.loads(deep_get(resource, "Policy", "Policy", default="{}"))
88
if any(
99
(statement.get("Principal") == "*" or deep_get(statement, "Principal", "AWS") == "*")
1010
and statement.get("Effect") == "Allow"
11-
and statement.get("Condition", {}) == {}
12-
for statement in json_policy.get("Statement")
11+
and (
12+
statement.get("Condition", {}) == {}
13+
or deep_get(statement, "Condition", "StringEquals", "lambda:FunctionUrlAuthType")
14+
== "NONE"
15+
)
16+
for statement in json_policy.get("Statement", [])
1317
):
1418
return False
1519
return True
20+
21+
22+
def severity(resource):
23+
json_policy = json.loads(deep_get(resource, "Policy", "Policy", default="{}"))
24+
if not any(
25+
deep_get(statement, "Condition", "StringEquals", "lambda:FunctionUrlAuthType") == "NONE"
26+
for statement in json_policy.get("Statement", [])
27+
):
28+
return "LOW"
29+
return "DEFAULT"

policies/aws_lambda_policies/aws_lambda_public_access.yml

+41
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,44 @@ Tests:
104104
Role: arn:aws:iam::123456789:role/some-name
105105
Timeout: 10
106106
Version: $LATEST
107+
- Name: AWS Lambda No Policy
108+
ExpectedResult: true
109+
Resource:
110+
AccountId: "123456789"
111+
Arn: arn:aws:lambda:us-west-2:123456789:function:some-name
112+
CodeSha256: azertyuiopqsdfghjklm
113+
CodeSize: 1234
114+
Description: Some description
115+
Handler: some-name.lambda_handler
116+
LastModified: 2024-09-13T15:23:51.000+0000
117+
MemorySize: 128
118+
Name: some-name
119+
Region: us-west-2
120+
ResourceId: arn:aws:lambda:us-west-2:123456789:function:some-name
121+
ResourceType: AWS.Lambda.Function
122+
RevisionId: 123456789-1234-1234-1234-123456789123
123+
Role: arn:aws:iam::123456789:role/some-name
124+
Timeout: 10
125+
Version: $LATEST
126+
- Name: AWS Lambda Unauthenticated Public Access
127+
ExpectedResult: false
128+
Resource:
129+
AccountId: "123456789"
130+
Arn: arn:aws:lambda:us-west-2:123456789:function:some-name
131+
CodeSha256: azertyuiopqsdfghjklm
132+
CodeSize: 1234
133+
Description: Some description
134+
Handler: some-name.lambda_handler
135+
LastModified: 2024-09-13T15:23:51.000+0000
136+
MemorySize: 128
137+
Name: some-name
138+
Policy:
139+
Policy: '{"Version":"2012-10-17","Id":"default","Statement":[{"Sid":"AllowExecutionFromCloudWatch","Effect":"Allow","Principal":{"AWS":"*"},"Action":"lambda:InvokeFunction","Resource":"arn:aws:lambda:us-west-2:123456789:function:some-name","Condition":{"StringEquals":{"lambda:FunctionUrlAuthType":"NONE"}}}]}'
140+
RevisionId: 123456789-1234-1234-1234-123456789123
141+
Region: us-west-2
142+
ResourceId: arn:aws:lambda:us-west-2:123456789:function:some-name
143+
ResourceType: AWS.Lambda.Function
144+
RevisionId: 123456789-1234-1234-1234-123456789123
145+
Role: arn:aws:iam::123456789:role/some-name
146+
Timeout: 10
147+
Version: $LATEST

0 commit comments

Comments
 (0)