-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(athena): add new check
athena_workgroup_logging_enabled
(#5468)
- Loading branch information
Showing
6 changed files
with
236 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
34 changes: 34 additions & 0 deletions
34
...es/athena/athena_workgroup_logging_enabled/athena_workgroup_logging_enabled.metadata.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{ | ||
"Provider": "aws", | ||
"CheckID": "athena_workgroup_logging_enabled", | ||
"CheckTitle": "Ensure that logging is enabled for Amazon Athena workgroups to capture query activity.", | ||
"CheckType": [ | ||
"Software and Configuration Checks/AWS Security Best Practices/Logging" | ||
], | ||
"ServiceName": "athena", | ||
"SubServiceName": "", | ||
"ResourceIdTemplate": "arn:partition:athena:region:account-id:workgroup/resource-id", | ||
"Severity": "medium", | ||
"ResourceType": "AwsAthenaWorkGroup", | ||
"Description": "Enabling logging for a workgroup provides valuable insights into query activity, including user actions, query execution details, and potential security events.", | ||
"Risk": "Without logging enabled, it can be difficult to track and investigate potential security incidents or unauthorized access to Athena data. This can lead to data breaches, compliance violations, and increased security risks.", | ||
"RelatedUrl": "https://docs.aws.amazon.com/athena/latest/ug/security-logging-monitoring.html", | ||
"Remediation": { | ||
"Code": { | ||
"CLI": "", | ||
"NativeIaC": "", | ||
"Other": "https://docs.aws.amazon.com/securityhub/latest/userguide/athena-controls.html#athena-4", | ||
"Terraform": "" | ||
}, | ||
"Recommendation": { | ||
"Text": "Enable logging for your Athena workgroups to capture query activity and enhance security monitoring. Configure the output location for logs in a secure S3 bucket and ensure appropriate encryption is applied.", | ||
"Url": "https://docs.aws.amazon.com/athena/latest/ug/athena-cloudwatch-metrics-enable.html" | ||
} | ||
}, | ||
"Categories": [ | ||
"logging" | ||
], | ||
"DependsOn": [], | ||
"RelatedTo": [], | ||
"Notes": "" | ||
} |
40 changes: 40 additions & 0 deletions
40
.../aws/services/athena/athena_workgroup_logging_enabled/athena_workgroup_logging_enabled.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from typing import List | ||
|
||
from prowler.lib.check.models import Check, Check_Report_AWS | ||
from prowler.providers.aws.services.athena.athena_client import athena_client | ||
|
||
|
||
class athena_workgroup_logging_enabled(Check): | ||
"""Check if there are Athena workgroups with logging disabled.""" | ||
|
||
def execute(self) -> List[Check_Report_AWS]: | ||
"""Execute the Athena workgroup logging enabled check. | ||
Iterates over all Athena workgroups and checks if is publishing logs to CloudWatch. | ||
Returns: | ||
List of reports object with the findings of each workgroup. | ||
""" | ||
findings = [] | ||
for workgroup in athena_client.workgroups.values(): | ||
# Only check for enabled and used workgroups (has recent queries) | ||
if ( | ||
workgroup.state == "ENABLED" and workgroup.queries | ||
) or athena_client.provider.scan_unused_services: | ||
report = Check_Report_AWS(self.metadata()) | ||
report.resource_id = workgroup.name | ||
report.resource_arn = workgroup.arn | ||
report.region = workgroup.region | ||
report.resource_tags = workgroup.tags | ||
report.status = "PASS" | ||
report.status_extended = ( | ||
f"Athena WorkGroup {workgroup.name} has CloudWatch logging enabled." | ||
) | ||
|
||
if not workgroup.cloudwatch_logging: | ||
report.status = "FAIL" | ||
report.status_extended = f"Athena WorkGroup {workgroup.name} does not have CloudWatch logging enabled." | ||
|
||
findings.append(report) | ||
|
||
return findings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
...services/athena/athena_workgroup_logging_enabled/athena_workgroup_logging_enabled_test.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
from unittest.mock import patch | ||
|
||
from boto3 import client | ||
from moto import mock_aws | ||
|
||
from tests.providers.aws.utils import ( | ||
AWS_ACCOUNT_NUMBER, | ||
AWS_REGION_EU_WEST_1, | ||
set_mocked_aws_provider, | ||
) | ||
|
||
ATHENA_PRIMARY_WORKGROUP = "primary" | ||
ATHENA_PRIMARY_WORKGROUP_ARN = f"arn:aws:athena:{AWS_REGION_EU_WEST_1}:{AWS_ACCOUNT_NUMBER}:workgroup/{ATHENA_PRIMARY_WORKGROUP}" | ||
|
||
|
||
class Test_athena_workgroup_logging_enabled: | ||
@mock_aws | ||
def test_primary_workgroup_logging_disabled(self): | ||
from prowler.providers.aws.services.athena.athena_service import Athena | ||
|
||
aws_provider = set_mocked_aws_provider([AWS_REGION_EU_WEST_1]) | ||
|
||
with patch( | ||
"prowler.providers.common.provider.Provider.get_global_provider", | ||
return_value=aws_provider, | ||
), patch( | ||
"prowler.providers.aws.services.athena.athena_workgroup_logging_enabled.athena_workgroup_logging_enabled.athena_client", | ||
new=Athena(aws_provider), | ||
): | ||
from prowler.providers.aws.services.athena.athena_workgroup_logging_enabled.athena_workgroup_logging_enabled import ( | ||
athena_workgroup_logging_enabled, | ||
) | ||
|
||
check = athena_workgroup_logging_enabled() | ||
result = check.execute() | ||
|
||
assert len(result) == 1 | ||
assert result[0].status == "FAIL" | ||
assert ( | ||
result[0].status_extended | ||
== f"Athena WorkGroup {ATHENA_PRIMARY_WORKGROUP} does not have CloudWatch logging enabled." | ||
) | ||
assert result[0].resource_id == ATHENA_PRIMARY_WORKGROUP | ||
assert result[0].resource_arn == ATHENA_PRIMARY_WORKGROUP_ARN | ||
assert result[0].region == AWS_REGION_EU_WEST_1 | ||
assert result[0].resource_tags == [] | ||
|
||
@mock_aws | ||
def test_primary_workgroup_logging_disabled_ignoring(self): | ||
from prowler.providers.aws.services.athena.athena_service import Athena | ||
|
||
aws_provider = set_mocked_aws_provider([AWS_REGION_EU_WEST_1]) | ||
aws_provider._scan_unused_services = False | ||
|
||
with patch( | ||
"prowler.providers.common.provider.Provider.get_global_provider", | ||
return_value=aws_provider, | ||
), patch( | ||
"prowler.providers.aws.services.athena.athena_workgroup_logging_enabled.athena_workgroup_logging_enabled.athena_client", | ||
new=Athena(aws_provider), | ||
): | ||
from prowler.providers.aws.services.athena.athena_workgroup_logging_enabled.athena_workgroup_logging_enabled import ( | ||
athena_workgroup_logging_enabled, | ||
) | ||
|
||
check = athena_workgroup_logging_enabled() | ||
result = check.execute() | ||
|
||
assert len(result) == 0 | ||
|
||
@mock_aws | ||
def test_primary_workgroup_logging_enabled(self): | ||
athena_client = client("athena", region_name=AWS_REGION_EU_WEST_1) | ||
|
||
# Delete and recreate the primary workgroup with logging enabled | ||
athena_client.delete_work_group(WorkGroup=ATHENA_PRIMARY_WORKGROUP) | ||
|
||
athena_client.create_work_group( | ||
Name=ATHENA_PRIMARY_WORKGROUP, | ||
Configuration={ | ||
"ResultConfiguration": { | ||
"OutputLocation": f"s3://aws-athena-query-results-{AWS_ACCOUNT_NUMBER}-{AWS_REGION_EU_WEST_1}/", | ||
"EncryptionConfiguration": {"EncryptionOption": "SSE_S3"}, | ||
}, | ||
"EnforceWorkGroupConfiguration": False, | ||
"PublishCloudWatchMetricsEnabled": True, | ||
"BytesScannedCutoffPerQuery": 100000000, | ||
"RequesterPaysEnabled": False, | ||
"EngineVersion": { | ||
"SelectedEngineVersion": "Athena engine version 2", | ||
"EffectiveEngineVersion": "Athena engine version 2", | ||
}, | ||
}, | ||
Description="Primary WorkGroup", | ||
) | ||
|
||
from prowler.providers.aws.services.athena.athena_service import Athena | ||
|
||
aws_provider = set_mocked_aws_provider([AWS_REGION_EU_WEST_1]) | ||
|
||
with patch( | ||
"prowler.providers.common.provider.Provider.get_global_provider", | ||
return_value=aws_provider, | ||
), patch( | ||
"prowler.providers.aws.services.athena.athena_workgroup_logging_enabled.athena_workgroup_logging_enabled.athena_client", | ||
new=Athena(aws_provider), | ||
): | ||
from prowler.providers.aws.services.athena.athena_workgroup_logging_enabled.athena_workgroup_logging_enabled import ( | ||
athena_workgroup_logging_enabled, | ||
) | ||
|
||
check = athena_workgroup_logging_enabled() | ||
result = check.execute() | ||
|
||
assert len(result) == 1 | ||
assert result[0].status == "PASS" | ||
assert ( | ||
result[0].status_extended | ||
== f"Athena WorkGroup {ATHENA_PRIMARY_WORKGROUP} has CloudWatch logging enabled." | ||
) | ||
assert result[0].resource_id == ATHENA_PRIMARY_WORKGROUP | ||
assert result[0].resource_arn == ATHENA_PRIMARY_WORKGROUP_ARN | ||
assert result[0].region == AWS_REGION_EU_WEST_1 | ||
assert result[0].resource_tags == [] |