aws / aws/containers-roadmap

ECS Metadata return region

Open
#337 3 comments 3 reactions 0 assignees View on GitHub
ECS Proposed
Dominant language
Shell
Stars
5.4k
Forks
334
PR merge metrics
No merged PRs in 30d

Description

### Summary
To make running containers on ECS easier, I think it would be appropriate to return some additional metadata on the ECS metadata endpoint.
EG: Region
### Description
A service running on ECS with the set rules for secure ECS Task roles
```
# Block access to the metadata service IP address over the docker bridge
iptables --insert DOCKER-USER 1 --in-interface docker+ --destination 169.254.169.254/32 --jump DROP
# Forwards traffic destined for a AWS magic IP address to the ecs-agent container
iptables -t nat -A PREROUTING -p tcp -d 169.254.170.2 --dport 80 -j DNAT --to-destination 127.0.0.1:51679
iptables -t nat -A OUTPUT -d 169.254.170.2 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 51679
echo 'net.ipv4.conf.all.route_localnet = 1' >>/etc/sysctl.d/99-ecs.conf
```
Is unable to resolve its region, for this reason we have to pass `AWS_REGION` to all services that use AWS services, instead of the SDK being able to resolve it.

This is a multi-part fix, but I think the first step is returning some information to the container on its metadata endpoint at `169.254.170.2`. Values like `region` `architecture` `accountId` shuold be safe to pass through and give better compatibility.

Its important to keep in mind how the SDKs are going to implement this changes, EG: https://github.com/boto/botocore/blob/8d3ea0e61473fba43774eb3c74e1b22995ee7370/botocore/credentials.py#L80 botocore has a chain of providers, we can do something similar for instance meta, and then use the same url paths as we use from EC2 Meta.

The alternative as user is:
A) Pass the region or other info
B) Implement something like: https://stackshare.io/remind/keeping-aws-secrets-secret-with-ecs with iptables to route `docker->nginxmeta` when `docker->169.254.169.254/32`
which I think its super clever, but might confuse the SDK using it as it can also reach the instance metadata.

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the ECS metadata endpoint at 169.254.170.2 and the linked botocore instance-metadata provider behavior. Define compatible URL paths and determine how region, architecture, and accountId should be exposed without weakening the stated metadata-access restrictions. Done means the endpoint provides the agreed metadata for ECS containers and supports SDK-style discovery.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, shell
Domain
cloud, infrastructure
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.