forked from Checkmarx/kics
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added new query IAM role allows public assume for ansible Checkmarx#1419
- Loading branch information
Showing
5 changed files
with
123 additions
and
0 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
assets/queries/ansible/aws/IAM_role_allows_all_principals_to_assume/metadata.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"id": "IAM_role_allows_all_principals_to_assume", | ||
"queryName": "IAM role allows all principals to assume", | ||
"severity": "LOW", | ||
"category": "Identity and Access Management", | ||
"descriptionText": "IAM role allows all services or principals to assume it", | ||
"descriptionUrl": "https://docs.ansible.com/ansible/latest/collections/community/aws/iam_managed_policy_module.html" | ||
} |
64 changes: 64 additions & 0 deletions
64
assets/queries/ansible/aws/IAM_role_allows_all_principals_to_assume/query.rego
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package Cx | ||
|
||
CxPolicy [result] { | ||
document := input.document[i] | ||
tasks := getTasks(document) | ||
task := tasks[t] | ||
awsApiGateway := task["community.aws.iam_managed_policy"] | ||
contains(awsApiGateway.state, "present") | ||
policy := json_unmarshal(awsApiGateway.policy) | ||
statement := policy.Statement[_] | ||
resource := statement.Principal.AWS | ||
contains(resource, "arn:aws:iam::") | ||
contains(resource, ":root") | ||
not contains(statement.Effect,"Deny") | ||
clusterName := task.name | ||
result := { | ||
"documentId": input.document[i].id, | ||
"searchKey": sprintf("name={{%s}}.{{community.aws.iam_managed_policy}}.Statement.Principal.AWS", [clusterName]), | ||
"issueType": "IncorrectAttribute", | ||
"keyExpectedValue": "community.aws.iam_managed_policy.policy.Statement.Principal.AWS should not contain ':root", | ||
"keyActualValue": "community.aws.iam_managed_policy.policy.Statement.Principal.AWS contains ':root'" | ||
} | ||
} | ||
|
||
CxPolicy [result] { | ||
document := input.document[i] | ||
tasks := getTasks(document) | ||
task := tasks[t] | ||
awsApiGateway := task["community.aws.iam_managed_policy"] | ||
contains(awsApiGateway.state, "present") | ||
statement := awsApiGateway.policy.Statement[_] | ||
resource := statement.Principal[j].AWS | ||
contains(resource, "arn:aws:iam::") | ||
contains(resource, ":root") | ||
not contains(statement.Effect,"Deny") | ||
clusterName := task.name | ||
result := { | ||
"documentId": input.document[i].id, | ||
"searchKey": sprintf("name={{%s}}.{{community.aws.iam_managed_policy}}.Statement.Principal.AWS", [clusterName]), | ||
"issueType": "IncorrectAttribute", | ||
"keyExpectedValue": "community.aws.iam_managed_policy.policy.Statement.Principal.AWS should not contain ':root", | ||
"keyActualValue": "community.aws.iam_managed_policy.policy.Statement.Principal.AWS contains ':root'" | ||
} | ||
|
||
} | ||
|
||
|
||
json_unmarshal(s) = result { | ||
s == null | ||
result := json.unmarshal("{}") | ||
} | ||
|
||
json_unmarshal(s) = result { | ||
s != null | ||
result := json.unmarshal(s) | ||
} | ||
|
||
getTasks(document) = result { | ||
result := [body | playbook := document.playbooks[0]; body := playbook.tasks] | ||
count(result) != 0 | ||
} else = result { | ||
result := [body | playbook := document.playbooks[_]; body := playbook ] | ||
count(result) != 0 | ||
} |
11 changes: 11 additions & 0 deletions
11
assets/queries/ansible/aws/IAM_role_allows_all_principals_to_assume/test/negative.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
- name: Create IAM Managed Policy | ||
community.aws.iam_managed_policy: | ||
policy_name: "ManagedPolicy" | ||
policy: | ||
Version: "2012-10-17" | ||
Statement: | ||
- Effect: "Allow" | ||
Action: "logs:CreateLogGroup" | ||
Resource: "*" | ||
make_default: false | ||
state: present |
28 changes: 28 additions & 0 deletions
28
assets/queries/ansible/aws/IAM_role_allows_all_principals_to_assume/test/positive.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
- name: Create IAM Managed Policy | ||
community.aws.iam_managed_policy: | ||
policy_name: "ManagedPolicy" | ||
policy: | ||
Version: "2012-10-17" | ||
Statement: | ||
- Effect: "Allow" | ||
Action: "logs:CreateLogGroup" | ||
Resource: "*" | ||
Principal: | ||
- AWS: "arn:aws:iam::root" | ||
make_default: false | ||
state: present | ||
- name: Create2 IAM Managed Policy | ||
community.aws.iam_managed_policy: | ||
policy_name: "ManagedPolicy2" | ||
policy: > | ||
{ | ||
"Version": "2012-10-17", | ||
"Statement":[{ | ||
"Effect": "Allow", | ||
"Action": "logs:PutRetentionPolicy", | ||
"Resource": "*", | ||
"Principal" : { "AWS" : "arn:aws:iam::root" } | ||
}] | ||
} | ||
only_version: true | ||
state: present |
12 changes: 12 additions & 0 deletions
12
...s/ansible/aws/IAM_role_allows_all_principals_to_assume/test/positive_expected_result.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[ | ||
{ | ||
"queryName": "IAM role allows all principals to assume", | ||
"severity": "LOW", | ||
"line": 11 | ||
}, | ||
{ | ||
"queryName": "IAM role allows all principals to assume", | ||
"severity": "LOW", | ||
"line": 24 | ||
} | ||
] |