Skip to content

Commit

Permalink
Merge pull request #2267 from mchaker/mchaker-2022-07-ecs-introspecti…
Browse files Browse the repository at this point in the history
…on-access

ecs: add `iptables` rules for ECS introspection server
  • Loading branch information
mchaker authored Jul 8, 2022
2 parents 9ccbf6a + 0075507 commit 84d074d
Showing 1 changed file with 12 additions and 0 deletions.
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

0 comments on commit 84d074d

Please sign in to comment.