Skip to content

Commit

Permalink
make it run for all python versions
Browse files Browse the repository at this point in the history
  • Loading branch information
kagahd committed May 30, 2024
1 parent dd24239 commit 17aa828
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ def check_enis(
report.status_extended = f"Security group {security_group_name} ({security_group_id}) has at least one port open to the Internet but is exclusively not attached to any network interface."
for eni in enis:

if self.is_allowed_eni_type(eni=eni):
if self.is_allowed_eni_type(eni_type=eni.type):
report.status = "PASS"
report.status_extended = f"Security group {security_group_name} ({security_group_id}) has at least one port open to the Internet but is exclusively attached to an allowed network interface type ({eni.type})."
continue

eni_owner = self.get_eni_owner(eni=eni)
if self.is_allowed_eni_owner(eni=eni, eni_owner=eni_owner):
if self.is_allowed_eni_owner(eni_owner=eni_owner):
report.status = "PASS"
report.status_extended = f"Security group {security_group_name} ({security_group_id}) has at least one port open to the Internet but is exclusively attached to an allowed network interface instance owner ({eni_owner})."
continue
Expand All @@ -79,14 +79,14 @@ def check_enis(
break # no need to check other network interfaces because at least one failed already

@staticmethod
def is_allowed_eni_type(eni) -> bool:
return eni.type in ec2_client.audit_config.get(
def is_allowed_eni_type(eni_type: str) -> bool:
return eni_type in ec2_client.audit_config.get(
"ec2_allowed_interface_types", []
)

@staticmethod
def get_eni_owner(eni) -> str | None:
eni_owner = None
def get_eni_owner(eni) -> str:
eni_owner = ""
if (
hasattr(eni, "attachment")
and isinstance(eni.attachment, dict)
Expand All @@ -97,7 +97,7 @@ def get_eni_owner(eni) -> str | None:
return eni_owner

@staticmethod
def is_allowed_eni_owner(eni, eni_owner: str) -> bool:
def is_allowed_eni_owner(eni_owner: str) -> bool:
return eni_owner in ec2_client.audit_config.get(
"ec2_allowed_instance_owners", []
)
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ def verify_check_fail(
):
eni = network_interface_response.get("NetworkInterface", {})
att = eni.get("Attachment", {})
eni_type = eni.get("InterfaceType", None)
eni_owner = att.get("InstanceOwnerId", None)
eni_type = eni.get("InterfaceType", "")
eni_owner = att.get("InstanceOwnerId", "")
from prowler.providers.aws.services.ec2.ec2_service import EC2

aws_provider = set_mocked_aws_provider(
Expand Down Expand Up @@ -357,7 +357,7 @@ def test_ec2_open_sg_attached_to_allowed_eni_owner(self):

eni = network_interface_response.get("NetworkInterface", {})
att = eni.get("Attachment", {})
eni_owner = att.get("InstanceOwnerId", None)
eni_owner = att.get("InstanceOwnerId", "")

from prowler.providers.aws.services.ec2.ec2_service import EC2

Expand Down

0 comments on commit 17aa828

Please sign in to comment.