Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(vpc_endpoint_services_allowed_principals_trust_boundaries) #2768

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def set_mocked_audit_info(self):
profile_region=None,
credentials=None,
assumed_role_info=None,
audited_regions=["us-east-1", "eu-west-1"],
audited_regions=[AWS_REGION],
organizations_metadata=None,
audit_resources=None,
mfa_enabled=False,
Expand All @@ -70,6 +70,13 @@ def set_mocked_audit_info(self):

@mock_ec2
def test_vpc_no_endpoint_services(self):
# VPC Endpoint Services
ec2_client = client("ec2", region_name=AWS_REGION)
endpoint_id = ec2_client.describe_vpc_endpoint_services()["ServiceDetails"][0][
"ServiceId"
]
endpoint_arn = f"arn:aws:ec2:{AWS_REGION}:{AWS_ACCOUNT_NUMBER}:vpc-endpoint-service/{endpoint_id}"

from prowler.providers.aws.services.vpc.vpc_service import VPC

current_audit_info = self.set_mocked_audit_info()
Expand All @@ -92,7 +99,16 @@ def test_vpc_no_endpoint_services(self):
check = vpc_endpoint_services_allowed_principals_trust_boundaries()
result = check.execute()

assert len(result) == 2 # one endpoint per region
assert len(result) == 1 # one endpoint per region
assert result[0].status == "PASS"
assert (
result[0].status_extended
== f"VPC Endpoint Service {endpoint_id} has no allowed principals."
)
assert result[0].resource_id == endpoint_id
assert result[0].resource_arn == endpoint_arn
assert result[0].resource_tags is None
assert result[0].region == AWS_REGION

@mock_ec2
@mock_elbv2
Expand All @@ -110,17 +126,21 @@ def test_vpc_endpoint_service_without_allowed_principals(self):
AvailabilityZone=f"{AWS_REGION}a",
)
lb_name = "lb_vpce-test"
_ = elbv2_client.create_load_balancer(
lb_arn = elbv2_client.create_load_balancer(
Name=lb_name,
Subnets=[subnet["Subnet"]["SubnetId"]],
Scheme="internal",
Type="network",
)["LoadBalancers"][0]["LoadBalancerArn"]

# Service is mocked until moto fix the issue https://github.com/spulec/moto/issues/5605
# service = ec2_client.create_vpc_endpoint_service_configuration(
# NetworkLoadBalancerArns=[lb_arn]
# )
_ = ec2_client.create_vpc_endpoint_service_configuration(
NetworkLoadBalancerArns=[lb_arn]
)

endpoint_id = ec2_client.describe_vpc_endpoint_services()["ServiceDetails"][0][
"ServiceId"
]
endpoint_arn = f"arn:aws:ec2:{AWS_REGION}:{AWS_ACCOUNT_NUMBER}:vpc-endpoint-service/{endpoint_id}"

from prowler.providers.aws.services.vpc.vpc_service import VPC

Expand All @@ -144,15 +164,13 @@ def test_vpc_endpoint_service_without_allowed_principals(self):
check = vpc_endpoint_services_allowed_principals_trust_boundaries()
result = check.execute()

assert len(result) == 2 # one per region
assert len(result) == 1
assert result[0].status == "PASS"
assert (
result[0].status_extended
== f"VPC Endpoint Service {ec2_client.describe_vpc_endpoint_services()['ServiceDetails'][0]['ServiceId']} has no allowed principals."
)
assert (
result[0].resource_id
== ec2_client.describe_vpc_endpoint_services()["ServiceDetails"][0][
"ServiceId"
]
)
assert result[0].resource_id == endpoint_id
assert result[0].resource_arn == endpoint_arn
assert result[0].resource_tags is None
assert result[0].region == AWS_REGION