Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ecs: add iptables rules for ECS introspection server #2267

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/ecs-agent/ecs.service
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,29 @@ RestartSec=1s
EnvironmentFile=-/etc/ecs/ecs.config
EnvironmentFile=/etc/network/proxy.env
Environment=ECS_CHECKPOINT=true
# Grant ECS tasks access to the ECS task metadata endpoint
ExecStartPre=/sbin/iptables -t nat -A PREROUTING -d 169.254.170.2/32 \
-p tcp -m tcp --dport 80 -j DNAT --to-destination 127.0.0.1:51679
ExecStartPre=/sbin/iptables -t nat -A OUTPUT -d 169.254.170.2/32 \
-p tcp -m tcp --dport 80 -j REDIRECT --to-ports 51679
# Grant access to the ECS Introspection server
ExecStartPre=/sbin/iptables -t nat -A PREROUTING -d 172.17.0.1/32 \
-p tcp -m tcp --dport 51678 -j DNAT --to-destination 127.0.0.1:51678
ExecStartPre=/sbin/iptables -t nat -A OUTPUT -d 172.17.0.1/32 \
-p tcp -m tcp --dport 51678 -j REDIRECT --to-ports 51678
ExecStartPre=/sbin/iptables -t filter -I INPUT --dst 127.0.0.0/8 ! \
--src 127.0.0.0/8 -m conntrack ! --ctstate RELATED,ESTABLISHED,DNAT -j DROP
ExecStart=/usr/bin/amazon-ecs-agent
# Remove access to the ECS task metadata endpoint from ECS tasks
ExecStopPost=-/sbin/iptables -t nat -D PREROUTING -d 169.254.170.2/32 \
-p tcp -m tcp --dport 80 -j DNAT --to-destination 127.0.0.1:51679
ExecStopPost=-/sbin/iptables -t nat -D OUTPUT -d 169.254.170.2/32 \
-p tcp -m tcp --dport 80 -j REDIRECT --to-ports 51679
# Remove access to the ECS Introspection server
ExecStopPost=-/sbin/iptables -t nat -D PREROUTING -d 172.17.0.1/32 \
-p tcp -m tcp --dport 51678 -j DNAT --to-destination 127.0.0.1:51678
ExecStopPost=-/sbin/iptables -t nat -D OUTPUT -d 172.17.0.1/32 \
-p tcp -m tcp --dport 51678 -j REDIRECT --to-ports 51678
ExecStopPost=-/sbin/iptables -t filter -D INPUT --dst 127.0.0.0/8 ! \
--src 127.0.0.0/8 -m conntrack ! --ctstate RELATED,ESTABLISHED,DNAT -j DROP

Expand Down