Use iptables to disable network (#2363)

* Use iptables to disable network

* Fix race condition problem

* Enable network after test finishes
This commit is contained in:
yhirose
2026-02-12 17:46:26 -10:00
committed by GitHub
parent 14e37bd75b
commit c1ee85d89e
2 changed files with 34 additions and 21 deletions

View File

@@ -40,7 +40,13 @@ jobs:
if: matrix.tls_backend == 'openssl'
run: sudo apt-get install -y libssl-dev
- name: disable network
run: sudo sh -c 'echo > /etc/resolv.conf'
run: |
sudo iptables -A OUTPUT -o lo -j ACCEPT
sudo iptables -A OUTPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
sudo iptables -A OUTPUT -j REJECT
sudo ip6tables -A OUTPUT -o lo -j ACCEPT
sudo ip6tables -A OUTPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
sudo ip6tables -A OUTPUT -j REJECT
- name: build and run tests (OpenSSL)
if: matrix.tls_backend == 'openssl'
run: cd test && make
@@ -49,3 +55,8 @@ jobs:
- name: build and run tests (No TLS)
if: matrix.tls_backend == 'no-tls'
run: cd test && make test_no_tls && ./test_no_tls
- name: restore network
if: always()
run: |
sudo iptables -F OUTPUT
sudo ip6tables -F OUTPUT