Commit Graph

3639 Commits

Author SHA1 Message Date
Sebastiaan van Stijn
4e3202affb Merge pull request #49125 from akerouanton/move-iptRule-to-ipt-pkg
libnet/d/bridge: move iptRule to iptables pkg
2024-12-19 13:50:42 +01:00
Sebastiaan van Stijn
4f5ec9994c pkg/reexec: deprecate and migrate to github.com/moby/sys/reexec
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-12-19 10:12:58 +01:00
Sebastiaan van Stijn
93101be4b7 Merge pull request #49128 from robmry/v6only/enable_ext_dns
Enable external DNS if a network has an IPv6 gateway
2024-12-18 16:24:06 +01:00
Rob Murray
b0be1f3af8 Enable external DNS if a network has an IPv6 gateway
Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-12-18 12:22:45 +00:00
Albin Kerouanton
ec8a5b0f4c libnet/d/bridge: move iptRule to iptables pkg
This moves the iptRule struct from the bridge package to the iptables
pkg.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-12-18 11:01:27 +01:00
Albin Kerouanton
1b823fb54e libnet: don't put external DNS answers in OTel spans
When containers make DNS resolution, and the domain name they're trying
to resolve doesn't match any running container, the DNS query is
forwarded to upstream servers. In that case, when we receive a response,
we put it in an OTel spans.

This was useful to debug DNS resolution on GHA, but it leads to
excessive memory usage when DNS resolution happen in a tight loop. So,
keep the OTel event signaling that a response was received, but drop the
answer from the OTel span.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
(cherry picked from commit 173a9f2091)
Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-12-18 09:24:44 +01:00
Sebastiaan van Stijn
fab60e2c2c Merge pull request #49121 from thaJeztah/iptables_rm_deprecated
libnetwork/iptables: remove deprecated IPV, Iptables, IP6Tables, Passthrough()
2024-12-18 00:00:55 +01:00
Albin Kerouanton
0d53725a7f Merge pull request #49107 from akerouanton/ipt-split-ProgramChain
libnet/iptables: split ProgramChain and move to bridge driver
2024-12-17 19:15:52 +01:00
Sebastiaan van Stijn
b6594353f8 libnetwork/iptables: remove deprecated Passthrough()
This was deprecated in d688389f4a, and has
no known external users. The deprecation was included in the 27.4.1
release, so we can remove it from master.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-12-17 18:49:10 +01:00
Sebastiaan van Stijn
d34d092b42 libnetwork/iptables: remove deprecated IPV, Iptables, IP6Tables
This was deprecated in 27deff4da1, and has
no known external users. The deprecation was included in the 27.4.1
release, so we can remove it from master.

This patch removes the deprecated `IPV`, and `Iptables` and `IP6Tables`
consts.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-12-17 18:49:09 +01:00
Rob Murray
f237ba0ea7 Merge pull request #48641 from robmry/iptables-combine-outgoing-and-icc-rules
Combine Outgoing and ICC=true iptables rules
2024-12-17 14:44:11 +00:00
Sebastiaan van Stijn
8d3ecc28c1 Merge pull request #49115 from thaJeztah/libnetwork_deprecate_Passthrough
libnetwork/iptables: deprecate Passthrough
2024-12-17 12:48:53 +01:00
Albin Kerouanton
820dea0d2b libnet/d/bridge: hardcode chain names
Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-12-17 12:31:35 +01:00
Albin Kerouanton
bd30a51ea7 libnet/iptables: split ProgramChain and move to bridge driver
The `ProgramChain` method was called exclusively by the bridge driver
to insert totally unrelated ipt rules in two different table-chains.

Break down this method into two functions, and move them into the bridge
pkg.

The new function `addNATJumpRules` inserts rules that aren't related to
any specific network, and depends solely on the driver config. Call it
during driver configuration instead of during network setup.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-12-17 12:31:34 +01:00
Rob Murray
df3c78d061 Combine outgoing and ICC iptables rules
Rather than:

  ACCEPT -i <bridge> -o <bridge>   // icc=true
  ACCEPT -i <bridge> ! -o <bridge> // outgoing

Do:

  ACCEPT -i <bridge>  // icc=true and outgoing

For ICC=false, continue to do:

  DROP -i <bridge> -o <bridge>
  ACCEPT -i <bridge> ! -o <bridge>

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-12-17 10:38:09 +00:00
Rob Murray
0f259dd76d Rename setupIPTablesInternal -> setupNonInternalNetworkRules
setupIPTablesInternal is/was called from setupIPTables to set
up some rules for a network ... "internal" behaviour of the
outer function.

Then commit 7b64b1c2 added support for "--internal" bridge
networks, calling setupInternalNetworkRules from setupIPTables
instead of setupIPTablesInternal.

So, setupIPTablesInternal is the function that deals with
everything except "--internal" networks ... rename it.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-12-17 10:38:09 +00:00
Rob Murray
556b8eed16 Tidy setupIPTablesInternal
- Move variable declarations closer to where they're used.
- Put comments in the blocks they apply to.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-12-17 10:38:09 +00:00
Rob Murray
0ef2b24c80 Make libnetwork responsible for DOCKER-USER setup/reload
It no longer needs to be moved to the top of the filter-FORWARD
chain after creating a new bridge network. But, it does need to
be rearranged after setting up Swarm ingress.

Similarly, the jump to DOCKER-INGRESS no longer needs to be
shuffled back to the top of the FORWARD chain after adding a
new network.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-12-17 09:14:26 +00:00
Rob Murray
29e20fc904 Add static filter-FORWARD rules during bridge driver init
Rules no longer need to be rearranged when creating a network.

Per-network rules are always appended to the FORWARD chain so,
after adding them, there's no need to delete the per-driver
rules to re-insert them at the top of the chain.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-12-17 09:14:25 +00:00
Rob Murray
5ccc699513 Use golden testdata in TestUserChain
Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-12-17 09:14:25 +00:00
Sebastiaan van Stijn
d688389f4a libnetwork/iptables: deprecate Passthrough
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-12-16 23:23:11 +01:00
Sebastiaan van Stijn
01a55860c6 libnetwork/drivers/bridge: setupIPChains: fix defer checking wrong err
The output variable was renamed in 0503cf2510,
but that commit failed to change this defer, which was now checking the
wrong error.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-12-16 16:46:31 +01:00
Paweł Gronowski
daacd6c591 Merge pull request #49099 from akerouanton/libnet-netns-path-gc
libnet/osl: drop netns path GC
2024-12-16 14:11:19 +00:00
Sebastiaan van Stijn
fca4d24c53 Merge pull request #49096 from akerouanton/ipt-drop-bestEffortLock
libnet/iptables: remove mutex-based serialization
2024-12-16 13:03:48 +01:00
Albin Kerouanton
f053beb34c libnet/osl: drop netns path GC
Commit 3ec19ff62b introduced a GC goroutine to delete files where netns
were mounted. It was primarly added to work around a race in kernel
3.18-4.0.1. Since no distros we support are using such old kernels,
there's no need to keep this code around.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-12-16 11:40:18 +01:00
Albin Kerouanton
27deff4da1 libnet/iptables: deprecate type IPV
The iptables package has two different types to specify the IP version:
IPVersion, used by iptables code, and IPV, used by firewalld code.
Both are representing the ip version as a string.

For iptables, the case doesn't matter because the string is never used
as-is. However, for firewalld the case matters.

Make the IPV type an alias of IPVersion, and deprecate it. Also change
the case used in IPVersion strings to make IPV consts aliases of
IPVersion consts.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-12-16 09:40:21 +01:00
Albin Kerouanton
c8f19e5e4c libnet/iptables: remove mutex-based serialization
All distros we support now ship a version of iptables that support the
`--wait` flag.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-12-16 09:37:05 +01:00
Albin Kerouanton
678ef1a267 libnet/d/bridge: unconditionally error out if LinkSetMTU fails
Since 89470a7 we ignore errors returned by `LinkSetMTU` when the MTU is
greater than 1500 but lower than 65535 to let CentOS/RHEL 7 users set
an MTU in that range (despite their kernel rejecting that value).

We dropped support for those distros, so we can now remove this code
and unconditionally error out if `LinkSetMTU` returns an error.

Commit 89470a7 introduced two unit tests - these are kept, and both now
have a proper GoDoc describing what they're testing.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-12-14 11:22:40 +01:00
Sebastiaan van Stijn
68dbb8b385 Merge pull request #49022 from robmry/ignore_kernel_ll_for_fcidrv6
Ignore kernel-assigned LL addrs when selecting "bip6"
2024-12-06 21:31:29 +01:00
Rob Murray
f2e1f52a04 Try to load kernel module ip6_tables, when necessary.
Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-12-06 10:27:24 +00:00
Rob Murray
4740820716 Use ioctl to try to trigger kernel module loads
An ioctl() call to get the "interface index" for a kernel module triggers
the kernel to try to load the module, if the process is running with
CAP_SYS_MODULE. This tends to be more reliable than "modprobe" for
docker-in-docker.

If the ioctl() method fails, fall back to trying "modprobe".

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-12-06 10:27:24 +00:00
Rob Murray
8fee8a759f Remove test env var DOCKER_TEST_CREATE_DEFAULT_BRIDGE
Env var DOCKER_TEST_CREATE_DEFAULT_BRIDGE could be set to
override the name of the default bridge - without the bridge
being user-managed (unlike the '--bridge' daemon option).

It was needed by tests looking at docker0 behaviour, using
their own instance of the daemon, without breaking the
docker0 instance belonging to CI's daemon.

Now, those tests run in their own netns using the name docker0.

So, remove the unused env var.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-12-04 12:02:03 +00:00
Rob Murray
0aba67203a Implement gateway mode "nat-unprotected"
Same as "nat" mode, there's masquerading and port mapping from the
host - but no port/protocol filtering for direct access to the
container's address from remote hosts.

This is the old default behaviour for IPv4 when the filter-FORWARD
chain's default policy was "ACCEPT" (the daemon would only set it
to "DROP" when it set sysctl "ip_forward" itself, but it didn't set
up DROP rules for unpublished ports).

Now, port filtering doesn't depend on the filter-FORWARD policy. So,
this mode is added as a way to restore the old/surprising/insecure
behaviour for anyone who's depending on it. Networks will need to
be re-created with this new gateway mode.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-11-28 19:33:37 +00:00
Rob Murray
07dff11a7e Wrap errors rather than using err.Error()
Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-11-28 19:03:10 +00:00
Sebastiaan van Stijn
003e35fea5 libnetwork/ipams/null: gofumpt code
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-28 10:05:40 +01:00
Sebastiaan van Stijn
a8e5a19706 libnetwork/drivers/bridge: gofumpt code
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-28 10:05:07 +01:00
Shreenidhi Shedi
264c15bfc4 Fix br_netfilter module loading logic
Checking for `/proc/sys/net/bridge` directory alone is not enough to
decide if bridge, br_netfilter module to be loaded.
Check for specific file for br_netfilter module and then
do modprobe if the file is not found under `/proc/sys/net/bridge`

Loading br_netfilter implicitly loads bridge module.

fixes: #48948

Signed-off-by: Shreenidhi Shedi <shreenidhi.shedi@broadcom.com>
2024-11-27 18:20:33 +05:30
Sebastiaan van Stijn
54fff36d95 Merge pull request #48906 from robmry/network_generic_opts
Disallow "network generic data" with type options.Generic
2024-11-25 15:41:00 +01:00
Aleksa Sarai
1b470d15d8 tests: migrate away from assert.Assert(v == nil)
If a values is non-nil when we don't expect it, it would be quite
helpful to get an error message explaining what happened.

  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r "assert.Assert(t, a == nil) -> assert.Assert(t, is.Nil(a))"
  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r "assert.Check(t, a == nil) -> assert.Check(t, is.Nil(a))"

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2024-11-22 23:59:20 +11:00
Rob Murray
b656cffe4c Disallow "network generic data" with type options.Generic
Field 'generic' in 'libnetwork.Network' is used to store driver options,
it has type 'options.Generic', which is 'map[string]any'.

In that map, there may be a key 'netlabel.GenericData' holding options
known as "network generic options", used for options like:
  -o com.docker.network.bridge.name=br-foo

The value type for key 'netlabel.GenericData' is always 'map[string]string'
when created via an API request. But, some unit tests use type
'options.Generic'.

That works because the bridge, ipvlan and macvlan drivers look for type
'options.Generic' as well as 'map[string]string'. If they find
'options.Generic', Go reflection is used to map keys to fields of the
config struct with the expectation that the value has the same type as
that field. But, that's only used in unit tests (so the tests aren't
testing the same code path as the API would use). The 'options.Generic'
form of the bridge name option is:
  "BridgeName": "br-foo"
(Because "BridgeName" is the name of the field in the bridge driver's
network config struct.)

The libnetwork code expects "network generic options" to have type
'map[string]string', and makes no provision for 'options.Generic'. So,
for example, function Network.DriverOptions will panic if called when
'Network.generic[netlabel.GenericData]' has type 'options.Generic'.

The type of 'Network.generic[netlabel.GenericData]' can't be statically
checked, because it's just a field in a 'map[string]any'.

So - remove the driver code that converts "network generic options"
from type 'options.Generic', as it's only used in tests and just makes
things more confusing.

This should reduce the chances of things appearing to work when the
type is wrong, and converting unit tests to use 'map[string]string'
means they're testing the right thing.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-11-19 20:13:39 +00:00
Rob Murray
0546d9084f Routed networks accept traffic from anywhere.
Create ipsets containing the subnet of each non-internal bridge network.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-11-19 15:28:42 +00:00
Rob Murray
10338053f0 Don't add default-RETURN rules to DOCKER-ISOLATION chains
The default for a user-defined chain is RETURN anyway.

This opens up the possibilty of sorting rules into two groups
by using insert or append, without having to deal with appending
after the unconditional RETURN.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-11-19 15:28:42 +00:00
Rob Murray
939bc14616 Tidy bridgeNetwork.isolateNetwork
IPv4 before IPv6, with consistent error paths.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-11-19 15:28:42 +00:00
Rob Murray
255fff4acd Propagate error from INC rule setup
Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-11-19 15:28:42 +00:00
Rob Murray
d3b7d84b23 Simplify setINC()
After an error, there's no need for it to roll back rules
it's created, the caller already does that.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-11-19 15:28:41 +00:00
Rob Murray
1a607cf257 Rename gwMode.natDisabled() to gwMode.routed()
Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-11-19 15:28:41 +00:00
Sebastiaan van Stijn
b0431a07fd Merge pull request #48884 from thaJeztah/more_build_tags
fix missing go:build tags
2024-11-15 15:00:08 +01:00
Rob Murray
4e1b178fc3 Merge pull request #48857 from robmry/fix_hosts_update_for_net_disconnect
Fix /etc/hosts update for net disconnect
2024-11-15 12:17:41 +00:00
Sebastiaan van Stijn
451fee91c5 libnetwork: add missing go:build tag
This was introduced in 18327745c00d4d2e98e5ea7241c1a1ef43b0401b;

    make BIND_DIR=. shell
    make -C ./internal/gocompat/
    GO111MODULE=on go test -v
    # github.com/docker/docker/libnetwork
    ../../libnetwork/sandbox.go:588:6: implicit function instantiation requires go1.18 or later (-lang was set to go1.16; check go.mod)
    FAIL	gocompat [build failed]

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-15 12:53:42 +01:00
Rob Murray
354dfdb928 Delete /etc/hosts entries on network disconnect
Delete the entries that were added, rather than looking at the service
map (DNS config) and trying to delete entries without accounting for
the container's --hostname.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-11-15 10:58:30 +00:00