From 0f4d8ff891a046053913e6a8e59928d672788ead Mon Sep 17 00:00:00 2001 From: Daniel Barranquero <74871504+danibarranqueroo@users.noreply.github.com> Date: Tue, 14 Apr 2026 12:22:22 +0200 Subject: [PATCH] feat(aws): add bedrock_vpc_endpoints_configured security check (#10591) --- prowler/CHANGELOG.md | 1 + ...itected_framework_security_pillar_aws.json | 1 + prowler/compliance/aws/c5_aws.json | 1 + prowler/compliance/aws/ccc_aws.json | 1 + prowler/compliance/aws/iso27001_2022_aws.json | 3 + .../compliance/aws/kisa_isms_p_2023_aws.json | 1 + .../aws/kisa_isms_p_2023_korean_aws.json | 1 + prowler/compliance/aws/nis2_aws.json | 5 +- prowler/compliance/aws/nist_csf_2.0_aws.json | 1 + prowler/compliance/aws/pci_3.2.1_aws.json | 1 + prowler/compliance/aws/pci_4.0_aws.json | 6 + .../compliance/aws/secnumcloud_3.2_aws.json | 1 + .../__init__.py | 0 ...ock_vpc_endpoints_configured.metadata.json | 44 ++ .../bedrock_vpc_endpoints_configured.py | 88 +++ .../bedrock_vpc_endpoints_configured_test.py | 558 ++++++++++++++++++ 16 files changed, 711 insertions(+), 2 deletions(-) create mode 100644 prowler/providers/aws/services/bedrock/bedrock_vpc_endpoints_configured/__init__.py create mode 100644 prowler/providers/aws/services/bedrock/bedrock_vpc_endpoints_configured/bedrock_vpc_endpoints_configured.metadata.json create mode 100644 prowler/providers/aws/services/bedrock/bedrock_vpc_endpoints_configured/bedrock_vpc_endpoints_configured.py create mode 100644 tests/providers/aws/services/bedrock/bedrock_vpc_endpoints_configured/bedrock_vpc_endpoints_configured_test.py diff --git a/prowler/CHANGELOG.md b/prowler/CHANGELOG.md index e71b9562da..9a7bece29d 100644 --- a/prowler/CHANGELOG.md +++ b/prowler/CHANGELOG.md @@ -9,6 +9,7 @@ All notable changes to the **Prowler SDK** are documented in this file. - `bedrock_full_access_policy_attached` check for AWS provider [(#10577)](https://github.com/prowler-cloud/prowler/pull/10577) - `iam_role_access_not_stale_to_bedrock` and `iam_user_access_not_stale_to_bedrock` checks for AWS provider [(#10536)](https://github.com/prowler-cloud/prowler/pull/10536) - `iam_policy_no_wildcard_marketplace_subscribe` and `iam_inline_policy_no_wildcard_marketplace_subscribe` checks for AWS provider [(#10525)](https://github.com/prowler-cloud/prowler/pull/10525) +- `bedrock_vpc_endpoints_configured` check for AWS provider [(#10591)](https://github.com/prowler-cloud/prowler/pull/10591) --- diff --git a/prowler/compliance/aws/aws_well_architected_framework_security_pillar_aws.json b/prowler/compliance/aws/aws_well_architected_framework_security_pillar_aws.json index a147a5ea1f..7a04e4ddf7 100644 --- a/prowler/compliance/aws/aws_well_architected_framework_security_pillar_aws.json +++ b/prowler/compliance/aws/aws_well_architected_framework_security_pillar_aws.json @@ -674,6 +674,7 @@ "sagemaker_notebook_instance_vpc_settings_configured", "sagemaker_training_jobs_network_isolation_enabled", "sagemaker_training_jobs_vpc_settings_configured", + "bedrock_vpc_endpoints_configured", "vpc_endpoint_connections_trust_boundaries", "vpc_endpoint_services_allowed_principals_trust_boundaries" ] diff --git a/prowler/compliance/aws/c5_aws.json b/prowler/compliance/aws/c5_aws.json index 70580e5d22..ddb4c8fce7 100644 --- a/prowler/compliance/aws/c5_aws.json +++ b/prowler/compliance/aws/c5_aws.json @@ -7218,6 +7218,7 @@ ], "Checks": [ "workspaces_vpc_2private_1public_subnets_nat", + "bedrock_vpc_endpoints_configured", "vpc_endpoint_connections_trust_boundaries", "networkfirewall_multi_az" ] diff --git a/prowler/compliance/aws/ccc_aws.json b/prowler/compliance/aws/ccc_aws.json index 11aa32f4ee..a625de389c 100644 --- a/prowler/compliance/aws/ccc_aws.json +++ b/prowler/compliance/aws/ccc_aws.json @@ -4172,6 +4172,7 @@ } ], "Checks": [ + "bedrock_vpc_endpoints_configured", "vpc_endpoint_services_allowed_principals_trust_boundaries", "vpc_endpoint_connections_trust_boundaries" ] diff --git a/prowler/compliance/aws/iso27001_2022_aws.json b/prowler/compliance/aws/iso27001_2022_aws.json index 04f7f750d3..cb64f4bdd8 100644 --- a/prowler/compliance/aws/iso27001_2022_aws.json +++ b/prowler/compliance/aws/iso27001_2022_aws.json @@ -1461,6 +1461,7 @@ "Checks": [ "awslambda_function_inside_vpc", "awslambda_function_vpc_multi_az", + "bedrock_vpc_endpoints_configured", "cloudwatch_changes_to_vpcs_alarm_configured", "ec2_transitgateway_auto_accept_vpc_attachments", "networkfirewall_in_all_vpc", @@ -1555,6 +1556,7 @@ "Checks": [ "awslambda_function_inside_vpc", "awslambda_function_vpc_multi_az", + "bedrock_vpc_endpoints_configured", "cloudwatch_changes_to_vpcs_alarm_configured", "ec2_transitgateway_auto_accept_vpc_attachments", "networkfirewall_in_all_vpc", @@ -1649,6 +1651,7 @@ "Checks": [ "awslambda_function_inside_vpc", "awslambda_function_vpc_multi_az", + "bedrock_vpc_endpoints_configured", "cloudwatch_changes_to_vpcs_alarm_configured", "ec2_transitgateway_auto_accept_vpc_attachments", "networkfirewall_in_all_vpc", diff --git a/prowler/compliance/aws/kisa_isms_p_2023_aws.json b/prowler/compliance/aws/kisa_isms_p_2023_aws.json index 35b863ae46..cb37e8bf67 100644 --- a/prowler/compliance/aws/kisa_isms_p_2023_aws.json +++ b/prowler/compliance/aws/kisa_isms_p_2023_aws.json @@ -1617,6 +1617,7 @@ "sagemaker_notebook_instance_without_direct_internet_access_configured", "sagemaker_training_jobs_network_isolation_enabled", "sagemaker_training_jobs_vpc_settings_configured", + "bedrock_vpc_endpoints_configured", "vpc_endpoint_connections_trust_boundaries", "vpc_endpoint_for_ec2_enabled", "vpc_peering_routing_tables_with_least_privilege", diff --git a/prowler/compliance/aws/kisa_isms_p_2023_korean_aws.json b/prowler/compliance/aws/kisa_isms_p_2023_korean_aws.json index 3f99680675..d1dbcb64b2 100644 --- a/prowler/compliance/aws/kisa_isms_p_2023_korean_aws.json +++ b/prowler/compliance/aws/kisa_isms_p_2023_korean_aws.json @@ -1616,6 +1616,7 @@ "sagemaker_notebook_instance_without_direct_internet_access_configured", "sagemaker_training_jobs_network_isolation_enabled", "sagemaker_training_jobs_vpc_settings_configured", + "bedrock_vpc_endpoints_configured", "vpc_endpoint_connections_trust_boundaries", "vpc_endpoint_for_ec2_enabled", "vpc_peering_routing_tables_with_least_privilege", diff --git a/prowler/compliance/aws/nis2_aws.json b/prowler/compliance/aws/nis2_aws.json index 1ee18feba8..687068e26d 100644 --- a/prowler/compliance/aws/nis2_aws.json +++ b/prowler/compliance/aws/nis2_aws.json @@ -1368,9 +1368,10 @@ "Id": "6.8.2.a", "Description": "consider the functional, logical and physical relationship, including location, between trustworthy systems and services;", "Checks": [ + "bedrock_vpc_endpoints_configured", "iam_role_cross_service_confused_deputy_prevention", - "vpc_endpoint_services_allowed_principals_trust_boundaries", - "vpc_endpoint_connections_trust_boundaries" + "vpc_endpoint_connections_trust_boundaries", + "vpc_endpoint_services_allowed_principals_trust_boundaries" ], "Attributes": [ { diff --git a/prowler/compliance/aws/nist_csf_2.0_aws.json b/prowler/compliance/aws/nist_csf_2.0_aws.json index c6750f1cae..fb9b1da4f1 100644 --- a/prowler/compliance/aws/nist_csf_2.0_aws.json +++ b/prowler/compliance/aws/nist_csf_2.0_aws.json @@ -810,6 +810,7 @@ "Checks": [ "vpc_subnet_different_az", "vpc_subnet_separate_private_public", + "bedrock_vpc_endpoints_configured", "vpc_endpoint_connections_trust_boundaries", "vpc_peering_routing_tables_with_least_privilege", "ec2_networkacl_unused", diff --git a/prowler/compliance/aws/pci_3.2.1_aws.json b/prowler/compliance/aws/pci_3.2.1_aws.json index ccab1c0813..a313c70ae8 100644 --- a/prowler/compliance/aws/pci_3.2.1_aws.json +++ b/prowler/compliance/aws/pci_3.2.1_aws.json @@ -276,6 +276,7 @@ "ec2_ebs_public_snapshot", "rds_instance_no_public_access", "eks_endpoints_not_publicly_accessible", + "bedrock_vpc_endpoints_configured", "vpc_endpoint_for_ec2_enabled", "s3_account_level_public_access_blocks", "awslambda_function_not_publicly_accessible", diff --git a/prowler/compliance/aws/pci_4.0_aws.json b/prowler/compliance/aws/pci_4.0_aws.json index 8367bc4cb6..dc8fab9140 100644 --- a/prowler/compliance/aws/pci_4.0_aws.json +++ b/prowler/compliance/aws/pci_4.0_aws.json @@ -754,6 +754,7 @@ "Description": "Checks if Service Endpoint for the service provided in rule parameter is created for each Amazon Virtual Private Cloud (Amazon VPC)", "Name": "vpc", "Checks": [ + "bedrock_vpc_endpoints_configured", "vpc_endpoint_for_ec2_enabled" ], "Attributes": [ @@ -1454,6 +1455,7 @@ "Description": "Checks if Service Endpoint for the service provided in rule parameter is created for each Amazon Virtual Private Cloud (Amazon VPC)", "Name": "vpc", "Checks": [ + "bedrock_vpc_endpoints_configured", "vpc_endpoint_for_ec2_enabled" ], "Attributes": [ @@ -2168,6 +2170,7 @@ "Description": "Checks if Service Endpoint for the service provided in rule parameter is created for each Amazon Virtual Private Cloud (Amazon VPC)", "Name": "vpc", "Checks": [ + "bedrock_vpc_endpoints_configured", "vpc_endpoint_for_ec2_enabled" ], "Attributes": [ @@ -2988,6 +2991,7 @@ "Description": "Checks if Service Endpoint for the service provided in rule parameter is created for each Amazon Virtual Private Cloud (Amazon VPC)", "Name": "vpc", "Checks": [ + "bedrock_vpc_endpoints_configured", "vpc_endpoint_for_ec2_enabled" ], "Attributes": [ @@ -3850,6 +3854,7 @@ "Description": "Checks if Service Endpoint for the service provided in rule parameter is created for each Amazon Virtual Private Cloud (Amazon VPC)", "Name": "vpc", "Checks": [ + "bedrock_vpc_endpoints_configured", "vpc_endpoint_for_ec2_enabled" ], "Attributes": [ @@ -21686,6 +21691,7 @@ "Description": "Checks if Service Endpoint for the service provided in rule parameter is created for each Amazon Virtual Private Cloud (Amazon VPC)", "Name": "vpc", "Checks": [ + "bedrock_vpc_endpoints_configured", "vpc_endpoint_for_ec2_enabled" ], "Attributes": [ diff --git a/prowler/compliance/aws/secnumcloud_3.2_aws.json b/prowler/compliance/aws/secnumcloud_3.2_aws.json index a3f44b5339..4f01db2f3f 100644 --- a/prowler/compliance/aws/secnumcloud_3.2_aws.json +++ b/prowler/compliance/aws/secnumcloud_3.2_aws.json @@ -1032,6 +1032,7 @@ "ec2_networkacl_allow_ingress_any_port", "vpc_subnet_separate_private_public", "vpc_peering_routing_tables_with_least_privilege", + "bedrock_vpc_endpoints_configured", "vpc_endpoint_connections_trust_boundaries", "vpc_endpoint_services_allowed_principals_trust_boundaries", "elbv2_waf_acl_attached", diff --git a/prowler/providers/aws/services/bedrock/bedrock_vpc_endpoints_configured/__init__.py b/prowler/providers/aws/services/bedrock/bedrock_vpc_endpoints_configured/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/prowler/providers/aws/services/bedrock/bedrock_vpc_endpoints_configured/bedrock_vpc_endpoints_configured.metadata.json b/prowler/providers/aws/services/bedrock/bedrock_vpc_endpoints_configured/bedrock_vpc_endpoints_configured.metadata.json new file mode 100644 index 0000000000..0e2ac8fef5 --- /dev/null +++ b/prowler/providers/aws/services/bedrock/bedrock_vpc_endpoints_configured/bedrock_vpc_endpoints_configured.metadata.json @@ -0,0 +1,44 @@ +{ + "Provider": "aws", + "CheckID": "bedrock_vpc_endpoints_configured", + "CheckTitle": "VPC endpoints ensure private connectivity for all Bedrock APIs", + "CheckType": [ + "Software and Configuration Checks/AWS Security Best Practices/Network Reachability" + ], + "ServiceName": "bedrock", + "SubServiceName": "", + "ResourceIdTemplate": "", + "Severity": "medium", + "ResourceType": "AwsEc2VpcEndpointService", + "ResourceGroup": "network", + "Description": "**Amazon VPCs** are evaluated for **interface VPC endpoints** to all Bedrock services: `bedrock`, `bedrock-runtime`, `bedrock-agent`, `bedrock-agent-runtime`, and `bedrock-mantle` (OpenAI-compatible API). Only endpoints in `available` state are considered. Their presence indicates private Bedrock API connectivity over **AWS PrivateLink** within the VPC.", + "Risk": "Without private Bedrock endpoints, control plane and runtime API traffic exits the VPC via IGW or NAT Gateway. This expands exposure to network path threats (e.g., DNS hijack, MITM), weakens egress isolation, and adds an internet dependency for Bedrock API access, reducing availability if NAT or edge paths fail.", + "RelatedUrl": "", + "AdditionalURLs": [ + "https://docs.aws.amazon.com/bedrock/latest/userguide/usingVPC.html", + "https://docs.aws.amazon.com/bedrock/latest/userguide/vpc-interface-endpoints.html", + "https://docs.aws.amazon.com/vpc/latest/privatelink/create-interface-endpoint.html" + ], + "Remediation": { + "Code": { + "CLI": "aws ec2 create-vpc-endpoint --vpc-id --service-name com.amazonaws..bedrock-runtime --vpc-endpoint-type Interface --subnet-ids && aws ec2 create-vpc-endpoint --vpc-id --service-name com.amazonaws..bedrock --vpc-endpoint-type Interface --subnet-ids && aws ec2 create-vpc-endpoint --vpc-id --service-name com.amazonaws..bedrock-agent --vpc-endpoint-type Interface --subnet-ids && aws ec2 create-vpc-endpoint --vpc-id --service-name com.amazonaws..bedrock-agent-runtime --vpc-endpoint-type Interface --subnet-ids && aws ec2 create-vpc-endpoint --vpc-id --service-name com.amazonaws..bedrock-mantle --vpc-endpoint-type Interface --subnet-ids ", + "NativeIaC": "```yaml\n# CloudFormation: create Bedrock interface VPC endpoints in the VPC\nResources:\n BedrockEndpoint:\n Type: AWS::EC2::VPCEndpoint\n Properties:\n VpcId: \"\" # CRITICAL: target VPC\n ServiceName: !Sub \"com.amazonaws.${AWS::Region}.bedrock\" # CRITICAL: Bedrock control plane endpoint\n VpcEndpointType: Interface # CRITICAL: interface endpoint\n SubnetIds:\n - \"\"\n BedrockRuntimeEndpoint:\n Type: AWS::EC2::VPCEndpoint\n Properties:\n VpcId: \"\" # CRITICAL: target VPC\n ServiceName: !Sub \"com.amazonaws.${AWS::Region}.bedrock-runtime\" # CRITICAL: Bedrock runtime endpoint\n VpcEndpointType: Interface # CRITICAL: interface endpoint\n SubnetIds:\n - \"\"\n BedrockAgentEndpoint:\n Type: AWS::EC2::VPCEndpoint\n Properties:\n VpcId: \"\" # CRITICAL: target VPC\n ServiceName: !Sub \"com.amazonaws.${AWS::Region}.bedrock-agent\" # CRITICAL: Bedrock agent control plane endpoint\n VpcEndpointType: Interface # CRITICAL: interface endpoint\n SubnetIds:\n - \"\"\n BedrockAgentRuntimeEndpoint:\n Type: AWS::EC2::VPCEndpoint\n Properties:\n VpcId: \"\" # CRITICAL: target VPC\n ServiceName: !Sub \"com.amazonaws.${AWS::Region}.bedrock-agent-runtime\" # CRITICAL: Bedrock agent runtime endpoint\n VpcEndpointType: Interface # CRITICAL: interface endpoint\n SubnetIds:\n - \"\"\n BedrockMantleEndpoint:\n Type: AWS::EC2::VPCEndpoint\n Properties:\n VpcId: \"\" # CRITICAL: target VPC\n ServiceName: !Sub \"com.amazonaws.${AWS::Region}.bedrock-mantle\" # CRITICAL: Bedrock Mantle OpenAI-compatible endpoint\n VpcEndpointType: Interface # CRITICAL: interface endpoint\n SubnetIds:\n - \"\"\n```", + "Other": "1. In the AWS console, go to VPC > Endpoints\n2. Click Create endpoint\n3. For Service category, choose AWS services and select com.amazonaws..bedrock\n4. Select your VPC and at least one subnet\n5. Click Create endpoint\n6. Repeat steps 2-5 for com.amazonaws..bedrock-runtime, com.amazonaws..bedrock-agent, com.amazonaws..bedrock-agent-runtime, and com.amazonaws..bedrock-mantle", + "Terraform": "```hcl\n# Create Bedrock control plane interface VPC endpoint\nresource \"aws_vpc_endpoint\" \"bedrock\" {\n vpc_id = \"\" # CRITICAL: target VPC\n service_name = \"com.amazonaws..bedrock\" # CRITICAL: Bedrock control plane endpoint\n vpc_endpoint_type = \"Interface\" # CRITICAL: interface endpoint\n subnet_ids = [\"\"] # CRITICAL: subnet(s) for endpoint ENIs\n}\n\n# Create Bedrock runtime interface VPC endpoint\nresource \"aws_vpc_endpoint\" \"bedrock_runtime\" {\n vpc_id = \"\" # CRITICAL: target VPC\n service_name = \"com.amazonaws..bedrock-runtime\" # CRITICAL: Bedrock runtime endpoint\n vpc_endpoint_type = \"Interface\" # CRITICAL: interface endpoint\n subnet_ids = [\"\"] # CRITICAL: subnet(s) for endpoint ENIs\n}\n\n# Create Bedrock agent control plane interface VPC endpoint\nresource \"aws_vpc_endpoint\" \"bedrock_agent\" {\n vpc_id = \"\" # CRITICAL: target VPC\n service_name = \"com.amazonaws..bedrock-agent\" # CRITICAL: Bedrock agent control plane endpoint\n vpc_endpoint_type = \"Interface\" # CRITICAL: interface endpoint\n subnet_ids = [\"\"] # CRITICAL: subnet(s) for endpoint ENIs\n}\n\n# Create Bedrock agent runtime interface VPC endpoint\nresource \"aws_vpc_endpoint\" \"bedrock_agent_runtime\" {\n vpc_id = \"\" # CRITICAL: target VPC\n service_name = \"com.amazonaws..bedrock-agent-runtime\" # CRITICAL: Bedrock agent runtime endpoint\n vpc_endpoint_type = \"Interface\" # CRITICAL: interface endpoint\n subnet_ids = [\"\"] # CRITICAL: subnet(s) for endpoint ENIs\n}\n\n# Create Bedrock Mantle (OpenAI-compatible) interface VPC endpoint\nresource \"aws_vpc_endpoint\" \"bedrock_mantle\" {\n vpc_id = \"\" # CRITICAL: target VPC\n service_name = \"com.amazonaws..bedrock-mantle\" # CRITICAL: Bedrock Mantle OpenAI-compatible endpoint\n vpc_endpoint_type = \"Interface\" # CRITICAL: interface endpoint\n subnet_ids = [\"\"] # CRITICAL: subnet(s) for endpoint ENIs\n}\n```" + }, + "Recommendation": { + "Text": "Use **interface VPC endpoints** for all Bedrock services (`bedrock`, `bedrock-runtime`, `bedrock-agent`, `bedrock-agent-runtime`, `bedrock-mantle`) in each VPC that requires Bedrock API access.\n- Enable **private DNS** to keep calls on the AWS network\n- Apply restrictive endpoint policies (**least privilege**)\n- Reduce reliance on public egress and layer controls for **defense in depth**", + "Url": "https://hub.prowler.com/check/bedrock_vpc_endpoints_configured" + } + }, + "Categories": [ + "internet-exposed", + "trust-boundaries", + "gen-ai" + ], + "DependsOn": [], + "RelatedTo": [ + "vpc_endpoint_for_ec2_enabled" + ], + "Notes": "This check only evaluates VPCs in regions where Bedrock activity is detected (guardrails, agents, or model invocation logging enabled). Only VPC endpoints in 'available' state are considered." +} diff --git a/prowler/providers/aws/services/bedrock/bedrock_vpc_endpoints_configured/bedrock_vpc_endpoints_configured.py b/prowler/providers/aws/services/bedrock/bedrock_vpc_endpoints_configured/bedrock_vpc_endpoints_configured.py new file mode 100644 index 0000000000..92e2de3464 --- /dev/null +++ b/prowler/providers/aws/services/bedrock/bedrock_vpc_endpoints_configured/bedrock_vpc_endpoints_configured.py @@ -0,0 +1,88 @@ +from prowler.lib.check.models import Check, Check_Report_AWS +from prowler.providers.aws.services.bedrock.bedrock_agent_client import ( + bedrock_agent_client, +) +from prowler.providers.aws.services.bedrock.bedrock_client import bedrock_client +from prowler.providers.aws.services.vpc.vpc_client import vpc_client + +BEDROCK_ENDPOINT_SERVICES = { + "bedrock": "Bedrock control plane", + "bedrock-runtime": "Bedrock runtime", + "bedrock-agent": "Bedrock agent control plane", + "bedrock-agent-runtime": "Bedrock agent runtime", + "bedrock-mantle": "Bedrock Mantle (OpenAI-compatible API)", +} + + +class bedrock_vpc_endpoints_configured(Check): + """Ensure VPC endpoints are configured for Bedrock services. + + This check verifies that each VPC in regions with Bedrock activity has + interface VPC endpoints for all Amazon Bedrock services (control plane, + runtime, agent, agent runtime, and Mantle OpenAI-compatible API), + ensuring that traffic to these services remains within the AWS network. + - PASS: The VPC has VPC endpoints for all Bedrock services. + - FAIL: The VPC is missing one or more Bedrock VPC endpoints. + VPCs in regions without Bedrock activity are skipped. + """ + + def execute(self) -> list[Check_Report_AWS]: + """Execute the check logic. + + Returns: + A list of reports containing the result of the check. + """ + findings = [] + bedrock_regions = self._get_bedrock_active_regions() + + for vpc_id, vpc in vpc_client.vpcs.items(): + if not (vpc_client.provider.scan_unused_services or vpc.in_use): + continue + + if vpc.region not in bedrock_regions: + continue + + report = Check_Report_AWS(metadata=self.metadata(), resource=vpc) + report.status = "FAIL" + + found_services = set() + + for endpoint in vpc_client.vpc_endpoints: + if endpoint.vpc_id == vpc_id and endpoint.state == "available": + for svc_suffix in BEDROCK_ENDPOINT_SERVICES: + if endpoint.service_name.endswith(f".{svc_suffix}"): + found_services.add(svc_suffix) + + missing_services = set(BEDROCK_ENDPOINT_SERVICES) - found_services + + if not missing_services: + report.status = "PASS" + report.status_extended = ( + f"VPC {vpc.id} has VPC endpoints for all Bedrock services." + ) + else: + missing_labels = [ + BEDROCK_ENDPOINT_SERVICES[svc] for svc in sorted(missing_services) + ] + report.status_extended = f"VPC {vpc.id} does not have VPC endpoints for the following Bedrock services: {', '.join(missing_labels)}." + + findings.append(report) + + return findings + + @staticmethod + def _get_bedrock_active_regions() -> set[str]: + """Return regions where Bedrock resources or logging are configured.""" + active_regions = set() + + for region, config in bedrock_client.logging_configurations.items(): + if config.enabled: + active_regions.add(region) + + for guardrail in bedrock_client.guardrails.values(): + active_regions.add(guardrail.region) + + for agent in bedrock_agent_client.agents.values(): + active_regions.add(agent.region) + + return active_regions diff --git a/tests/providers/aws/services/bedrock/bedrock_vpc_endpoints_configured/bedrock_vpc_endpoints_configured_test.py b/tests/providers/aws/services/bedrock/bedrock_vpc_endpoints_configured/bedrock_vpc_endpoints_configured_test.py new file mode 100644 index 0000000000..a4850d8a39 --- /dev/null +++ b/tests/providers/aws/services/bedrock/bedrock_vpc_endpoints_configured/bedrock_vpc_endpoints_configured_test.py @@ -0,0 +1,558 @@ +from unittest import mock + +from boto3 import client +from moto import mock_aws + +from prowler.providers.aws.services.bedrock.bedrock_service import ( + Guardrail, + LoggingConfiguration, +) +from tests.providers.aws.utils import AWS_REGION_US_EAST_1, set_mocked_aws_provider + +BEDROCK_SERVICES = [ + "com.amazonaws.us-east-1.bedrock", + "com.amazonaws.us-east-1.bedrock-runtime", + "com.amazonaws.us-east-1.bedrock-agent", + "com.amazonaws.us-east-1.bedrock-agent-runtime", + "com.amazonaws.us-east-1.bedrock-mantle", +] + +MOCK_BEDROCK_CLIENT = mock.MagicMock( + logging_configurations={AWS_REGION_US_EAST_1: LoggingConfiguration(enabled=True)}, + guardrails={}, +) + +MOCK_BEDROCK_AGENT_CLIENT = mock.MagicMock(agents={}) + +MOCK_BEDROCK_CLIENT_NO_ACTIVITY = mock.MagicMock( + logging_configurations={AWS_REGION_US_EAST_1: LoggingConfiguration(enabled=False)}, + guardrails={}, +) + +MOCK_BEDROCK_AGENT_CLIENT_NO_ACTIVITY = mock.MagicMock(agents={}) + +CHECK_MODULE = "prowler.providers.aws.services.bedrock.bedrock_vpc_endpoints_configured.bedrock_vpc_endpoints_configured" + + +class Test_bedrock_vpc_endpoints_configured: + @mock_aws + def test_no_resources(self): + """Test with no in-use VPCs and scan_unused_services disabled - should return no results.""" + client("ec2", region_name=AWS_REGION_US_EAST_1) + + from prowler.providers.aws.services.vpc.vpc_service import VPC + + aws_provider = set_mocked_aws_provider( + [AWS_REGION_US_EAST_1], scan_unused_services=False + ) + + with mock.patch( + "prowler.providers.common.provider.Provider.get_global_provider", + return_value=aws_provider, + ): + with ( + mock.patch( + f"{CHECK_MODULE}.vpc_client", + new=VPC(aws_provider), + ), + mock.patch( + f"{CHECK_MODULE}.bedrock_client", + new=MOCK_BEDROCK_CLIENT, + ), + mock.patch( + f"{CHECK_MODULE}.bedrock_agent_client", + new=MOCK_BEDROCK_AGENT_CLIENT, + ), + ): + from prowler.providers.aws.services.bedrock.bedrock_vpc_endpoints_configured.bedrock_vpc_endpoints_configured import ( + bedrock_vpc_endpoints_configured, + ) + + check = bedrock_vpc_endpoints_configured() + result = check.execute() + + assert len(result) == 0 + + @mock_aws + def test_no_bedrock_activity(self): + """Test VPCs in region with no Bedrock activity - should return no results.""" + ec2_client = client("ec2", region_name=AWS_REGION_US_EAST_1) + ec2_client.describe_vpcs() + + from prowler.providers.aws.services.vpc.vpc_service import VPC + + 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( + f"{CHECK_MODULE}.vpc_client", + new=VPC(aws_provider), + ), + mock.patch( + f"{CHECK_MODULE}.bedrock_client", + new=MOCK_BEDROCK_CLIENT_NO_ACTIVITY, + ), + mock.patch( + f"{CHECK_MODULE}.bedrock_agent_client", + new=MOCK_BEDROCK_AGENT_CLIENT_NO_ACTIVITY, + ), + ): + from prowler.providers.aws.services.bedrock.bedrock_vpc_endpoints_configured.bedrock_vpc_endpoints_configured import ( + bedrock_vpc_endpoints_configured, + ) + + check = bedrock_vpc_endpoints_configured() + result = check.execute() + + assert len(result) == 0 + + @mock_aws + def test_vpc_no_endpoints(self): + """Test VPC with no VPC endpoints at all - should FAIL with all services missing.""" + ec2_client = client("ec2", region_name=AWS_REGION_US_EAST_1) + vpc_id = ec2_client.describe_vpcs()["Vpcs"][0]["VpcId"] + + from prowler.providers.aws.services.vpc.vpc_service import VPC + + 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( + f"{CHECK_MODULE}.vpc_client", + new=VPC(aws_provider), + ), + mock.patch( + f"{CHECK_MODULE}.bedrock_client", + new=MOCK_BEDROCK_CLIENT, + ), + mock.patch( + f"{CHECK_MODULE}.bedrock_agent_client", + new=MOCK_BEDROCK_AGENT_CLIENT, + ), + ): + from prowler.providers.aws.services.bedrock.bedrock_vpc_endpoints_configured.bedrock_vpc_endpoints_configured import ( + bedrock_vpc_endpoints_configured, + ) + + check = bedrock_vpc_endpoints_configured() + result = check.execute() + + assert len(result) == 1 + assert result[0].resource_id == vpc_id + assert result[0].region == AWS_REGION_US_EAST_1 + assert result[0].status == "FAIL" + assert "Bedrock control plane" in result[0].status_extended + assert "Bedrock runtime" in result[0].status_extended + assert "Bedrock agent control plane" in result[0].status_extended + assert "Bedrock agent runtime" in result[0].status_extended + assert "Bedrock Mantle" in result[0].status_extended + + @mock_aws + def test_vpc_only_bedrock_runtime_endpoint(self): + """Test VPC with only Bedrock runtime endpoint - should FAIL with three services missing.""" + ec2_client = client("ec2", region_name=AWS_REGION_US_EAST_1) + + vpc = ec2_client.create_vpc(CidrBlock="10.0.0.0/16")["Vpc"] + + route_table = ec2_client.create_route_table(VpcId=vpc["VpcId"])["RouteTable"] + ec2_client.create_vpc_endpoint( + VpcId=vpc["VpcId"], + ServiceName="com.amazonaws.us-east-1.bedrock-runtime", + RouteTableIds=[route_table["RouteTableId"]], + VpcEndpointType="Interface", + ) + + from prowler.providers.aws.services.vpc.vpc_service import VPC + + 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( + f"{CHECK_MODULE}.vpc_client", + new=VPC(aws_provider), + ), + mock.patch( + f"{CHECK_MODULE}.bedrock_client", + new=MOCK_BEDROCK_CLIENT, + ), + mock.patch( + f"{CHECK_MODULE}.bedrock_agent_client", + new=MOCK_BEDROCK_AGENT_CLIENT, + ), + ): + from prowler.providers.aws.services.bedrock.bedrock_vpc_endpoints_configured.bedrock_vpc_endpoints_configured import ( + bedrock_vpc_endpoints_configured, + ) + + check = bedrock_vpc_endpoints_configured() + result = check.execute() + + # Default VPC + created VPC + assert len(result) == 2 + finding = next(f for f in result if f.resource_id == vpc["VpcId"]) + assert finding.region == AWS_REGION_US_EAST_1 + assert finding.status == "FAIL" + assert "Bedrock runtime" not in finding.status_extended + assert "Bedrock control plane" in finding.status_extended + assert "Bedrock agent control plane" in finding.status_extended + assert "Bedrock agent runtime" in finding.status_extended + assert "Bedrock Mantle" in finding.status_extended + assert ( + finding.resource_arn + == f"arn:aws:ec2:{AWS_REGION_US_EAST_1}:123456789012:vpc/{vpc['VpcId']}" + ) + + @mock_aws + def test_vpc_only_bedrock_agent_runtime_endpoint(self): + """Test VPC with only Bedrock agent runtime endpoint - should FAIL with three services missing.""" + ec2_client = client("ec2", region_name=AWS_REGION_US_EAST_1) + + vpc = ec2_client.create_vpc(CidrBlock="10.0.0.0/16")["Vpc"] + + route_table = ec2_client.create_route_table(VpcId=vpc["VpcId"])["RouteTable"] + ec2_client.create_vpc_endpoint( + VpcId=vpc["VpcId"], + ServiceName="com.amazonaws.us-east-1.bedrock-agent-runtime", + RouteTableIds=[route_table["RouteTableId"]], + VpcEndpointType="Interface", + ) + + from prowler.providers.aws.services.vpc.vpc_service import VPC + + 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( + f"{CHECK_MODULE}.vpc_client", + new=VPC(aws_provider), + ), + mock.patch( + f"{CHECK_MODULE}.bedrock_client", + new=MOCK_BEDROCK_CLIENT, + ), + mock.patch( + f"{CHECK_MODULE}.bedrock_agent_client", + new=MOCK_BEDROCK_AGENT_CLIENT, + ), + ): + from prowler.providers.aws.services.bedrock.bedrock_vpc_endpoints_configured.bedrock_vpc_endpoints_configured import ( + bedrock_vpc_endpoints_configured, + ) + + check = bedrock_vpc_endpoints_configured() + result = check.execute() + + assert len(result) == 2 + finding = next(f for f in result if f.resource_id == vpc["VpcId"]) + assert finding.region == AWS_REGION_US_EAST_1 + assert finding.status == "FAIL" + assert "Bedrock agent runtime" not in finding.status_extended + assert "Bedrock control plane" in finding.status_extended + assert "Bedrock runtime" in finding.status_extended + assert "Bedrock agent control plane" in finding.status_extended + assert "Bedrock Mantle" in finding.status_extended + assert ( + finding.resource_arn + == f"arn:aws:ec2:{AWS_REGION_US_EAST_1}:123456789012:vpc/{vpc['VpcId']}" + ) + + @mock_aws + def test_vpc_all_bedrock_endpoints(self): + """Test VPC with all four Bedrock endpoints - should PASS.""" + ec2_client = client("ec2", region_name=AWS_REGION_US_EAST_1) + + vpc = ec2_client.create_vpc(CidrBlock="10.0.0.0/16")["Vpc"] + vpc_default_id = ec2_client.describe_vpcs()["Vpcs"][0]["VpcId"] + + route_table = ec2_client.create_route_table(VpcId=vpc["VpcId"])["RouteTable"] + for svc in BEDROCK_SERVICES: + ec2_client.create_vpc_endpoint( + VpcId=vpc["VpcId"], + ServiceName=svc, + RouteTableIds=[route_table["RouteTableId"]], + VpcEndpointType="Interface", + ) + + from prowler.providers.aws.services.vpc.vpc_service import VPC + + 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( + f"{CHECK_MODULE}.vpc_client", + new=VPC(aws_provider), + ), + mock.patch( + f"{CHECK_MODULE}.bedrock_client", + new=MOCK_BEDROCK_CLIENT, + ), + mock.patch( + f"{CHECK_MODULE}.bedrock_agent_client", + new=MOCK_BEDROCK_AGENT_CLIENT, + ), + ): + from prowler.providers.aws.services.bedrock.bedrock_vpc_endpoints_configured.bedrock_vpc_endpoints_configured import ( + bedrock_vpc_endpoints_configured, + ) + + check = bedrock_vpc_endpoints_configured() + result = check.execute() + + assert len(result) == 2 + finding = next(f for f in result if f.resource_id == vpc["VpcId"]) + assert finding.region == AWS_REGION_US_EAST_1 + assert finding.status == "PASS" + assert ( + finding.status_extended + == f"VPC {vpc['VpcId']} has VPC endpoints for all Bedrock services." + ) + assert ( + finding.resource_arn + == f"arn:aws:ec2:{AWS_REGION_US_EAST_1}:123456789012:vpc/{vpc['VpcId']}" + ) + + # Default VPC should FAIL + default_finding = next( + f for f in result if f.resource_id == vpc_default_id + ) + assert default_finding.status == "FAIL" + + @mock_aws + def test_vpc_only_runtime_endpoints(self): + """Test VPC with only both runtime endpoints but missing control plane endpoints - should FAIL.""" + ec2_client = client("ec2", region_name=AWS_REGION_US_EAST_1) + + vpc = ec2_client.create_vpc(CidrBlock="10.0.0.0/16")["Vpc"] + + route_table = ec2_client.create_route_table(VpcId=vpc["VpcId"])["RouteTable"] + ec2_client.create_vpc_endpoint( + VpcId=vpc["VpcId"], + ServiceName="com.amazonaws.us-east-1.bedrock-runtime", + RouteTableIds=[route_table["RouteTableId"]], + VpcEndpointType="Interface", + ) + ec2_client.create_vpc_endpoint( + VpcId=vpc["VpcId"], + ServiceName="com.amazonaws.us-east-1.bedrock-agent-runtime", + RouteTableIds=[route_table["RouteTableId"]], + VpcEndpointType="Interface", + ) + + from prowler.providers.aws.services.vpc.vpc_service import VPC + + 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( + f"{CHECK_MODULE}.vpc_client", + new=VPC(aws_provider), + ), + mock.patch( + f"{CHECK_MODULE}.bedrock_client", + new=MOCK_BEDROCK_CLIENT, + ), + mock.patch( + f"{CHECK_MODULE}.bedrock_agent_client", + new=MOCK_BEDROCK_AGENT_CLIENT, + ), + ): + from prowler.providers.aws.services.bedrock.bedrock_vpc_endpoints_configured.bedrock_vpc_endpoints_configured import ( + bedrock_vpc_endpoints_configured, + ) + + check = bedrock_vpc_endpoints_configured() + result = check.execute() + + assert len(result) == 2 + finding = next(f for f in result if f.resource_id == vpc["VpcId"]) + assert finding.status == "FAIL" + assert "Bedrock control plane" in finding.status_extended + assert "Bedrock agent control plane" in finding.status_extended + assert "Bedrock Mantle" in finding.status_extended + assert "Bedrock runtime" not in finding.status_extended + assert "Bedrock agent runtime" not in finding.status_extended + + @mock_aws + def test_vpc_unrelated_endpoint_only(self): + """Test VPC with only an unrelated endpoint (S3) - should FAIL with all services missing.""" + ec2_client = client("ec2", region_name=AWS_REGION_US_EAST_1) + + vpc = ec2_client.create_vpc(CidrBlock="10.0.0.0/16")["Vpc"] + + route_table = ec2_client.create_route_table(VpcId=vpc["VpcId"])["RouteTable"] + ec2_client.create_vpc_endpoint( + VpcId=vpc["VpcId"], + ServiceName="com.amazonaws.us-east-1.s3", + RouteTableIds=[route_table["RouteTableId"]], + VpcEndpointType="Gateway", + ) + + from prowler.providers.aws.services.vpc.vpc_service import VPC + + 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( + f"{CHECK_MODULE}.vpc_client", + new=VPC(aws_provider), + ), + mock.patch( + f"{CHECK_MODULE}.bedrock_client", + new=MOCK_BEDROCK_CLIENT, + ), + mock.patch( + f"{CHECK_MODULE}.bedrock_agent_client", + new=MOCK_BEDROCK_AGENT_CLIENT, + ), + ): + from prowler.providers.aws.services.bedrock.bedrock_vpc_endpoints_configured.bedrock_vpc_endpoints_configured import ( + bedrock_vpc_endpoints_configured, + ) + + check = bedrock_vpc_endpoints_configured() + result = check.execute() + + assert len(result) == 2 + finding = next(f for f in result if f.resource_id == vpc["VpcId"]) + assert finding.region == AWS_REGION_US_EAST_1 + assert finding.status == "FAIL" + assert "Bedrock control plane" in finding.status_extended + assert "Bedrock runtime" in finding.status_extended + assert "Bedrock agent control plane" in finding.status_extended + assert "Bedrock agent runtime" in finding.status_extended + assert "Bedrock Mantle" in finding.status_extended + + @mock_aws + def test_vpc_only_bedrock_mantle_endpoint(self): + """Test VPC with only Bedrock Mantle endpoint - should FAIL with four services missing.""" + ec2_client = client("ec2", region_name=AWS_REGION_US_EAST_1) + + vpc = ec2_client.create_vpc(CidrBlock="10.0.0.0/16")["Vpc"] + + route_table = ec2_client.create_route_table(VpcId=vpc["VpcId"])["RouteTable"] + ec2_client.create_vpc_endpoint( + VpcId=vpc["VpcId"], + ServiceName="com.amazonaws.us-east-1.bedrock-mantle", + RouteTableIds=[route_table["RouteTableId"]], + VpcEndpointType="Interface", + ) + + from prowler.providers.aws.services.vpc.vpc_service import VPC + + 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( + f"{CHECK_MODULE}.vpc_client", + new=VPC(aws_provider), + ), + mock.patch( + f"{CHECK_MODULE}.bedrock_client", + new=MOCK_BEDROCK_CLIENT, + ), + mock.patch( + f"{CHECK_MODULE}.bedrock_agent_client", + new=MOCK_BEDROCK_AGENT_CLIENT, + ), + ): + from prowler.providers.aws.services.bedrock.bedrock_vpc_endpoints_configured.bedrock_vpc_endpoints_configured import ( + bedrock_vpc_endpoints_configured, + ) + + check = bedrock_vpc_endpoints_configured() + result = check.execute() + + assert len(result) == 2 + finding = next(f for f in result if f.resource_id == vpc["VpcId"]) + assert finding.status == "FAIL" + assert "Bedrock Mantle" not in finding.status_extended + assert "Bedrock control plane" in finding.status_extended + assert "Bedrock runtime" in finding.status_extended + assert "Bedrock agent control plane" in finding.status_extended + assert "Bedrock agent runtime" in finding.status_extended + + @mock_aws + def test_bedrock_activity_via_guardrail(self): + """Test that Bedrock activity is detected via guardrails.""" + ec2_client = client("ec2", region_name=AWS_REGION_US_EAST_1) + vpc_id = ec2_client.describe_vpcs()["Vpcs"][0]["VpcId"] + + from prowler.providers.aws.services.vpc.vpc_service import VPC + + aws_provider = set_mocked_aws_provider([AWS_REGION_US_EAST_1]) + + bedrock_with_guardrail = mock.MagicMock( + logging_configurations={ + AWS_REGION_US_EAST_1: LoggingConfiguration(enabled=False) + }, + guardrails={ + "arn:aws:bedrock:us-east-1:123456789012:guardrail/test": Guardrail( + id="test", + name="test-guardrail", + arn="arn:aws:bedrock:us-east-1:123456789012:guardrail/test", + region=AWS_REGION_US_EAST_1, + ) + }, + ) + + with mock.patch( + "prowler.providers.common.provider.Provider.get_global_provider", + return_value=aws_provider, + ): + with ( + mock.patch( + f"{CHECK_MODULE}.vpc_client", + new=VPC(aws_provider), + ), + mock.patch( + f"{CHECK_MODULE}.bedrock_client", + new=bedrock_with_guardrail, + ), + mock.patch( + f"{CHECK_MODULE}.bedrock_agent_client", + new=MOCK_BEDROCK_AGENT_CLIENT_NO_ACTIVITY, + ), + ): + from prowler.providers.aws.services.bedrock.bedrock_vpc_endpoints_configured.bedrock_vpc_endpoints_configured import ( + bedrock_vpc_endpoints_configured, + ) + + check = bedrock_vpc_endpoints_configured() + result = check.execute() + + # Region has Bedrock activity via guardrail, so VPC should be checked + assert len(result) == 1 + assert result[0].resource_id == vpc_id + assert result[0].status == "FAIL"