-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6700 from Checkmarx/kics-1035-logging
feat(query): ansible playbooks Logging of Sensitive Data
- Loading branch information
Showing
6 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
assets/queries/ansible/general/logging_of_sensitive_data/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,12 @@ | ||
{ | ||
"id": "59029ddf-e651-412b-ae7b-ff6d403184bc", | ||
"queryName": "Logging of Sensitive Data", | ||
"severity": "LOW", | ||
"category": "Best Practices", | ||
"descriptionText": "To keep sensitive values out of logs, tasks that expose them need to be marked defining 'no_log' and setting to True", | ||
"descriptionUrl": "https://ansible.readthedocs.io/projects/lint/rules/no-log-password/", | ||
"platform": "Ansible", | ||
"descriptionID": "a700e724", | ||
"cloudProvider": "common" | ||
} | ||
|
42 changes: 42 additions & 0 deletions
42
assets/queries/ansible/general/logging_of_sensitive_data/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,42 @@ | ||
package Cx | ||
|
||
import data.generic.ansible as ansLib | ||
import data.generic.common as commonLib | ||
|
||
CxPolicy[result] { | ||
task := ansLib.tasks[id][t] | ||
|
||
not commonLib.valid_key(task, "no_log") | ||
|
||
action := task["ansible.builtin.user"] | ||
commonLib.valid_key(action, "password") | ||
|
||
result := { | ||
"documentId": id, | ||
"resourceName": task.name, | ||
"resourceType": "ansible.builtin.user", | ||
"searchKey": sprintf("name={{%s}}", [task.name]), | ||
"issueType": "MissingAttribute", | ||
"keyExpectedValue": "'no_log' should be defined and set to 'true' in order to not expose sensitive data", | ||
"keyActualValue": "'no_log' is not defined", | ||
} | ||
} | ||
|
||
CxPolicy[result] { | ||
task := ansLib.tasks[id][t] | ||
|
||
task.no_log == false | ||
|
||
action := task["ansible.builtin.user"] | ||
commonLib.valid_key(action, "password") | ||
|
||
result := { | ||
"documentId": id, | ||
"resourceName": task.name, | ||
"resourceType": "ansible.builtin.user", | ||
"searchKey": sprintf("name={{%s}}.no_log", [task.name]), | ||
"issueType": "IncorrectValue", | ||
"keyExpectedValue": "'no_log' should be set to 'true' in order to not expose sensitive data", | ||
"keyActualValue": "'no_log' is set to false", | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
assets/queries/ansible/general/logging_of_sensitive_data/test/negative1.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,41 @@ | ||
--- | ||
- name: Negative playbook | ||
hosts: localhost | ||
tasks: | ||
- name: foo | ||
ansible.builtin.user: | ||
name: john_doe | ||
comment: John Doe | ||
uid: 1040 | ||
group: admin | ||
password: "{{ item }}" | ||
with_items: | ||
- wow | ||
no_log: true | ||
|
||
--- | ||
- name: Negative Playbook 2 | ||
hosts: localhost | ||
tasks: | ||
- name: bar | ||
ansible.builtin.user: | ||
name: john_doe | ||
comment: John Doe | ||
uid: 1040 | ||
group: admin | ||
with_items: | ||
- wow | ||
no_log: false | ||
|
||
--- | ||
- name: Negative Playbook 3 | ||
hosts: localhost | ||
tasks: | ||
- name: bar | ||
ansible.builtin.user: | ||
name: john_doe | ||
comment: John Doe | ||
uid: 1040 | ||
group: admin | ||
with_items: | ||
- wow |
14 changes: 14 additions & 0 deletions
14
assets/queries/ansible/general/logging_of_sensitive_data/test/positive1.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,14 @@ | ||
--- | ||
- name: Positive Playbook | ||
hosts: localhost | ||
tasks: | ||
- name: bar | ||
ansible.builtin.user: | ||
name: john_doe | ||
comment: John Doe | ||
uid: 1040 | ||
group: admin | ||
password: "{{ item }}" | ||
with_items: | ||
- wow | ||
no_log: false |
13 changes: 13 additions & 0 deletions
13
assets/queries/ansible/general/logging_of_sensitive_data/test/positive2.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,13 @@ | ||
--- | ||
- name: Positive Playbook | ||
hosts: localhost | ||
tasks: | ||
- name: bar | ||
ansible.builtin.user: | ||
name: john_doe | ||
comment: John Doe | ||
uid: 1040 | ||
group: admin | ||
password: "{{ item }}" | ||
with_items: | ||
- wow |
14 changes: 14 additions & 0 deletions
14
assets/queries/ansible/general/logging_of_sensitive_data/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,14 @@ | ||
[ | ||
{ | ||
"queryName": "Logging of Sensitive Data", | ||
"severity": "LOW", | ||
"line": 14, | ||
"fileName": "positive1.yaml" | ||
}, | ||
{ | ||
"queryName": "Logging of Sensitive Data", | ||
"severity": "LOW", | ||
"line": 5, | ||
"fileName": "positive2.yaml" | ||
} | ||
] |