AWS Amazon EC2 Endpoint Service Allowed Principal

This page shows how to write Terraform and CloudFormation for Amazon EC2 Endpoint Service Allowed Principal and write them securely.

aws_vpc_endpoint_service_allowed_principal (Terraform)

The Endpoint Service Allowed Principal in Amazon EC2 can be configured in Terraform with the resource name aws_vpc_endpoint_service_allowed_principal. The following sections describe 4 examples of how to use the resource and its parameters.

Example Usage from GitHub

endpoint_service.tf#L7
resource "aws_vpc_endpoint_service_allowed_principal" "managed_envs" {
  for_each                = var.managed_envs_account_numbers
  vpc_endpoint_service_id = aws_vpc_endpoint_service.internet_proxy.id
  principal_arn           = format("arn:aws:iam::%s:root", each.value)
}

endpoint-service.tf#L8
resource "aws_vpc_endpoint_service_allowed_principal" "tarball_ingester" {
  count                   = local.tarball_ingester_uc_connected[local.environment] ? 1 : 0
  vpc_endpoint_service_id = aws_vpc_endpoint_service.tarball_ingester.id
  principal_arn           = format("arn:aws:iam::%s:root", local.ucfs_account[local.environment])
}

endpoint-service.tf#L7
resource "aws_vpc_endpoint_service_allowed_principal" "managed_envs" {
  count                   = length(lookup(local.mgmt_account_mapping, local.environment))
  vpc_endpoint_service_id = aws_vpc_endpoint_service.internet_proxy.id
  principal_arn           = format("arn:aws:iam::%s:root", lookup(local.account, element(local.mgmt_account_mapping[local.environment], count.index)))
}

vpce.tf#L7
resource "aws_vpc_endpoint_service_allowed_principal" "concourse_internal" {
  count                   = length(var.concourse_internal_allowed_principals)
  vpc_endpoint_service_id = aws_vpc_endpoint_service.concourse_internal.id
  principal_arn           = var.concourse_internal_allowed_principals[count.index]
}

Review your Terraform file for AWS best practices

Shisho Cloud, our free checker to make sure your Terraform configuration follows best practices, is available (beta).

Parameters

Explanation in Terraform Registry

Provides a resource to allow a principal to discover a VPC endpoint service.

NOTE on VPC Endpoint Services and VPC Endpoint Service Allowed Principals: Terraform provides both a standalone VPC Endpoint Service Allowed Principal resource and a VPC Endpoint Service resource with an allowed_principals attribute. Do not use the same principal ARN in both a VPC Endpoint Service resource and a VPC Endpoint Service Allowed Principal resource. Doing so will cause a conflict and will overwrite the association.

Tips: Best Practices for The Other AWS Amazon EC2 Resources

In addition to the aws_default_vpc, AWS Amazon EC2 has the other resources that should be configured for security reasons. Please check some examples of those resources and precautions.

risk-label

aws_default_vpc

Ensure to avoid using default VPC

It is better to define the own VPC and use it.

risk-label

aws_network_acl_rule

Ensure your network ACL rule blocks unwanted inbound traffic

It is better to block unwanted inbound traffic.

risk-label

aws_ebs_volume

Ensure to use a customer-managed key for EBS volume encryption

It is better to use a customer-managed key for EBS volume encryption. It can be gain more control over the encryption by using customer-managed keys (CMK).

risk-label

aws_instance

Ensure to avoid storing AWS access keys in user data

It is better to avoid storing AWS access keys in user data. `aws_iam_instance_profile` could be used instead.

risk-label

aws_security_group

Ensure your security group blocks unwanted inbound traffic

It is better to block unwanted inbound traffic.

Review your AWS Amazon EC2 settings

In addition to the above, there are other security points you should be aware of making sure that your .tf files are protected in Shisho Cloud.

AWS::EC2::VPCEndpoint (CloudFormation)

The VPCEndpoint in EC2 can be configured in CloudFormation with the resource name AWS::EC2::VPCEndpoint. The following sections describe 10 examples of how to use the resource and its parameters.

Example Usage from GitHub

routes.yml#L32
##    Type: AWS::EC2::VPCEndpoint
##    Properties:
##      VpcId:        !ImportValue vpc4
##      ServiceName:  !Sub 'com.amazonaws.${AWS::Region}.s3'
##      RouteTableIds:
##        - !ImportValue rtbVpc4Dmz
03-endpoint.yml#L25
    Type: "AWS::EC2::VPCEndpoint"
    Properties:
      RouteTableIds:
        - { "Fn::ImportValue": !Sub "${PJPrefix}-private-route-a" }
        - { "Fn::ImportValue": !Sub "${PJPrefix}-private-route-c" }
      ServiceName: !Sub "com.amazonaws.${AWS::Region}.s3"
endpoint.yml#L24
    Type: AWS::EC2::VPCEndpoint
    Properties:
      SecurityGroupIds:
        - Fn::ImportValue:
            !Sub ${SecurityStack}-SgEndpoint
      ServiceName: !Join
vpc_privatelink.yml#L182
    Type: AWS::EC2::VPCEndpoint
    Properties:
      ServiceName: !Sub com.amazonaws.${AWS::Region}.ssm
      VpcEndpointType: Interface
      PrivateDnsEnabled: true
      VpcId: !Ref VPC
VPC.yml#L148
    Type: 'AWS::EC2::VPCEndpoint'
    Properties:
      RouteTableIds:
        - !Ref myRouteTable
      VpcEndpointType: Gateway
      ServiceName: !Sub 'com.amazonaws.${AWS::Region}.s3'
custom_vpc_private_endpoint.json#L5
            "Type": "AWS::EC2::VPCEndpoint",
            "Properties": {
                "PrivateDnsEnabled": true,
                "SecurityGroupIds": [
                    "sg-test"
                ],
custom_vpc_private_endpoint_same_route_table.json#L5
            "Type": "AWS::EC2::VPCEndpoint",
            "Properties": {
                "PrivateDnsEnabled": true,
                "SecurityGroupIds": [
                    "sg-test"
                ],
integ.vpc-endpoint-service.expected.json#L4
      "Type": "AWS::EC2::VPCEndpointService",
      "Properties": {
        "NetworkLoadBalancerArns": [
          "arn:aws:elasticloadbalancing:us-east-1:123456789012:loadbalancer/net/Test/9bn6qkf4e9jrw77a"
        ],
        "AcceptanceRequired": false
batchNetwork.json#L126
            "Type": "AWS::EC2::VPCEndpoint",
            "Properties": {
                "PolicyDocument": {
                    "Version": "2012-10-17",
                    "Statement": [
                        {
vpc_private_china.json#L119
            "Type": "AWS::EC2::VPCEndpoint",
            "Properties": {
                "PrivateDnsEnabled": true,
                "SecurityGroupIds": ["sg-test"],
                "ServiceName": "cn.com.amazonaws.cn-north-1.ec2",
                "SubnetIds": [

Parameters

Explanation in CloudFormation Registry

Specifies a VPC endpoint for a service. An endpoint enables you to create a private connection between your VPC and the service. The service may be provided by AWS, an AWS Marketplace Partner, or another AWS account. For more information, see VPC Endpoints in the AWS PrivateLink User Guide.

A gateway endpoint serves as a target for a route in your route table for traffic destined for the AWS service. You can specify an endpoint policy to attach to the endpoint, which controls access to the service from your VPC. You can also specify the VPC route tables that use the endpoint.

For information about connectivity when you use a gateway endpoint to connect to an Amazon S3 bucket from an EC2 instance, see Why can’t I connect to an S3 bucket using a gateway VPC endpoint.

An interface endpoint is a network interface in your subnet that serves as an endpoint for communicating with the specified service. You can specify the subnets in which to create an endpoint, and the security groups to associate with the endpoint network interface.

A GatewayLoadBalancer endpoint is a network interface in your subnet that serves an endpoint for communicating with a Gateway Load Balancer that you've configured as a VPC endpoint service.

Frequently asked questions

What is AWS Amazon EC2 Endpoint Service Allowed Principal?

AWS Amazon EC2 Endpoint Service Allowed Principal is a resource for Amazon EC2 of Amazon Web Service. Settings can be wrote in Terraform and CloudFormation.

Where can I find the example code for the AWS Amazon EC2 Endpoint Service Allowed Principal?

For Terraform, the dwp/aws-analytical-env, dwp/dataworks-aws-tarball-ingester and north-kite/terraform-aws-egress-proxy source code examples are useful. See the Terraform Example section for further details.

For CloudFormation, the applerom/gos, fujisawatk/merpochi_server and jun-suzuki1028/sample-templete source code examples are useful. See the CloudFormation Example section for further details.