Panther high experimental python

AWS CloudTrail S3 Bucket Public

This policy validates that CloudTrail S3 buckets are not publicly accessible.

View Source

Detection Logic

from panther_aws_helpers import BadLookup, aws_regions, resource_lookup
from panther_base_helpers import deep_get

BAD_PERMISSIONS = {
    "http://acs.amazonaws.com/groups/global/AuthenticatedUsers",
    "http://acs.amazonaws.com/groups/global/AllUsers",
}

# docs.aws.amazon.com/codepipeline/latest/userguide/reference-ct-placeholder-buckets.html
EXCLUDED_BUCKET_NAMES = {
    f"codepipeline-cloudtrail-placeholder-bucket-{region}" for region in aws_regions()
}


def policy(resource):
    bucket_arn = "arn:aws:s3:::" + resource["S3BucketName"]

    try:
        bucket = resource_lookup(bucket_arn)
    except BadLookup:
        return True

    for grant in bucket["Grants"] or []:
        if deep_get(grant, "Grantee", "URI") in BAD_PERMISSIONS and not any(
            bucket_name in bucket_arn for bucket_name in EXCLUDED_BUCKET_NAMES
        ):
            return False

    return True

Field Validations

Loading…

Comments (0)

Loading comments...