Skip to content

Commit

Permalink
feat(general): add policy name and guidelines to CSV output (#6082)
Browse files Browse the repository at this point in the history
* add policy name and guidelines to CSV output

* fix fields for types

* change CSV header to match platform

* fix tests for CSV header
  • Loading branch information
mikeurbanski1 authored Mar 11, 2024
1 parent c5a2625 commit 458d526
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
8 changes: 7 additions & 1 deletion checkov/common/output/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
FILE_NAME_CONTAINER_IMAGES = f"{date_now}_container_images.csv"

FILE_NAME_IAC = f"{date_now}_iac.csv"
HEADER_IAC = ["Resource", "Path", "Git Org", "Git Repository", "Misconfigurations", "Severity"]
HEADER_IAC = ["Resource", "Path", "Git Org", "Git Repository", "Misconfigurations", "Severity", "Policy title", "Guideline"]

CTA_NO_API_KEY = "SCA, image and runtime findings are only available with a Prisma Cloud subscription."

Expand Down Expand Up @@ -115,11 +115,15 @@ def add_iac_resources(self, resource: Record | ExtraResource, git_org: str, git_

misconfig = None
severity = None
check_name = None
guideline = None
if isinstance(resource, Record) and resource.check_result["result"] == CheckResult.FAILED:
# only failed resources should be added with their misconfiguration
misconfig = resource.check_id
if resource.severity is not None:
severity = resource.severity.name
check_name = resource.check_name
guideline = resource.guideline
elif resource_id in self.iac_resource_cache:
# IaC resources shouldn't be added multiple times, if they don't have any misconfiguration
return
Expand All @@ -131,6 +135,8 @@ def add_iac_resources(self, resource: Record | ExtraResource, git_org: str, git_
"Git Repository": git_repository,
"Misconfigurations": misconfig,
"Severity": severity,
"Policy title": check_name,
"Guideline": guideline
}

if isinstance(resource, Record) and resource.details:
Expand Down
2 changes: 1 addition & 1 deletion tests/common/output/test_bom_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def test_iac_csv_output(self, tmp_path: Path):
with open(iac_file_path) as file:
content = file.readlines()
header = content[:1][0]
assert 'Resource,Path,Git Org,Git Repository,Misconfigurations,Severity\n' == header
assert 'Resource,Path,Git Org,Git Repository,Misconfigurations,Severity,Policy title,Guideline\n' == header
rows = content[1:]
assert 'aws_s3_bucket' in rows[0]

Expand Down
2 changes: 1 addition & 1 deletion tests/common/runner_registry/test_runner_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def test_compact_csv_output(self):
with open(iac_file_path) as file:
content = file.readlines()
header = content[:1][0]
self.assertEqual('Resource,Path,Git Org,Git Repository,Misconfigurations,Severity\n', header)
self.assertEqual('Resource,Path,Git Org,Git Repository,Misconfigurations,Severity,Policy title,Guideline\n', header)
rows = content[1:]
self.assertIn('aws_s3_bucket', rows[0])
oss_file_path = re.search("Persisting SBOM to (.*oss_packages.csv)", output).group(1)
Expand Down

0 comments on commit 458d526

Please sign in to comment.