-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(networkfirewall): add new check
networkfirewall_logging_enabled
(
#5145) Co-authored-by: Sergio Garcia <[email protected]>
- Loading branch information
1 parent
b2151e2
commit ff10108
Showing
6 changed files
with
328 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
34 changes: 34 additions & 0 deletions
34
...orkfirewall/networkfirewall_logging_enabled/networkfirewall_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": "networkfirewall_logging_enabled", | ||
"CheckTitle": "Ensure Network Firewall Logging is Enabled", | ||
"CheckType": [ | ||
"Software and Configuration Checks/Industry and Regulatory Standards/NIST 800-53" | ||
], | ||
"ServiceName": "network-firewall", | ||
"SubServiceName": "", | ||
"ResourceIdTemplate": "arn:partition:network-firewall::account-id:firewall/firewall-name", | ||
"Severity": "medium", | ||
"ResourceType": "AwsNetworkFirewallFirewall", | ||
"Description": "This control checks whether logging is enabled for an AWS Network Firewall firewall. The control fails if logging isn't enabled for at least one log type or if the logging destination doesn't exist.", | ||
"Risk": "Failing to enable logging on an AWS Network Firewall can lead to a lack of visibility into network traffic, making it difficult to monitor and respond to security incidents effectively, which could jeopardize the security and integrity of your infrastructure.", | ||
"RelatedUrl": "https://docs.aws.amazon.com/network-firewall/latest/developerguide/firewall-logging.html", | ||
"Remediation": { | ||
"Code": { | ||
"CLI": "aws network-firewall update-logging-configuration --firewall-arn <firewall-arn> --logging-configuration <configuration>", | ||
"NativeIaC": "", | ||
"Other": "https://docs.aws.amazon.com/securityhub/latest/userguide/networkfirewall-controls.html#networkfirewall-2", | ||
"Terraform": "" | ||
}, | ||
"Recommendation": { | ||
"Text": "Enable logging for your AWS Network Firewall by updating its logging configuration to ensure comprehensive tracking of network traffic and facilitate better incident response and auditing capabilities.", | ||
"Url": "https://docs.aws.amazon.com/network-firewall/latest/developerguide/firewall-update-logging-configuration.html" | ||
} | ||
}, | ||
"Categories": [ | ||
"logging" | ||
], | ||
"DependsOn": [], | ||
"RelatedTo": [], | ||
"Notes": "" | ||
} |
31 changes: 31 additions & 0 deletions
31
...rvices/networkfirewall/networkfirewall_logging_enabled/networkfirewall_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,31 @@ | ||
from prowler.lib.check.models import Check, Check_Report_AWS | ||
from prowler.providers.aws.services.networkfirewall.networkfirewall_client import ( | ||
networkfirewall_client, | ||
) | ||
|
||
|
||
class networkfirewall_logging_enabled(Check): | ||
def execute(self): | ||
findings = [] | ||
for arn, firewall in networkfirewall_client.network_firewalls.items(): | ||
report = Check_Report_AWS(self.metadata()) | ||
report.region = firewall.region | ||
report.resource_id = firewall.name | ||
report.resource_arn = arn | ||
report.resource_tags = firewall.tags | ||
report.status = "FAIL" | ||
report.status_extended = ( | ||
f"Network Firewall {firewall.name} does not have logging enabled." | ||
) | ||
|
||
for configuration in firewall.logging_configuration: | ||
if configuration.log_type or configuration.log_destination: | ||
report.status = "PASS" | ||
report.status_extended = ( | ||
f"Network Firewall {firewall.name} has logging enabled." | ||
) | ||
break | ||
|
||
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
147 changes: 147 additions & 0 deletions
147
...s/networkfirewall/networkfirewall_logging_enabled/networkfirewall_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,147 @@ | ||
from unittest import mock | ||
|
||
from prowler.providers.aws.services.networkfirewall.networkfirewall_service import ( | ||
Firewall, | ||
LogDestinationType, | ||
LoggingConfiguration, | ||
LogType, | ||
) | ||
from tests.providers.aws.utils import AWS_REGION_US_EAST_1, set_mocked_aws_provider | ||
|
||
FIREWALL_ARN = "arn:aws:network-firewall:us-east-1:123456789012:firewall/my-firewall" | ||
FIREWALL_NAME = "my-firewall" | ||
VPC_ID_PROTECTED = "vpc-12345678901234567" | ||
VPC_ID_UNPROTECTED = "vpc-12345678901234568" | ||
POLICY_ARN = "arn:aws:network-firewall:us-east-1:123456789012:firewall-policy/my-policy" | ||
|
||
|
||
class Test_networkfirewall_logging_enabled: | ||
def test_no_networkfirewall(self): | ||
networkfirewall_client = mock.MagicMock | ||
networkfirewall_client.provider = set_mocked_aws_provider( | ||
[AWS_REGION_US_EAST_1] | ||
) | ||
networkfirewall_client.region = AWS_REGION_US_EAST_1 | ||
networkfirewall_client.network_firewalls = {} | ||
|
||
aws_provider = set_mocked_aws_provider([AWS_REGION_US_EAST_1]) | ||
|
||
with mock.patch( | ||
"prowler.providers.common.provider.Provider.get_global_provider", | ||
return_value=aws_provider, | ||
): | ||
with mock.patch( | ||
"prowler.providers.aws.services.networkfirewall.networkfirewall_logging_enabled.networkfirewall_logging_enabled.networkfirewall_client", | ||
new=networkfirewall_client, | ||
): | ||
# Test Check | ||
from prowler.providers.aws.services.networkfirewall.networkfirewall_logging_enabled.networkfirewall_logging_enabled import ( | ||
networkfirewall_logging_enabled, | ||
) | ||
|
||
check = networkfirewall_logging_enabled() | ||
result = check.execute() | ||
|
||
assert len(result) == 0 | ||
|
||
def test_networkfirewall_logging_disabled(self): | ||
networkfirewall_client = mock.MagicMock | ||
networkfirewall_client.provider = set_mocked_aws_provider( | ||
[AWS_REGION_US_EAST_1] | ||
) | ||
networkfirewall_client.region = AWS_REGION_US_EAST_1 | ||
networkfirewall_client.network_firewalls = { | ||
FIREWALL_ARN: Firewall( | ||
arn=FIREWALL_ARN, | ||
name=FIREWALL_NAME, | ||
region=AWS_REGION_US_EAST_1, | ||
policy_arn=POLICY_ARN, | ||
vpc_id=VPC_ID_PROTECTED, | ||
tags=[], | ||
encryption_type="CUSTOMER_KMS", | ||
logging_configuration=[], | ||
) | ||
} | ||
|
||
aws_provider = set_mocked_aws_provider([AWS_REGION_US_EAST_1]) | ||
|
||
with mock.patch( | ||
"prowler.providers.common.provider.Provider.get_global_provider", | ||
return_value=aws_provider, | ||
): | ||
with mock.patch( | ||
"prowler.providers.aws.services.networkfirewall.networkfirewall_logging_enabled.networkfirewall_logging_enabled.networkfirewall_client", | ||
new=networkfirewall_client, | ||
): | ||
# Test Check | ||
from prowler.providers.aws.services.networkfirewall.networkfirewall_logging_enabled.networkfirewall_logging_enabled import ( | ||
networkfirewall_logging_enabled, | ||
) | ||
|
||
check = networkfirewall_logging_enabled() | ||
result = check.execute() | ||
|
||
assert len(result) == 1 | ||
assert result[0].status == "FAIL" | ||
assert ( | ||
result[0].status_extended | ||
== f"Network Firewall {FIREWALL_NAME} does not have logging enabled." | ||
) | ||
assert result[0].region == AWS_REGION_US_EAST_1 | ||
assert result[0].resource_id == FIREWALL_NAME | ||
assert result[0].resource_tags == [] | ||
assert result[0].resource_arn == FIREWALL_ARN | ||
|
||
def test_networkfirewall_logging_enabled(self): | ||
networkfirewall_client = mock.MagicMock | ||
networkfirewall_client.provider = set_mocked_aws_provider( | ||
[AWS_REGION_US_EAST_1] | ||
) | ||
networkfirewall_client.region = AWS_REGION_US_EAST_1 | ||
networkfirewall_client.network_firewalls = { | ||
FIREWALL_ARN: Firewall( | ||
arn=FIREWALL_ARN, | ||
name=FIREWALL_NAME, | ||
region=AWS_REGION_US_EAST_1, | ||
policy_arn=POLICY_ARN, | ||
vpc_id=VPC_ID_PROTECTED, | ||
tags=[], | ||
encryption_type="CUSTOMER_KMS", | ||
logging_configuration=[ | ||
LoggingConfiguration( | ||
log_type=LogType.flow, | ||
log_destination_type=LogDestinationType.s3, | ||
log_destination={"bucket_name": "my-bucket"}, | ||
) | ||
], | ||
), | ||
} | ||
|
||
aws_provider = set_mocked_aws_provider([AWS_REGION_US_EAST_1]) | ||
|
||
with mock.patch( | ||
"prowler.providers.common.provider.Provider.get_global_provider", | ||
return_value=aws_provider, | ||
): | ||
with mock.patch( | ||
"prowler.providers.aws.services.networkfirewall.networkfirewall_logging_enabled.networkfirewall_logging_enabled.networkfirewall_client", | ||
new=networkfirewall_client, | ||
): | ||
# Test Check | ||
from prowler.providers.aws.services.networkfirewall.networkfirewall_logging_enabled.networkfirewall_logging_enabled import ( | ||
networkfirewall_logging_enabled, | ||
) | ||
|
||
check = networkfirewall_logging_enabled() | ||
result = check.execute() | ||
|
||
assert len(result) == 1 | ||
assert result[0].status == "PASS" | ||
assert ( | ||
result[0].status_extended | ||
== f"Network Firewall {FIREWALL_NAME} has logging enabled." | ||
) | ||
assert result[0].region == AWS_REGION_US_EAST_1 | ||
assert result[0].resource_id == FIREWALL_NAME | ||
assert result[0].resource_tags == [] | ||
assert result[0].resource_arn == FIREWALL_ARN |
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