Skip to content

Commit

Permalink
Merge pull request #6292 from Checkmarx/kics706
Browse files Browse the repository at this point in the history
fix(query): serverless_function_without_unique_iam_role
  • Loading branch information
gabriel-cx authored Apr 12, 2023
2 parents 7b0ba2d + 7235a99 commit 4e841b2
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import data.generic.serverlessfw as sfw_lib
CxPolicy[result] {
document := input.document[i]
functions := document.functions
is_object(functions)
function := functions[fname]

not common_lib.valid_key(function, "role")
Expand All @@ -21,3 +22,23 @@ CxPolicy[result] {
"searchLine": common_lib.build_search_line(["functions", fname], []),
}
}

CxPolicy[result] {
document := input.document[i]
functions := document.functions
is_array(functions)
function := functions[k][fname]

not common_lib.valid_key(function, "role")

result := {
"documentId": input.document[i].id,
"resourceType": sfw_lib.resourceTypeMapping("function", document.provider.name),
"resourceName": fname,
"searchKey": sprintf("functions[%s].%s", [k,fname]),
"issueType": "MissingAttribute",
"keyExpectedValue": "'role' should be defined inside the function",
"keyActualValue": "'role' is not defined",
"searchLine": common_lib.build_search_line(["functions",k ,fname], []),
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
service: service
frameworkVersion: '2'
provider:
name: aws
runtime: nodejs12.x

functions:
- hello:
handler: handler.hello
onError: arn:aws:sns:us-east-1:XXXXXX:test
tags:
foo: bar
role: arn:aws:iam::XXXXXX:role/role
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
service: service
frameworkVersion: '2'
provider:
name: aws
runtime: nodejs12.x

functions:
- hello:
handler: handler.hello
onError: arn:aws:sns:us-east-1:XXXXXX:test
tags:
foo: bar
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,11 @@
"severity": "MEDIUM",
"line": 8,
"fileName": "positive1.yml"
},
{
"queryName": "Serverless Function Without Unique IAM Role",
"severity": "MEDIUM",
"line": 8,
"fileName": "positive2.yml"
}
]

0 comments on commit 4e841b2

Please sign in to comment.