Commit Graph

23 Commits

Author SHA1 Message Date
Toshi Kikuchi d1edabdca0 iptables: support postrouting hook and SNAT target
The current SNAT implementation has several limitations:
- SNAT source port has to be specified. It is not optional.
- SNAT source port range is not supported.
- SNAT for UDP is a one-way translation. No response packets
  are handled (because conntrack doesn't support UDP currently).
- SNAT and REDIRECT can't work on the same connection.

Fixes #5489

PiperOrigin-RevId: 367750325
2021-04-09 21:11:26 -07:00
Kevin Krakauer 2f35fa14ab Deflake //test/iptables:iptables_test
We were opening dual-stack sockets, but tests only set iptables rules for a
single network protocol. Thus, packets (probably sent by previous tests) could
sneak in and break tests.

Tested with:
bazel test ///test/iptables:iptables_test
--test_arg=--runtime=runsc --nocache_test_results --test_output=errors
--runs_per_test=1000 --test_filter=TestFilterInputDropUDP
PiperOrigin-RevId: 357972385
2021-02-17 10:02:02 -08:00
Toshi Kikuchi cfbf209173 iptables: support matching the input interface name
We have support for the output interface name, but not for the input
interface name.
This change adds the support for the input interface name, and adds the
test cases for it.

Fixes #5300

PiperOrigin-RevId: 353179389
2021-01-21 23:19:19 -08:00
Kevin Krakauer 805a96d7ba Speed up iptables tests
//test/iptables:iptables_test runs 30 seconds faster on my machine.

* Using contexts instead of many smaller timeouts makes the tests less
  likely to flake and removes unnecessary complexity.
* We also use context to properly shut down concurrent goroutines and
  the test container.
* Container logs are always logged.
2020-08-10 17:50:01 -07:00
Kevin Krakauer 2a7b2a61e3 iptables: support SO_ORIGINAL_DST
Envoy (#170) uses this to get the original destination of redirected
packets.
2020-07-31 10:47:26 -07:00
Kevin Krakauer d9c9420335 ip6tables testing
We skip gVisor tests for now, as ip6tables aren't yet implemented.
2020-07-28 10:51:14 -07:00
Kevin Krakauer da631a3ef2 Speed up some iptables tests
Sending UDP packets in a loop can be done in a separate goroutine. We
can't do this in ContainerAction because the container will terminate
early.

Locally, scripts/iptables_tests.sh runs ~40 seconds faster.
2020-07-24 15:06:07 -07:00
Kevin Krakauer 14ff2ea9bf ip6tables: handle both IPv4 and v6 addresses
Enabling IPv6 in Docker caused IPv4 tests to fail because localAddrs
didn't distinguish between address types. Example failure:
https://source.cloud.google.com/results/invocations/203b2401-3333-4bec-9a56-72cc53d68ddd/log
2020-07-08 15:14:29 -07:00
gVisor bot cfd30665c1 iptables - filter packets using outgoing interface.
Enables commands with -o (--out-interface) for iptables rules.
$ iptables -A OUTPUT -o eth0 -j ACCEPT

PiperOrigin-RevId: 310642286
2020-05-08 15:44:54 -07:00
Nayana Bidari b660f16d18 Support for connection tracking of TCP packets.
Connection tracking is used to track packets in prerouting and
output hooks of iptables. The NAT rules modify the tuples in
connections. The connection tracking code modifies the packets by
looking at the modified tuples.
2020-05-01 16:59:40 -07:00
Adin Scannell 1481499fe2 Simplify Docker test infrastructure.
This change adds a layer of abstraction around the internal Docker APIs,
and eliminates all direct dependencies on Dockerfiles in the infrastructure.

A subsequent change will automated the generation of local images (with
efficient caching). Note that this change drops the use of bazel container
rules, as that experiment does not seem to be viable.

PiperOrigin-RevId: 308095430
2020-04-23 11:33:30 -07:00
Kevin Krakauer a8f9cc8798 iptables: deflake DropTCP*Port tests
These tests could timeout because net.DialTCP didn't respect the
timeout.
2020-03-18 18:16:33 -07:00
gVisor bot 159a230b9b Merge pull request #1943 from kevinGC:ipt-filter-ip
PiperOrigin-RevId: 301197007
2020-03-16 11:13:14 -07:00
Kevin Krakauer 4054b021f0 iptables: ready tests to be enabled in kokoro
Fixed flakes (tested via --runs_per_test=100) and added skips for
not-yet-implemented features. Once submitted, the iptables tests will be
ready to enable in kokoro.
2020-03-11 15:13:58 -07:00
Kevin Krakauer 408979e619 iptables: filter by IP address (and range)
Enables commands such as:
$ iptables -A INPUT -d 127.0.0.1 -j ACCEPT
$ iptables -t nat -A PREROUTING ! -d 127.0.0.1 -j REDIRECT

Also adds a bunch of REDIRECT+destination tests.
2020-02-26 11:04:00 -08:00
gVisor bot 247843bbc5 iptables: use "-t nat" for NAT tests
PiperOrigin-RevId: 295835807
2020-02-18 15:25:51 -08:00
Kevin Krakauer 6ef63cd7da We can now create and jump in iptables. For example:
$ iptables -N foochain
$ iptables -A INPUT -j foochain
2020-02-13 17:02:50 -08:00
gVisor bot 3d10edc942 Merge pull request #1617 from kevinGC:iptables-write-filter-proto
PiperOrigin-RevId: 291249314
2020-01-23 14:48:39 -08:00
Kevin Krakauer 62357a0afb Merge branch 'master' into iptables-write-filter-proto 2020-01-21 13:16:25 -08:00
gVisor bot 989b611f5a Merge pull request #1541 from nybidari:iptables
PiperOrigin-RevId: 290273561
2020-01-17 08:38:25 -08:00
Nayana Bidari 98327a94cc Add test for iptables TCP rule
Added tests for tcp protocol with input and output rules including options sport and dport
Increased timeout in iptables_test as TCP tests were timing out with existing value.
2020-01-13 09:11:40 -08:00
Kevin Krakauer 89d11b4d96 Added a test that we don't pass yet 2020-01-09 13:41:52 -08:00
Kevin Krakauer be2754a4b9 Add iptables testing framework.
It would be preferrable to test iptables via syscall tests, but there are some
problems with that approach:

* We're limited to loopback-only, as syscall tests involve only a single
  container. Other link interfaces (e.g. fdbased) should be tested.
* We'd have to shell out to call iptables anyways, as the iptables syscall
  interface itself is too large and complex to work with alone.
* Running the Linux/native version of the syscall test will require root, which
  is a pain to configure, is inherently unsafe, and could leave host iptables
  misconfigured.

Using the go_test target allows there to be no new test runner.

PiperOrigin-RevId: 285274275
2019-12-12 14:42:11 -08:00