Sub topic 12
DNS names, security groups, and who may connect
This chapter covers the controls that sit around a PrivateLink connection: how consumers resolve the service name, which security groups filter traffic, and how the provider decides who may connect. It assumes you have already published an endpoint service from a Network Load Balancer (NLB) and created an interface endpoint, as in the previous two chapters. You should also know how security groups and network ACLs work.
Three layers of control
A PrivateLink connection is governed by three separate layers. A failure in any one of them looks like a timeout or a refused connection, so it helps to know which layer you are debugging.
| Layer | Who controls it | Question it answers |
|---|---|---|
| Endpoint service permissions and acceptance | Provider | May this account or principal create an endpoint to my service? |
| Security group on the endpoint network interfaces | Consumer | Which clients in my VPC may send traffic to the endpoint? |
| Endpoint policy, DNS, and routing in the consumer VPC | Consumer | Which names resolve to the endpoint, and what may be done through it? |
The provider never sees the consumer's VPC, and the consumer never sees the provider's. This is what separates PrivateLink from network-level connectivity such as Transit Gateway.
DNS names for an interface endpoint
When you create an interface endpoint, AWS places one elastic network interface (ENI) in each subnet you chose. Each ENI gets a private IP address from that subnet. Every endpoint receives generated DNS names that resolve to those addresses:
- A regional name, such as
vpce-0123456789abcdef0-abcd1234.vpce-svc-0123456789abcdef0.us-east-1.vpce.amazonaws.com. It resolves to the ENI addresses in all the endpoint's subnets. - A zonal name, which has the Availability Zone in it, such as
vpce-0123456789abcdef0-abcd1234-us-east-1a.vpce-svc-0123456789abcdef0.us-east-1.vpce.amazonaws.com. It resolves only to the ENI in that zone.
Use the regional name by default. Use a zonal name when you want to keep traffic inside one zone, for example to avoid cross-zone data charges or to test one zone at a time.
Private DNS names
A generated name is hard to remember and hard to put in application configuration. The provider can instead associate a private DNS name with the endpoint service, for example orders.example.com. The consumer then enables private DNS on the endpoint, and the name resolves to the endpoint's ENI addresses inside the consumer VPC.
Before AWS accepts a private DNS name, the provider has to prove that they own the domain. AWS gives the provider a TXT record name and value, and the provider adds it to the domain's public DNS zone. The service's private DNS name state then moves from pendingVerification to verified.
The provider sets the name like this:
aws ec2 modify-vpc-endpoint-service-configuration \
--service-id vpce-svc-0123456789abcdef0 \
--private-dns-name orders.example.com
aws ec2 start-vpc-endpoint-service-private-dns-verification \
--service-id vpce-svc-0123456789abcdef0
aws ec2 describe-vpc-endpoint-service-configurations \
--service-ids vpce-svc-0123456789abcdef0 \
--query "ServiceConfigurations[0].PrivateDnsNameConfiguration"The last command shows the verification state, plus the TXT record Name and Value to publish.
The consumer then turns on private DNS for the endpoint:
aws ec2 modify-vpc-endpoint \
--vpc-endpoint-id vpce-0123456789abcdef0 \
--private-dns-enabledAWS creates a private hosted zone behind the scenes for that name and attaches it to the consumer VPC.
A consequence of private DNS is that the name resolves differently depending on where the query comes from. Inside the consumer VPC, orders.example.com returns private ENI addresses. Outside it, the same name returns whatever your public DNS says. Clients in other VPCs or on-premises networks that reach the consumer VPC through a transit gateway do not get the private answer automatically. They need a Route 53 Resolver inbound endpoint or a shared private hosted zone to resolve the name. This is a frequent source of "works from one VPC, fails from the next" reports.
Security groups on the endpoint
Each interface endpoint has security groups attached to its ENIs. They work like any other ENI security group, with these points that matter in practice:
- The security group must allow inbound traffic on the service's listener port from the clients. If you leave it unspecified, the VPC's default security group is used, and that may not allow your clients.
- Reference client security groups as the source where the clients are in the same VPC. Use CIDR ranges for clients that arrive through a transit gateway, because a security group reference only works within the same VPC or a peered VPC.
- You do not need outbound rules for return traffic, because security groups are stateful.
- Network ACLs on the endpoint subnets also apply and are stateless. Allow the listener port inbound and the ephemeral ports outbound.
The provider side has its own detail. The NLB sees the client's traffic as coming from the NLB's own addresses by default, not the consumer's. If the provider needs the consumer's source IP, enable Proxy Protocol v2 on the NLB target group. The provider's target security groups then have to allow traffic from the NLB, and if the NLB has a security group attached, from that group.
Here is a consumer endpoint security group that allows HTTPS from a client subnet range:
aws ec2 create-security-group \
--group-name orders-endpoint-sg \
--description "Clients of the orders endpoint service" \
--vpc-id vpc-0aaa1111bbb22222c
aws ec2 authorize-security-group-ingress \
--group-id sg-0123456789abcdef0 \
--protocol tcp \
--port 443 \
--cidr 10.1.0.0/16Who may connect
Access control starts on the provider side, with two settings you have already met.
- Allowed principals. This is an allow list of IAM principals, such as an account root, a user, or a role. A principal not on the list cannot even request a connection. The
--add-allowed-principalsoption in the earlier example set this. - Acceptance required. When on, every connection request waits in
pendingAcceptanceuntil the provider callsaccept-vpc-endpoint-connections. Usereject-vpc-endpoint-connectionsto refuse one.
Allowing the account root (arn:aws:iam::444455556666:root) permits any principal in that account that has the right IAM permissions to create the endpoint. A narrower role ARN limits who in that account can connect. The consumer's IAM identity also needs ec2:CreateVpcEndpoint permission, so the consumer organization keeps its own control.
Endpoint policies
An endpoint policy is an IAM resource policy attached to the endpoint on the consumer side. It limits what can be done through the endpoint. For AWS services reached through interface endpoints, this can restrict actions and resources. For a custom endpoint service behind an NLB, support is limited, because the NLB passes plain TCP or TLS and AWS cannot inspect API calls. Do not rely on an endpoint policy to restrict access to your own service. Enforce authorization in the application.
Checking and changing connections
The provider can list connections and their states, and remove access later:
aws ec2 describe-vpc-endpoint-connections \
--filters Name=service-id,Values=vpce-svc-0123456789abcdef0
aws ec2 modify-vpc-endpoint-service-permissions \
--service-id vpce-svc-0123456789abcdef0 \
--remove-allowed-principals arn:aws:iam::444455556666:rootRemoving a principal from the allow list does not tear down endpoints that already exist. To cut off an existing connection, reject it with reject-vpc-endpoint-connections.
Common errors
| Symptom | Likely cause |
|---|---|
| Endpoint stays in `pendingAcceptance` | Provider has not run `accept-vpc-endpoint-connections`. |
| `create-vpc-endpoint` is denied | The consumer principal is not on the allow list, or lacks IAM permission. |
| Private name resolves to a public address | Private DNS not enabled, or VPC DNS attributes are off. |
| Connection times out from the same VPC | Endpoint security group does not allow the client or port. |
| Works in the consumer VPC, fails from another VPC | The other VPC cannot resolve the private DNS name. |
| Connections fail only from some zones | The endpoint has no subnet in that zone, or the NLB lacks targets there. |
Exercise
A consumer enabled private DNS for orders.example.com on an interface endpoint. Instances in the same VPC connect fine. Instances in a second VPC, attached to the same transit gateway, get a public IP address for the name and time out. Why, and what are two ways to fix it?
Show answer
The private hosted zone that AWS creates for private DNS is attached only to the consumer VPC where the endpoint lives, so the second VPC resolves the name through public DNS. Fix it by associating a private hosted zone for the name with the second VPC, with records pointing at the endpoint addresses, or by forwarding queries from the second VPC to the consumer VPC with Route 53 Resolver endpoints and rules. The second VPC must also have a route to the endpoint subnets through the transit gateway and the endpoint security group must allow its CIDR.
Exercise
The provider removed an account from the allowed principals list, but that account's endpoint is still carrying traffic. What must the provider do to stop it?
Show answer
Removing the principal only blocks new connection requests. The provider must reject the existing connection with aws ec2 reject-vpc-endpoint-connections, giving the service ID and the endpoint ID.