fix(aws): exclude member accounts in IAM Root Credentials check (#5813)

This commit is contained in:
Sergio Garcia
2024-11-19 10:06:12 -04:00
committed by GitHub
parent 7a4f5f34f7
commit a5f5967bb2
6 changed files with 31 additions and 5 deletions
@@ -6,7 +6,10 @@ class iam_no_root_access_key(Check):
def execute(self) -> Check_Report_AWS:
findings = []
# Check if the root credentials are managed by AWS Organizations
if "RootCredentialsManagement" not in iam_client.organization_features:
if (
iam_client.organization_features is not None
and "RootCredentialsManagement" not in iam_client.organization_features
):
for user in iam_client.credential_report:
if user["user"] == "<root_account>":
report = Check_Report_AWS(self.metadata())
@@ -27,7 +27,8 @@
"DependsOn": [],
"RelatedTo": [
"iam_root_hardware_mfa_enabled",
"iam_root_mfa_enabled"
"iam_root_mfa_enabled",
"iam_no_root_access_key"
],
"Notes": ""
"Notes": "This check skips findings for member accounts as they cannot execute the ListOrganizationsFeatures API call, which is restricted to the management account or delegated administrators."
}
@@ -11,6 +11,7 @@ class iam_root_credentials_management_enabled(Check):
if (
organizations_client.organization
and organizations_client.organization.status == "ACTIVE"
and iam_client.organization_features is not None
):
report = Check_Report_AWS(self.metadata())
report.region = iam_client.region
@@ -8,7 +8,10 @@ class iam_root_hardware_mfa_enabled(Check):
# This check is only available in Commercial Partition
if iam_client.audited_partition == "aws":
# Check if the root credentials are managed by AWS Organizations
if "RootCredentialsManagement" not in iam_client.organization_features:
if (
iam_client.organization_features is not None
and "RootCredentialsManagement" not in iam_client.organization_features
):
if iam_client.account_summary:
virtual_mfa = False
report = Check_Report_AWS(self.metadata())
@@ -6,7 +6,10 @@ class iam_root_mfa_enabled(Check):
def execute(self) -> Check_Report_AWS:
findings = []
# Check if the root credentials are managed by AWS Organizations
if "RootCredentialsManagement" not in iam_client.organization_features:
if (
iam_client.organization_features is not None
and "RootCredentialsManagement" not in iam_client.organization_features
):
if iam_client.credential_report:
for user in iam_client.credential_report:
if user["user"] == "<root_account>":
@@ -982,6 +982,21 @@ class IAM(AWSService):
logger.warning(
f"{self.region} -- {error.__class__.__name__}[{error.__traceback__.tb_lineno}]: {error}"
)
elif (
error.response["Error"]["Code"]
== "OrganizationNotInAllFeaturesModeException"
):
logger.warning(
f"{self.region} -- {error.__class__.__name__}[{error.__traceback__.tb_lineno}]: {error}"
)
elif (
error.response["Error"]["Code"]
== "AccountNotManagementOrDelegatedAdministratorException"
):
logger.warning(
f"{self.region} -- {error.__class__.__name__}[{error.__traceback__.tb_lineno}]: {error}"
)
self.organization_features = None
else:
logger.error(
f"{self.region} -- {error.__class__.__name__}[{error.__traceback__.tb_lineno}]: {error}"