mirror of
https://github.com/ghndrx/prowler.git
synced 2026-02-10 23:05:05 +00:00
fix(fms): Handle PolicyComplianceStatusList key error (#3230)
Co-authored-by: Sergio Garcia <sergargar1@gmail.com>
This commit is contained in:
@@ -13,17 +13,21 @@ class fms_policy_compliant(Check):
|
|||||||
report.status = "PASS"
|
report.status = "PASS"
|
||||||
report.status_extended = "FMS enabled with all compliant accounts."
|
report.status_extended = "FMS enabled with all compliant accounts."
|
||||||
non_compliant_policy = False
|
non_compliant_policy = False
|
||||||
for policy in fms_client.fms_policies:
|
if fms_client.fms_policies:
|
||||||
for policy_to_account in policy.compliance_status:
|
for policy in fms_client.fms_policies:
|
||||||
if policy_to_account.status == "NON_COMPLIANT":
|
for policy_to_account in policy.compliance_status:
|
||||||
report.status = "FAIL"
|
if policy_to_account.status == "NON_COMPLIANT":
|
||||||
report.status_extended = f"FMS with non-compliant policy {policy.name} for account {policy_to_account.account_id}."
|
report.status = "FAIL"
|
||||||
report.resource_id = policy.id
|
report.status_extended = f"FMS with non-compliant policy {policy.name} for account {policy_to_account.account_id}."
|
||||||
report.resource_arn = policy.arn
|
report.resource_id = policy.id
|
||||||
non_compliant_policy = True
|
report.resource_arn = policy.arn
|
||||||
|
non_compliant_policy = True
|
||||||
|
break
|
||||||
|
if non_compliant_policy:
|
||||||
break
|
break
|
||||||
if non_compliant_policy:
|
else:
|
||||||
break
|
report.status = "FAIL"
|
||||||
|
report.status_extended = f"FMS without any compliant policy for account {fms_client.audited_account}."
|
||||||
|
|
||||||
findings.append(report)
|
findings.append(report)
|
||||||
return findings
|
return findings
|
||||||
|
|||||||
@@ -66,7 +66,9 @@ class FMS(AWSService):
|
|||||||
for page in list_compliance_status_paginator.paginate(
|
for page in list_compliance_status_paginator.paginate(
|
||||||
PolicyId=fms_policy.id
|
PolicyId=fms_policy.id
|
||||||
):
|
):
|
||||||
for fms_compliance_status in page["PolicyComplianceStatusList"]:
|
for fms_compliance_status in page.get(
|
||||||
|
"PolicyComplianceStatusList", []
|
||||||
|
):
|
||||||
fms_policy.compliance_status.append(
|
fms_policy.compliance_status.append(
|
||||||
PolicyAccountComplianceStatus(
|
PolicyAccountComplianceStatus(
|
||||||
account_id=fms_compliance_status.get("MemberAccount"),
|
account_id=fms_compliance_status.get("MemberAccount"),
|
||||||
|
|||||||
@@ -170,3 +170,32 @@ class Test_fms_policy_compliant:
|
|||||||
assert result[0].resource_id == "12345678901"
|
assert result[0].resource_id == "12345678901"
|
||||||
assert result[0].resource_arn == "arn:aws:fms:us-east-1:12345678901"
|
assert result[0].resource_arn == "arn:aws:fms:us-east-1:12345678901"
|
||||||
assert result[0].region == AWS_REGION_US_EAST_1
|
assert result[0].region == AWS_REGION_US_EAST_1
|
||||||
|
|
||||||
|
def test_fms_admin_without_policies(self):
|
||||||
|
fms_client = mock.MagicMock
|
||||||
|
fms_client.audited_account = AWS_ACCOUNT_NUMBER
|
||||||
|
fms_client.audited_account_arn = f"arn:aws:iam::{AWS_ACCOUNT_NUMBER}:root"
|
||||||
|
fms_client.region = AWS_REGION_US_EAST_1
|
||||||
|
fms_client.fms_admin_account = True
|
||||||
|
fms_client.fms_policies = []
|
||||||
|
with mock.patch(
|
||||||
|
"prowler.providers.aws.services.fms.fms_service.FMS",
|
||||||
|
new=fms_client,
|
||||||
|
):
|
||||||
|
# Test Check
|
||||||
|
from prowler.providers.aws.services.fms.fms_policy_compliant.fms_policy_compliant import (
|
||||||
|
fms_policy_compliant,
|
||||||
|
)
|
||||||
|
|
||||||
|
check = fms_policy_compliant()
|
||||||
|
result = check.execute()
|
||||||
|
|
||||||
|
assert len(result) == 1
|
||||||
|
assert result[0].status == "FAIL"
|
||||||
|
assert (
|
||||||
|
result[0].status_extended
|
||||||
|
== f"FMS without any compliant policy for account {AWS_ACCOUNT_NUMBER}."
|
||||||
|
)
|
||||||
|
assert result[0].resource_id == AWS_ACCOUNT_NUMBER
|
||||||
|
assert result[0].resource_arn == fms_client.audited_account_arn
|
||||||
|
assert result[0].region == AWS_REGION_US_EAST_1
|
||||||
|
|||||||
Reference in New Issue
Block a user