fix(kms): handle empty principal error (#2192)

This commit is contained in:
Sergio Garcia
2023-04-11 16:59:29 +02:00
committed by GitHub
parent e75022763c
commit 9104d2e89e
2 changed files with 52 additions and 2 deletions

View File

@@ -20,14 +20,17 @@ class kms_key_not_publicly_accessible(Check):
if key.policy and "Statement" in key.policy:
for statement in key.policy["Statement"]:
if (
"*" == statement["Principal"]
"Principal" in statement
and "*" == statement["Principal"]
and "Condition" not in statement
):
report.status = "FAIL"
report.status_extended = (
f"KMS key {key.id} may be publicly accessible!"
)
elif "AWS" in statement["Principal"]:
elif (
"Principal" in statement and "AWS" in statement["Principal"]
):
if type(statement["Principal"]["AWS"]) == str:
principals = [statement["Principal"]["AWS"]]
else: