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

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

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.

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?

@@ -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.

@@ -202,6 +203,7 @@ func NewNetworkFaultInjectionErrorResponse(err string) NetworkFaultInjectionResp
}
}

// validateNetworkFaultRequestSources validates each source is IPv4 or IPv4 CIDR block.
Copy link
Contributor

Choose a reason for hiding this comment

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

Q: Are we still using this function anywhere?

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.

4 participants