Commit Graph

537 Commits

Author SHA1 Message Date
Rob Murray
cf1695bef1 Add option --bridge-accept-fwmark
Packets with the given firewall mark are accepted by the bridge
driver's filter-FORWARD rules.

The value can either be an integer mark, or it can include a
mask in the format "<mark>/<mask>".

Signed-off-by: Rob Murray <rob.murray@docker.com>
2025-07-22 19:15:02 +01:00
Albin Kerouanton
f996384932 Merge pull request #50382 from akerouanton/split-nat-routed-portmappers
libnet/d/bridge: mv portmapper to libnet/pms/{nat,routed}
2025-07-22 15:45:52 +02:00
Albin Kerouanton
4e246efcd1 libnet/d/bridge: mv portmapper to libnet/pms/{nat,routed}
Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2025-07-22 12:37:01 +02:00
Albin Kerouanton
afb231d027 libnet/d/bridge: add a new Hairpin config flag
The bridge driver currently determines if hairpin mode is enabled by
checking whether the userland proxy is enabled, and if the binary path
is set to a non-empty string. It's used (amongst other things) by the
driver to decide whether 6-to-4 portmappings are supported, while it
normalizes port bindings.

As the userland proxy is going to be handled by the nat portmapper,
proxy-related params will be removed from the bridge driver, but the
port binding normalization will stay in the bridge driver.

So, introduce a new Hairpin config flag, and reimplement the original
logic in the daemon, when creating the bridge config.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2025-07-22 12:37:01 +02:00
Derek McGowan
afd6487b2e Create github.com/moby/moby/api module
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-07-21 09:30:05 -07:00
Derek McGowan
04f5276267 Move volume to daemon/volume
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-07-15 10:44:44 -07:00
Derek McGowan
7a720df61f Move libnetwork to daemon/libnetwork
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-07-14 09:25:23 -07:00
Derek McGowan
f05652867d Move opts to daemon/pkg/opts
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-07-14 09:25:05 -07:00
Sebastiaan van Stijn
3f8630cb84 internal/usergroup: move to daemon/internal
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-01 15:22:39 +02:00
Derek McGowan
4e8bd050bf Move libcontainerd/remote to daemon/internal/libcontainerd/remote
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-06-27 14:28:08 -07:00
Derek McGowan
5419eb1efc Move container to daemon/container
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-06-27 14:27:21 -07:00
Matthieu MOREL
381d9d0723 fix use-errors-new from revive
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2025-06-26 12:07:38 +00:00
Sebastiaan van Stijn
5318877858 daemon: remove // import comments
These comments were added to enforce using the correct import path for
our packages ("github.com/docker/docker", not "github.com/moby/moby").
However, when working in go module mode (not GOPATH / vendor), they have
no effect, so their impact is limited.

Remove these imports in preparation of migrating our code to become an
actual go module.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-05-30 15:59:13 +02:00
Matthieu MOREL
55da8ea276 daemon: replace uses of errdefs package
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
2025-05-28 05:38:39 +00:00
Matthieu MOREL
9e9b6cc42e fix(ST1019): Importing the same package multiple times
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-05-01 14:17:59 +02:00
Matthieu MOREL
b0711d5fe9 fix(QF1001): Apply De Morgan’s law
Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-05-01 14:16:44 +02:00
Sebastiaan van Stijn
76adb8f5c3 Merge pull request #49894 from thaJeztah/daemon_less_output_vars
daemon/*: reduce named (error)-returns, naked returns, and some minor linting-fixes
2025-05-01 10:19:50 +02:00
Rob Murray
44a3453d73 Add daemon option --allow-direct-routing
Per-network option com.docker.network.bridge.trusted-host-interfaces
accepts a list of interfaces that are allowed to route
directly to a container's published ports in a bridge
network with nat enabled.

This daemon level option disables direct access filtering,
enabling direct access to published ports on container
addresses in all bridge networks, via all host interfaces.

It overlaps with short-term env-var workaround:
  DOCKER_INSECURE_NO_IPTABLES_RAW=1
- it does not allow packets sent from outside the host to reach
  ports published only to 127.0.0.1
- it will outlive iptables (the workaround was initially intended
  for hosts that do not have kernel support for the "raw" iptables
  table).

Signed-off-by: Rob Murray <rob.murray@docker.com>
2025-04-30 20:59:28 +01:00
Sebastiaan van Stijn
19ccb75c62 daemon: remove/rename err-returns and remove naked returns
Prevent accidentally shadowing these errors, which are used in defers, and
remove naked returns.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-04-28 15:50:03 +02:00
Sebastiaan van Stijn
7c52c4d92e update go:build tags to go1.23 to align with vendor.mod
Go maintainers started to unconditionally update the minimum go version
for golang.org/x/ dependencies to go1.23, which means that we'll no longer
be able to support any version below that when updating those dependencies;

> all: upgrade go directive to at least 1.23.0 [generated]
>
> By now Go 1.24.0 has been released, and Go 1.22 is no longer supported
> per the Go Release Policy (https://go.dev/doc/devel/release#policy).
>
> For golang/go#69095.

This updates our minimum version to go1.23, as we won't be able to maintain
compatibility with older versions because of the above.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-04-17 15:43:19 +02:00
Sebastiaan van Stijn
a38ca9a548 daemon/initlayer: Setup: remove uses of idtools.Identity
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-04-16 09:58:24 +02:00
Albin Kerouanton
489cd7edfc api, daemon, libnet: add a 'trigger' baggage member
Add an OTel span processor copying the 'trigger' baggage member
propagated through contexts to all children spans. It's used to identify
what triggered a trace / span (API call, libnet init, etc...)

All code paths that call libnet's `NewNetwork` set this baggage member
with a unique value.

For instance, this can be used to distinguish bridge's `createNetwork`
spans triggered by daemon / libnet initialization from custom network
creation triggerd by an API call.

Two util functions are added to wrap `baggage.New` and
`baggage.NewMemberRaw` to make it easier to deal with baggage and
members by panicking on error. These should not be used with dynamic
values.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2025-04-09 08:45:33 +02:00
Albin Kerouanton
31ac5cb6d9 libnet: New: plumb context
Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2025-04-09 08:45:33 +02:00
Albin Kerouanton
78be7ebad7 libnet/d/bridge: trace createNetwork
Plumb context from the API down to libnet driver method `CreateNetwork`,
and add an OTel span to the bridge driver's `createNetwork` method.
Include a few attributes describing the network configuration (e.g.
IPv4/IPv6, ICC, internal and MTU).

A new util function, `RecordStatus`, is added to the `otelutil` package
to easily record any error, and update the span status accordingly.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2025-04-09 08:45:33 +02:00
Derek McGowan
3fc36bcac4 Update daemon to use moby sys/user identity mapping
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-04-04 08:24:09 -07:00
Paweł Gronowski
82ec984d10 daemon: Update to any from interface{}
Only files that have go build version enforcing tag

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2025-03-25 13:38:28 +01:00
Sebastiaan van Stijn
9c7112d118 daemon: configureMaxThreads: remove unused arg
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-02-07 02:24:31 +01:00
Sebastiaan van Stijn
433e9a50ce Merge pull request #48828 from vbatts/cgroups-rw
daemon/&container/: enable `--security-opt writable-cgroups=true|false` as an option
2025-01-23 20:41:08 +01:00
Rob Murray
bc130f367d bridge/macvlan endpoints always use a random MAC address
Now a gratuitous/unsolicted ARP is sent, there's no need to
use an IPv4-based MAC address to preserve arp-cache mappings
between an endpoint's IP addresses and its MAC addresses.

Because a random MAC address is used for the default bridge,
it no longer makes sense to derive container IPv6 addresses
from the MAC address. This "postIPv6" behaviour was needed
before IPv6 addresses could be configured, but not now. So,
IPv6 addresses will now be IPAM-allocated on the default
bridge network, just as they are for user-defined bridges.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2025-01-22 16:59:27 +00:00
Tianon Gravi
ce3e34816a Add support for bare writable-cgroups security-opt
This requires changes in the CLI to support fully, but matches our other boolean option handling (`no-new-privileges`).

Signed-off-by: Tianon Gravi <admwiggin@gmail.com>
2025-01-16 16:00:44 -08:00
Tianon Gravi
f8187c0214 Error on invalid requests for writable-cgroups
This makes `WritableCgroups` a pointer so we can error when it's specified in invalid configurations (both rootless and user namespaces).

Signed-off-by: Tianon Gravi <admwiggin@gmail.com>
2025-01-16 15:59:06 -08:00
Vincent Batts
e3cdd59a82 daemon/&container/: enable --security-opt writable-cgroups=true as an option
Fixes #42040
Closes #42043

Rather than making cgroups read-write by default, instead have a flag
for making it possible.

Since these security options are passed through the cli to daemon API,
no changes are needed to docker-cli.

Signed-off-by: Vincent Batts <vbatts@hashbangbash.com>
2025-01-16 12:58:17 -08:00
Sebastiaan van Stijn
033f97519c Merge pull request #49184 from thaJeztah/drop_kernel_4.10_check
daemon: remove kernel-version check for kernel < 4.0.0
2025-01-16 18:53:34 +01:00
Sebastiaan van Stijn
45fe68629b Merge pull request #49241 from vvoland/runtime-numcpu
pkg/sysinfo: Deprecate NumCPU
2025-01-09 15:15:41 +01:00
Paweł Gronowski
3db72b255d pkg/sysinfo: Deprecate NumCPU
Deprecate in favor of `runtime.NumCPU` as the behavior is the same now.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2025-01-09 13:39:49 +01:00
Sebastiaan van Stijn
6d24a21643 improve validation of cpu-shares, and migrate TestRunInvalidCPUShares
This test was testing errors produced by runc; both the "maximum" and
"minimum" values originate from the OCI runtime;
d48d9cfefc/libcontainer/cgroups/fs/cpu.go (L66-L83)

    docker run --cpu-shares=1 alpine
    docker: Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error setting cgroup config for procHooks process: the minimum allowed cpu-shares is 2: unknown.

Happy path for this setting is covered by TestRunWithCPUShares, and
various other tests, so we validate that the options take effect;
f5af46d4d5/integration-cli/docker_cli_run_unix_test.go (L494-L503)

This patch:

- removes the test and migrates it to an integration test
- removes the checks for errors that might be produced by runc
- updates our validation for invalid (negative) values to happen
  when creating the contaienr; the existing check that happened when
  creating the OCI spec is preserved, so that configs of existing containers
  are still validated.
- updates validateResources to return the correct error-type
- updated unit-test to validate

With this patch:

    make TEST_FILTER='TestCreateInvalidHostConfig' TEST_SKIP_INTEGRATION_CLI=1 test-integration
    --- PASS: TestCreateInvalidHostConfig (0.00s)
        --- PASS: TestCreateInvalidHostConfig/invalid_IpcMode (0.00s)
        --- PASS: TestCreateInvalidHostConfig/invalid_CPUShares (0.00s)
        --- PASS: TestCreateInvalidHostConfig/invalid_PidMode (0.00s)
        --- PASS: TestCreateInvalidHostConfig/invalid_PidMode_without_container_ID (0.00s)
        --- PASS: TestCreateInvalidHostConfig/invalid_Annotations (0.00s)
        --- PASS: TestCreateInvalidHostConfig/invalid_UTSMode (0.00s)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-09 13:24:02 +01:00
Sebastiaan van Stijn
eb36b182d3 Merge pull request #49229 from robmry/defgw_labels
Use bridge consts for "DefaultGatewayIPv[46]" aux-addr keys
2025-01-08 15:03:45 +01:00
Derek McGowan
3fa5e7e6a9 Update internal use of idtools to usergroup
Signed-off-by: Derek McGowan <derek@mcg.dev>
2025-01-07 11:18:46 -08:00
Rob Murray
a4ae38b010 Use bridge consts for "DefaultGatewayIPv[46]" aux-addr keys
Signed-off-by: Rob Murray <rob.murray@docker.com>
2025-01-07 15:51:04 +00:00
Sebastiaan van Stijn
d7f59cec05 daemon/config: add basic validation of exec-opt options
Validate if options are passed in the right format and if the given option
is supported on the current platform.

Before this patch, no validation would happen until the daemon was started,
and unknown options as well as incorrectly formatted options would be silently
ignored on Linux;

    dockerd --exec-opt =value-only --validate
    configuration OK

    dockerd --exec-opt unknown-opt=unknown-value --validate
    configuration OK

    dockerd --exec-opt unknown-opt=unknown-value --validate
    ...
    INFO[2024-11-28T12:07:44.255942174Z] Daemon has completed initialization
    INFO[2024-11-28T12:07:44.361412049Z] API listen on /var/run/docker.sock

With this patch, exec-opts are included in the validation before the daemon
is started/created, and errors are produced when trying to use an option
that's either unknown or not supported by the platform;

    dockerd --exec-opt =value-only --validate
    unable to configure the Docker daemon with file /etc/docker/daemon.json: merged configuration validation from file and command line flags failed: invalid exec-opt (=value-only): must be formatted 'opt=value'

    dockerd --exec-opt isolation=default --validate
    unable to configure the Docker daemon with file /etc/docker/daemon.json: merged configuration validation from file and command line flags failed: invalid exec-opt (isolation=default): 'isolation' option is only supported on windows

    dockerd --exec-opt unknown-opt=unknown-value --validate
    unable to configure the Docker daemon with file /etc/docker/daemon.json: merged configuration validation from file and command line flags failed: invalid exec-opt (unknown-opt=unknown-value): unknown option: 'unknown-opt'

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-03 13:05:35 +01:00
Sebastiaan van Stijn
ddd885a961 daemon: don't repeatedly call NumCPU if not needed
sysinfo.NumCPU returns the number of CPUs which are currently online,
which involves some syscalls and parsing on Windows.

Change the code to only retrieve this information when needed, and
memoize the result to prevent calling this function multiple times.

Ideally, we'd obtain this information from daemon.RawSysInfo(), but
that uses a sync.Once, which could return outdated information.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-01 18:24:22 +01:00
Sebastiaan van Stijn
0e10cd65f3 Merge pull request #49186 from thaJeztah/daemon_add_missing_gobuild
daemon: add missing "//go:build" directive
2025-01-01 16:00:34 +01:00
Sebastiaan van Stijn
c5575b5119 daemon: add missing "//go:build" directive
relates to 56eb47c622, which added
the "slices" package.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-01 13:42:32 +01:00
Sebastiaan van Stijn
8e9213a6b6 daemon: remove kernel-version check for kernel < 4.0.0
This check was in place for CentOS/RHEL 7, which use kernel 3.10. Now
that both reached EOL, and we stopped packaging for those distros, we
can remove this condition.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-01-01 12:42:57 +01:00
Sebastiaan van Stijn
f321120767 daemon: parseSecurityOpt: rename var that shadowed function
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-12-30 13:59:17 +01: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
56eb47c622 Ignore kernel-assigned LL addrs when selecting "bip6"
Commit facb2323 aligned the way the default bridge's IPv6 subnet
and gateway addresses are selected with IPv4.

Part of that involved looking at addresses already on the bridge,
along with daemon config options. But, for IPv6, the kernel will
assign a link-local address to the bridge.

Make sure that address is ignored when selecting "bip6" when it's
not explicitly specified.

This is made slightly complicated because we allow fixed-cidr-v6
to be a link-local subnet (either the standard "fe80::/64", or
any other non-overlapping LL subnet in "fe80::/10").

Following this change, if fixed-cidr-v6 is (or is included by)
"fe80::/64", the bridge's kernel-assigned LL address may be used
as the network's gateway address - even though it may also get an
IPAM-assigned LL address.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-12-04 18:19:41 +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
Sebastiaan van Stijn
68a98a7263 daemon: getCD: remove use of parsers.ParseKeyValueOpt
We were discarding the error returned by it, and its functionality
is very minimal, so inline the equivalent.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-28 13:18:53 +01:00
Sebastiaan van Stijn
da5e86a82b daemon: gofumpt code
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-28 10:03:46 +01:00