Skip to content

fargate ECS task is not starting without public IP -> The task cannot pull secrets from AWS Systems Manager

0

i am trying to start a fargate ECS task without a public IP (because it is tucked behind an application load balancer and ultimately behind an AWS rest api) but get the error message

ResourceInitializationError: unable to pull secrets or registry auth: unable to retrieve secrets from ssm: The task cannot pull secrets from AWS Systems Manager. There is a connection issue between the task and AWS Systems Manager Parameter Store. Check your task network configuration. RequestCanceled: request context canceled caused by: context deadline exceeded

the exact same task / service works fine, when i activate the public IP. the task:

  • is based on a public dockerhub image (no ECR involved and no credentials)
  • is using secrets from the system managers parameter store (credentials for database access)
  • is using awslogs as logDriver

while researching issues with non-public-ip-ecs-tasks i learned that i need to create VPC endpoints. so i did create:

  • com.amazonaws.eu-central-1.ecs-agent
  • com.amazonaws.eu-central-1.ecs-telemetry
  • com.amazonaws.eu-central-1.ecs
  • com.amazonaws.eu-central-1.ecr.dkr (probably not needed since i dont use the ECR)
  • com.amazonaws.eu-central-1.ecr.api (probably not needed since i dont use the ECR)
  • com.amazonaws.eu-central-1.logs
  • com.amazonaws.eu-central-1.secretsmanager

all endpoints:

  • are using eu-central-1 (same as my task / service)
  • are using the same VPC (i only have one currently)
  • are using the same subnets as my task / service
  • are using the same security group (all traffic outbound allowed, all traffic inbound allowed to all IPs in my VPC - i also tried 0.0.0.0/0 as destination here but that didnt change anyting)

to read secrets from the parameter store, i had to create a role and set it via executionRoleArn in my task definition. i used https://repost.aws/knowledge-center/ecs-data-security-container-task as a template but to be honest, didnt really understand what i was doing exactly. my role has 2 permission policies. one is the aws managed AmazonECSTaskExecutionRolePolicy. the other is my custom inline policy that looks like this:

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "ssm:GetParameters",
                "secretsmanager:GetSecretValue"
            ],
            "Resource": [
                "arn:aws:ssm:eu-central-1:123:parameter/FOO"
            ]
        }
    ]
}

i would be eternally thankful if anybody could find the issue because i am out of ideas. and also new to AWS.

asked 2 years ago931 views

2 Answers
1
Accepted Answer

For Parameter store based on your error, you will need the following endpoint

com.amazonaws.eu-central-1.ssm

EXPERT

answered 2 years ago

EXPERT

reviewed 2 years ago

  • @Gary Mclean tyvm, that worked. unfortunately now i get

    CannotPullContainerError: pull image manifest has been retried 5 time(s): failed to resolve ref docker.io/foo/bar:0.0.1@sha256:baz: failed to do request: Head "https://registry-1.docker.io/v2/foo/bar/manifests/sha256:baz": dial tcp 54.227.20.253:443: i/o timeout

    url can be opened by browser, so its not an docker.io issue (also works with public IP for the ECS task / service). the service has a security group that allows all outbound IPv4 traffic to 0.0.0.0/0.

    also: whats the preferred process here? should i open a new question for this and mark your answer as accepted or should i keep follow-ups in the same 'thread'?

  • Without access to the internet, ECS cant download the docker image from a public Repo registry-1.docker.io If you want to access the registry without a PUBLIC IP, then your ECS Service needs to be on a Private Subnet with a NAT Gateway in a Public Subnet. This also means you will not need any Private endpoints if you dont want to use them and you still have Public internet access. If you want to keep it all private, you can setup a ECR Pull through Cache with docker then your ECS Service will not need public internet

  • Happy to help out here and before/after you wish to accept the answer. I hope my comment has explained the next issue? I can supply a couple of links if needed about VPC Private/Public Subnets etc

  • This is how private resources can access the internet without public IPS https://docs.aws.amazon.com/vpc/latest/userguide/vpc-example-private-subnets-nat.html i.e. ECS Services. Place your ECS Services in a private subnet

  • @Gary Mclean: thx for the hints. that will take some time to read into. what confuses me right now is that the subnets i use (they were created by default) are public, i.e. 'Auto-assign public IPv4 address' is set to 'yes'. they are also the exact same subnets i used when i activate 'public IP address' in my service definition (then the image can be pulled). i dont really understand how this works together. i would think that there is some AWS component pulling the image, creating the container and so on that does not live in my subnets or vpc even but has access to it. thats obviously not the case. i guess i have some reading to to. thx for your help. i will accept your answer.

0

Based on the information provided, it appears that your Fargate ECS task is unable to connect to AWS Systems Manager Parameter Store to retrieve secrets when running without a public IP. This is likely due to networking configuration issues. Here are some steps to troubleshoot and potentially resolve the problem:

  1. VPC Endpoints: You've already created several VPC endpoints, which is good. However, for accessing Systems Manager Parameter Store, you need to ensure you have the following endpoint:

    • com.amazonaws.eu-central-1.ssm

    Make sure to create this endpoint if it's not already present.

  2. Security Group Configuration: Verify that the security group associated with your VPC endpoints allows inbound traffic from the security group associated with your Fargate tasks. This is crucial for enabling communication between your tasks and the VPC endpoints.

  3. Route Table: Ensure that the route table associated with your private subnets has routes to the VPC endpoints. This is necessary for directing traffic to the endpoints.

  4. IAM Role Permissions: Your IAM role seems to have the correct permissions for accessing Systems Manager parameters. However, make sure the resource ARN in your custom policy matches exactly with the ARN of the parameter you're trying to access.

  5. Task Definition: In your task definition, ensure that you're using the correct execution role ARN (executionRoleArn) that has the necessary permissions.

  6. Network Configuration: Double-check that your task is indeed using the private subnets where you've set up the VPC endpoints.

  7. DNS Settings: Ensure that DNS hostnames and DNS resolution are enabled for your VPC. This is required for the VPC endpoints to work correctly.

  8. Fargate Platform Version: Use the latest Fargate platform version (1.4.0 or later) as it includes improvements in networking and supports the task metadata endpoint version 4.

If after implementing these suggestions you still encounter issues, you may want to use Amazon ECS Exec to access a container in your task and manually test the connection to the Systems Manager endpoint. This can help identify if there are any remaining networking or permission issues.

Remember, when running Fargate tasks in private subnets without public IPs, it's crucial to have properly configured VPC endpoints and network settings to allow the tasks to communicate with AWS services.
Sources
Troubleshoot metadata errors in my ECS Fargate tasks | AWS re:Post
Amazon ECS task networking options for the Fargate launch type - Amazon Elastic Container Service
Amazon ECS task metadata available for tasks on Fargate - Amazon Elastic Container Service

answered 2 years ago

EXPERT

reviewed 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.