mirror of
https://github.com/prowler-cloud/prowler.git
synced 2026-07-23 12:31:54 +00:00
chore(ec2): improve severity logic in SG all ports open check (#7764)
This commit is contained in:
@@ -24,6 +24,7 @@ All notable changes to the **Prowler SDK** are documented in this file.
|
||||
### Fixed
|
||||
- Update CIS 4.0 for M365 provider. [(#7699)](https://github.com/prowler-cloud/prowler/pull/7699)
|
||||
- Cover policies with conditions with SNS endpoint in `sns_topics_not_publicly_accessible`. [(#7750)](https://github.com/prowler-cloud/prowler/pull/7750)
|
||||
- Change severity logic for `ec2_securitygroup_allow_ingress_from_internet_to_all_ports` check. [(#7764)](https://github.com/prowler-cloud/prowler/pull/7764)
|
||||
|
||||
---
|
||||
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@
|
||||
"ServiceName": "ec2",
|
||||
"SubServiceName": "securitygroup",
|
||||
"ResourceIdTemplate": "arn:partition:service:region:account-id:resource-id",
|
||||
"Severity": "high",
|
||||
"Severity": "critical",
|
||||
"ResourceType": "AwsEc2SecurityGroup",
|
||||
"Description": "Ensure no security groups allow ingress from 0.0.0.0/0 or ::/0 to all ports.",
|
||||
"Risk": "If Security groups are not properly configured the attack surface is increased. An attacker could exploit this misconfiguration to gain unauthorized access to resources.",
|
||||
|
||||
+6
-3
@@ -1,4 +1,4 @@
|
||||
from prowler.lib.check.models import Check, Check_Report_AWS
|
||||
from prowler.lib.check.models import Check, Check_Report_AWS, Severity
|
||||
from prowler.providers.aws.services.ec2.ec2_client import ec2_client
|
||||
from prowler.providers.aws.services.ec2.lib.security_groups import check_security_group
|
||||
from prowler.providers.aws.services.vpc.vpc_client import vpc_client
|
||||
@@ -9,14 +9,17 @@ class ec2_securitygroup_allow_ingress_from_internet_to_all_ports(Check):
|
||||
findings = []
|
||||
for security_group_arn, security_group in ec2_client.security_groups.items():
|
||||
# Check if ignoring flag is set and if the VPC and the SG is in use
|
||||
if ec2_client.provider.scan_unused_services or (
|
||||
sg_in_use = (
|
||||
security_group.vpc_id in vpc_client.vpcs
|
||||
and vpc_client.vpcs[security_group.vpc_id].in_use
|
||||
and len(security_group.network_interfaces) > 0
|
||||
):
|
||||
)
|
||||
if ec2_client.provider.scan_unused_services or sg_in_use:
|
||||
report = Check_Report_AWS(
|
||||
metadata=self.metadata(), resource=security_group
|
||||
)
|
||||
if not sg_in_use:
|
||||
report.check_metadata.Severity = Severity.high
|
||||
report.resource_details = security_group.name
|
||||
report.status = "PASS"
|
||||
report.status_extended = f"Security group {security_group.name} ({security_group.id}) does not have all ports open to the Internet."
|
||||
|
||||
+2
-1
@@ -269,6 +269,7 @@ class Test_ec2_securitygroup_allow_ingress_from_internet_to_all_ports:
|
||||
== f"arn:{aws_provider.identity.partition}:ec2:{AWS_REGION_US_EAST_1}:{aws_provider.identity.account}:security-group/{default_sg_id}"
|
||||
)
|
||||
assert sg.resource_details == default_sg_name
|
||||
assert sg.check_metadata.Severity == "high"
|
||||
assert sg.resource_tags == []
|
||||
|
||||
@mock_aws
|
||||
@@ -361,6 +362,7 @@ class Test_ec2_securitygroup_allow_ingress_from_internet_to_all_ports:
|
||||
assert len(result) == 1
|
||||
assert result[0].status == "PASS"
|
||||
assert result[0].region == AWS_REGION_US_EAST_1
|
||||
assert result[0].check_metadata.Severity == "critical"
|
||||
|
||||
@mock_aws
|
||||
def test_set_failed_check_called_correctly(self):
|
||||
@@ -409,7 +411,6 @@ class Test_ec2_securitygroup_allow_ingress_from_internet_to_all_ports:
|
||||
"prowler.providers.aws.lib.service.service.AWSService.set_failed_check"
|
||||
) as mock_set_failed_check,
|
||||
):
|
||||
|
||||
from prowler.providers.aws.services.ec2.ec2_securitygroup_allow_ingress_from_internet_to_all_ports.ec2_securitygroup_allow_ingress_from_internet_to_all_ports import (
|
||||
ec2_securitygroup_allow_ingress_from_internet_to_all_ports,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user