Skip to content

Commit 3395841

Browse files
authored
Explicit error message on VPC endpoint check for shared VPC subnets (#29)
1 parent 1a6b19e commit 3395841

File tree

2 files changed

+43
-29
lines changed

2 files changed

+43
-29
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ Note that the `Condition` element of the IAM policy is not currently supported t
122122
17. **_🟡 SSM PrivateLink "com.amazonaws.(region).ssmmessages" not found_**
123123
The `check-ecs-exec.sh` found one or more VPC endpoints configured in the VPC for your task, so you **may** want to add an additional SSM PrivateLink for your VPC. Make sure your ECS task has proper outbound internet connectivity, and if it doesn't, then you **need** to configure an additional SSM PrivateLink for your VPC.
124124

125+
18. **_🔴 VPC Endpoints | CHECK FAILED_**
126+
The `check-ecs-exec.sh` doesn't support checking this item for shared VPC subnets using [AWS Resouce Access Manager (AWS RAM)](https://aws.amazon.com/ram/). In short, this may not an issue to use ECS Exec if your ECS task VPC doesn't have any VPC endpoint and the task has proper outbound internet connectivity. Make sure to consult your administrator with the official ECS Exec documentation](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-exec.html#ecs-exec-considerations) to find if your VPC need to have an additional VPC endpoint.
127+
125128
## Security
126129

127130
See [CONTRIBUTING](CONTRIBUTING.md#security-issue-notifications) for more information.

check-ecs-exec.sh

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -606,46 +606,57 @@ fi
606606
# 10. Check existing VPC Endpoints (PrivateLinks) in the task VPC.
607607
# If there is any VPC Endpoints configured for the task VPC, we assume you would need an additional SSM PrivateLink to be configured. (yellow)
608608
# TODO: In the ideal world, the script should simply check if the task can reach to the internet or not :)
609+
requiredEndpoint="com.amazonaws.${AWS_REGION}.ssmmessages"
609610
taskNetworkingAttachment=$(echo "${describedTaskJson}" | jq -r ".tasks[0].attachments[0]")
610-
taskVpcId=""
611+
taskSubnetId=$(echo "${describedTaskJson}" | jq -r ".tasks[0].attachments[0].details[] | select(.name==\"subnetId\") | .value")
612+
subnetJson=$(${AWS_CLI_BIN} ec2 describe-subnets --subnet-ids "${taskSubnetId}")
611613
if [[ "x${taskNetworkingAttachment}" = "xnull" ]]; then
612614
## bridge/host networking (only for EC2)
613615
taskVpcId=$(echo "${describedContainerInstanceJson}" | jq -r ".containerInstances[0].attributes[] | select(.name==\"ecs.vpc-id\") | .value")
614616
else
615617
## awsvpc networking (for both EC2 and Fargate)
616-
taskSubnetId=$(echo "${describedTaskJson}" | jq -r ".tasks[0].attachments[0].details[] | select(.name==\"subnetId\") | .value")
617-
taskVpcId=$(${AWS_CLI_BIN} ec2 describe-subnets --subnet-ids "${taskSubnetId}" | jq -r ".Subnets[0].VpcId")
618+
taskVpcId=$(echo "${subnetJson}" | jq -r ".Subnets[0].VpcId")
618619
fi
619-
## List Vpc Endpoints
620-
vpcEndpointsJson=$(${AWS_CLI_BIN} ec2 describe-vpc-endpoints \
621-
--filters Name=vpc-id,Values="${taskVpcId}")
622-
vpcEndpoints=$(echo "${vpcEndpointsJson}" | tr -d '\n' | jq -r ".VpcEndpoints[]")
620+
## Obtain the ownerID of subnet's owner to check if the subnet is shared via AWS RAM (which check-ecs-exec.sh doesn't support today)
621+
subnetOwnerId=$(echo "${subnetJson}" | jq -r ".Subnets[0].OwnerId")
623622
printf "${COLOR_DEFAULT} VPC Endpoints | "
624-
if [[ "x${vpcEndpoints}" = "x" ]]; then
625-
printf "${COLOR_GREEN}SKIPPED ${COLOR_DEFAULT}(${taskVpcId} - No additional VPC endpoints required)\n"
623+
if [[ ! "x${ACCOUNT_ID}" = "x${subnetOwnerId}" ]]; then
624+
## Shared Subnets (VPC) are not supported in Amazon ECS Exec Checker
625+
printf "${COLOR_RED}CHECK FAILED${COLOR_YELLOW}\n"
626+
printf " Amazon ECS Exec Checker doesn't support VPC endpoint validation for AWS RAM shared VPC/subnets.\n"
627+
printf " Contact your administrator to find if the following resources require to have an additional VPC endpoint.\n"
628+
printf " - Resources: ${taskVpcId} and ${taskSubnetId}\n"
629+
printf " - VPC Endpoint: ${requiredEndpoint}${COLOR_DEFAULT}\n"
626630
else
627-
# Check whether an ssmmessages VPC endpoint exists
628-
vpcEndpoints=$(echo "${vpcEndpointsJson}" | tr -d '\n' | jq -r ".VpcEndpoints[].ServiceName")
629-
printf "\n"
630-
ssmsessionVpcEndpointExists=false
631-
requiredEndpoint="com.amazonaws.${AWS_REGION}.ssmmessages"
632-
for vpe in $vpcEndpoints; do
633-
if [[ "x${vpe}" = "x${requiredEndpoint}" ]]; then
634-
ssmsessionVpcEndpointExists=true
635-
break
636-
fi
637-
done
631+
## List Vpc Endpoints
632+
vpcEndpointsJson=$(${AWS_CLI_BIN} ec2 describe-vpc-endpoints \
633+
--filters Name=vpc-id,Values="${taskVpcId}")
634+
vpcEndpoints=$(echo "${vpcEndpointsJson}" | tr -d '\n' | jq -r ".VpcEndpoints[]")
635+
if [[ "x${vpcEndpoints}" = "x" ]]; then
636+
printf "${COLOR_GREEN}SKIPPED ${COLOR_DEFAULT}(${taskVpcId} - No additional VPC endpoints required)\n"
637+
else
638+
# Check whether an ssmmessages VPC endpoint exists
639+
vpcEndpoints=$(echo "${vpcEndpointsJson}" | tr -d '\n' | jq -r ".VpcEndpoints[].ServiceName")
640+
printf "\n"
641+
ssmsessionVpcEndpointExists=false
642+
for vpe in $vpcEndpoints; do
643+
if [[ "x${vpe}" = "x${requiredEndpoint}" ]]; then
644+
ssmsessionVpcEndpointExists=true
645+
break
646+
fi
647+
done
638648

639-
printf " Found existing endpoints for ${taskVpcId}:\n"
640-
for vpe in $vpcEndpoints; do
641-
if [[ "x${vpe}" = "x${requiredEndpoint}" ]]; then
642-
printf " - ${COLOR_GREEN}${vpe}${COLOR_DEFAULT}\n"
643-
else
644-
printf " - ${COLOR_DEFAULT}${vpe}\n"
649+
printf " Found existing endpoints for ${taskVpcId}:\n"
650+
for vpe in $vpcEndpoints; do
651+
if [[ "x${vpe}" = "x${requiredEndpoint}" ]]; then
652+
printf " - ${COLOR_GREEN}${vpe}${COLOR_DEFAULT}\n"
653+
else
654+
printf " - ${COLOR_DEFAULT}${vpe}\n"
655+
fi
656+
done
657+
if [[ "x${ssmsessionVpcEndpointExists}" = "xfalse" ]]; then
658+
printf " SSM PrivateLink \"${COLOR_YELLOW}${requiredEndpoint}${COLOR_DEFAULT}\" not found. You must ensure your task has proper outbound internet connectivity."
645659
fi
646-
done
647-
if [[ "x${ssmsessionVpcEndpointExists}" = "xfalse" ]]; then
648-
printf " SSM PrivateLink \"${COLOR_YELLOW}${requiredEndpoint}${COLOR_DEFAULT}\" not found. You must ensure your task has proper outbound internet connectivity."
649660
fi
650661
fi
651662

0 commit comments

Comments
 (0)