fix(gcp): make logging sink check at project level (#7421)

This commit is contained in:
Sergio Garcia
2025-04-03 09:37:46 -04:00
committed by GitHub
parent d8dce07019
commit 41e576f4f1
2 changed files with 24 additions and 17 deletions
@@ -5,23 +5,13 @@ from prowler.providers.gcp.services.logging.logging_client import logging_client
class logging_sink_created(Check):
def execute(self) -> Check_Report_GCP:
findings = []
projects_with_sink = set()
projects_with_logging_sink = {}
for sink in logging_client.sinks:
report = Check_Report_GCP(
metadata=self.metadata(),
resource=sink,
location=logging_client.region,
)
projects_with_sink.add(sink.project_id)
report.status = "FAIL"
report.status_extended = f"Sink {sink.name} is enabled but not exporting copies of all the log entries in project {sink.project_id}."
if sink.filter == "all":
report.status = "PASS"
report.status_extended = f"Sink {sink.name} is enabled exporting copies of all the log entries in project {sink.project_id}."
findings.append(report)
projects_with_logging_sink[sink.project_id] = sink
for project in logging_client.project_ids:
if project not in projects_with_sink:
if project not in projects_with_logging_sink.keys():
report = Check_Report_GCP(
metadata=self.metadata(),
resource=logging_client.projects[project],
@@ -31,5 +21,13 @@ class logging_sink_created(Check):
report.status = "FAIL"
report.status_extended = f"There are no logging sinks to export copies of all the log entries in project {project}."
findings.append(report)
else:
report = Check_Report_GCP(
metadata=self.metadata(),
resource=projects_with_logging_sink[project],
location=logging_client.region,
)
report.status = "PASS"
report.status_extended = f"Sink {projects_with_logging_sink[project].name} is enabled exporting copies of all the log entries in project {project}."
findings.append(report)
return findings
@@ -146,6 +146,15 @@ class Test_logging_sink_created:
project_id=GCP_PROJECT_ID,
)
]
logging_client.projects = {
GCP_PROJECT_ID: GCPProject(
id=GCP_PROJECT_ID,
number="123456789012",
name="test",
labels={},
lifecycle_state="ACTIVE",
)
}
check = logging_sink_created()
result = check.execute()
@@ -153,9 +162,9 @@ class Test_logging_sink_created:
assert result[0].status == "FAIL"
assert (
result[0].status_extended
== f"Sink sink1 is enabled but not exporting copies of all the log entries in project {GCP_PROJECT_ID}."
== f"There are no logging sinks to export copies of all the log entries in project {GCP_PROJECT_ID}."
)
assert result[0].resource_id == "sink1"
assert result[0].resource_name == "sink1"
assert result[0].resource_id == GCP_PROJECT_ID
assert result[0].resource_name == "test"
assert result[0].project_id == GCP_PROJECT_ID
assert result[0].location == GCP_EU1_LOCATION