Skip to content

Allow IPv6 for network blackhole port fault API #4629

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

Merged
merged 3 commits into from
May 13, 2025
Merged

Conversation

xxx0624
Copy link
Contributor

@xxx0624 xxx0624 commented May 8, 2025

Summary

This change is to allow drop packets for both IPv6 and IPv4 in the network blackhole port API in TMDS.

For IPv4 only or dual stack tasks, we will make IPv6 updates on a best effort basis. For IPv6 only tasks, both IPv4 and IPv6 updates are required.

Implementation details

  1. Allow IPv6 in SourcesToFiler field in the request body
  2. One additional chain will be injected to IPv6 table beside the same one for IPv4 table when the start fault API call is made. Any failure about IPv6 table update will impact IPv6 only tasks.
  3. The additional chain for IPv6 table will be removed when the stop fault API call is made. Any failure about IPv6 table update will impact IPv6 only tasks.
  4. For status check API, no major changes and we will check if the chain of IPv4 table exists.

Testing

New tests cover the changes:

yes

manual testing

  1. Launch a FIS enabled task with a patched AMI which has this change
  2. Use ecs exec to enter the container to start up a simple http server listens to port 8080 and local ipv6 addr
sh-5.2# python3 -m http.server 8000 --bind ::
Serving HTTP on :: port 8000 (http://[::]:8000/) ...
::1 - - [09/May/2025 19:05:59] "GET / HTTP/1.1" 200 -
::1 - - [09/May/2025 19:08:59] "GET / HTTP/1.1" 200 -
...
  1. Use ecs exec to inject network blackhole port fault and see how it behaves
// We can see it drops packet for port 8000
sh-5.2# curl -X POST $ECS_AGENT_URI/fault/v1/network-blackhole-port/status -d '{"Port":8000,"Protocol":"tcp","TrafficType":"egress"}'                                                                                                                                                           
{"Status":"not-running"}
sh-5.2# 
sh-5.2# curl -X POST $ECS_AGENT_URI/fault/v1/network-blackhole-port/start -d '{"Port":8000,"Protocol":"tcp","TrafficType":"egress"}'                                                                                                                                                             
{"Status":"running"}
sh-5.2# 
sh-5.2# curl -X POST $ECS_AGENT_URI/fault/v1/network-blackhole-port/status -d '{"Port":8000,"Protocol":"tcp","TrafficType":"egress"}'                                                                                                                                                            
{"Status":"running"}
sh-5.2# 
sh-5.2# curl [::1]:8000
^C
sh-5.2# curl [::1]:8000 -m 5
curl: (28) Connection timed out after 5002 milliseconds
sh-5.2# curl -X POST $ECS_AGENT_URI/fault/v1/network-blackhole-port/stop -d '{"Port":8000,"Protocol":"tcp","TrafficType":"egress"}'
{"Status":"stopped"}
sh-5.2# 
sh-5.2# curl -X POST $ECS_AGENT_URI/fault/v1/network-blackhole-port/status -d '{"Port":8000,"Protocol":"tcp","TrafficType":"egress"}'
{"Status":"not-running"}
sh-5.2# 
sh-5.2# curl -s -o /dev/null -w "%{http_code}" [::1]:8000 -m 5
200
sh-5.2# 

// We can see it's not blocking local IPv6 address 
sh-5.2# curl -X POST $ECS_AGENT_URI/fault/v1/network-blackhole-port/start -d '{"Port":8000,"Protocol":"tcp","TrafficType":"egress","SourcesToFilter":["::1"]}'                                                                                                                                 
{"Status":"running"}
sh-5.2# 
sh-5.2# curl -X POST $ECS_AGENT_URI/fault/v1/network-blackhole-port/status -d '{"Port":8000,"Protocol":"tcp","TrafficType":"egress"}'
{"Status":"running"}
sh-5.2# 
sh-5.2# curl -s -o /dev/null -w "%{http_code}" [::1]:8000 -m 5
200
sh-5.2# 
// And we can see the expected iptables change
[root@ip-10-0-129-206 ~]# <enter task ns> iptables -nL
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         
egress-tcp-8000  all  --  0.0.0.0/0            0.0.0.0/0           

Chain egress-tcp-8000 (1 references)
target     prot opt source               destination         
DROP       tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:8000
[root@ip-10-0-129-206 ~]# <enter task ns> ip6tables -nL
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination         
egress-tcp-8000  all      ::/0                 ::/0                

Chain egress-tcp-8000 (1 references)
target     prot opt source               destination         
ACCEPT     tcp      ::/0                 ::1                  tcp dpt:8000
DROP       tcp      ::/0                 ::/0                 tcp dpt:8000
[root@ip-10-0-129-206 ~]#

Description for the changelog

  • Feature - expand the network blackhole port to allow drop packets for IPv6.

Additional Information

Does this PR include breaking model changes? If so, Have you added transformation functions?

No

Does this PR include the addition of new environment variables in the README?

No

Licensing

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@xxx0624 xxx0624 marked this pull request as ready for review May 9, 2025 19:23
@xxx0624 xxx0624 requested a review from a team as a code owner May 9, 2025 19:23
@@ -141,6 +145,8 @@ func (h *FaultHandler) StartNetworkBlackholePort() func(http.ResponseWriter, *ht
return
}

isIPv6OnlyTask := isIPv6OnlyTask(taskMetadata)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: is this variable necessary? Can we pass in isIPv6OnlyTask(taskMetadata) directly on line 181?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I can do that in a follow up change.

Copy link
Contributor Author

@xxx0624 xxx0624 May 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in a new rev.

@@ -542,7 +601,7 @@ func (h *FaultHandler) CheckNetworkBlackHolePort() func(http.ResponseWriter, *ht
}
}

// checkNetworkBlackHolePort will check if there's a running black hole port within the task network namespace based on the chain name and the passed in required request fields.
// checkNetworkBlackHolePort will check if there's a running black hole port within the task network namespace based on the chain in IPv4 tables.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit(non-blocking): might be helpful to provide a reason why we can just rely on checking the Ipv4 route tables to see if a BHP fault is running.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I will add that in a new rev.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in a new rev.


func IsIPv6(s string) bool {
parsedIP := net.ParseIP(s)
return parsedIP != nil && parsedIP.To4() == nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we want parsedIP.To4() == nil and not parsedIP.To16() != nil?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To16 func will return non-empty value for IPv4 addr - https://go.dev/play/p/sBjowEPblpW

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow

@xxx0624 xxx0624 enabled auto-merge (squash) May 13, 2025 16:58
@xxx0624 xxx0624 merged commit fcffb5f into aws:dev May 13, 2025
40 checks passed
xxx0624 added a commit to xxx0624/amazon-ecs-agent that referenced this pull request May 14, 2025
* Allow IPv6 for network blackhole port fault API

* Fail network blackhole port API for IPv6 only tasks

* Update comments
xxx0624 added a commit to xxx0624/amazon-ecs-agent that referenced this pull request May 15, 2025
* Allow IPv6 for network blackhole port fault API

* Fail network blackhole port API for IPv6 only tasks

* Update comments
@danehlim danehlim mentioned this pull request May 20, 2025
timj-hh pushed a commit to timj-hh/amazon-ecs-agent that referenced this pull request Jul 19, 2025
* Allow IPv6 for network blackhole port fault API

* Fail network blackhole port API for IPv6 only tasks

* Update comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants