Commit Graph

554 Commits

Author SHA1 Message Date
Sebastiaan van Stijn
f052dbb54b Merge pull request #48953 from thaJeztah/carry_buildkit_init_timeout
Remove buildkit init timeout
2024-11-27 10:23:24 +01:00
Brian Goff
b7f43c3729 Remove buildkit init timeout
Buildkit *can* take a long time to start, we don't want the daemon to fail
to startup because buildkit took too long.

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2024-11-26 00:37:20 +00:00
Rob Murray
0b5b1db1c1 Use default ULA prefix if fixed-cidr-v6 is not specified
Use the same logic to generate IPAMConf for IPv6 as for IPv4.

- When no fixed-cidr-v6 is specified, rather than error out, use
  the default address pools (as for an IPv4 default bridge with no
  fixed-cidr, and as for user-defined networks).
- Add daemon option --bip6, similar to --bip.
  - Necessary because it's the only way to override an old address
    on docker0 (daemon-managed default bridge), as illustrated by
    test cases.
- For a user-managed default bridge (--bridge), use IPv6 addresses
  on the user's bridge to determine the pool, sub-pool and gateway.
  Following the same rules as IPv4.
- Don't set up IPv6 IPAMConf if IPv6 is not enabled.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-11-25 18:29:25 +00: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
Paweł Gronowski
e1dd1c5d1d Merge pull request #47955 from CharityKathure/windows-containerd-as-managed-process
Windows: Run containerd as managed process
2024-11-15 10:20:18 +00:00
Rob Murray
3cadadb4eb Add daemon option --ip-forward-no-drop
The daemon no longer depends on the iptables/ip6tables filter-FORWARD
chain's policy being DROP in order to implement its port filtering
rules.

However, if the daemon enables IP forwarding in the host's system
config, by default it will set the policy to DROP to avoid potential
security issues for other applications/networks.

If docker does need to enable IP forwarding, but other applications
on the host require filter-FORWARD's policies to be ACCEPT, this
option can be used to tell the daemon to leave the policy unchanged.
(Equivalent to enabling IP forwarding before starting the daemon,
but without needing to do that.)

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-11-11 12:12:57 +00:00
Charity Kathure
84965c0752 Windows: Run containerd as managed process
Signed-off-by: Charity Kathure <ckathure@microsoft.com>
Co-authored-by: Olli Janatuinen <olli.janatuinen@gmail.com>
2024-11-06 21:04:31 +03:00
Paweł Gronowski
cca7085464 cmd/dockerd: Add workaround for OTEL meter leak
OTEL meter implementation has a memory leak issue which causes each
meter counter invocation to create a new instrument when the meter
provider is not set.

Also add a test, which will fail once a fixed OTEL is vendored.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-10-18 14:41:54 +02:00
Albin Kerouanton
6c6174b371 cmd/docker-proxy: UDP: reply to clients with original daddr
When a UDP server is running on a multihomed server, as is the case with
pretty much _all_ Docker hosts (eg. eth0 + docker0), the kernel has to
choose which source address is used when replying to a UDP client. But
that process is based on heuristics and is fallible.

If the address picked doesn't match the original destination address
used by the client, it'll drop the datagram and return an ICMP Port
Unreachable.

To prevent that, we need to:

- `setsockopt(IP_PKTINFO)` on proxy's sockets.
- Extract the original destination address from an ancillary message
  every time a new 'UDP connection' is 'established' (ie. every time we
  insert a new entry into the UDP conntrack table).
- And finally, pass a control message containing the desired source
  address to the kernel, every time we send a response back to the
  client.

Also, update the inline comment on read errors in `(*UDPProxy).Run()`.
This comment was misleadingly referencing ECONNREFUSED - Linux's UDP
implementation never returns this error (see [1]). Instead, state why
`net.ErrClosed` is perfectly fine and doesn't need to be logged
(although, docker-proxy currently logs to nowhere).

[1]: https://github.com/search?q=repo%3Atorvalds%2Flinux+ECONNREFUSED+path%3A%2F%5Enet%5C%2F%28ipv4%7Cipv6%29%5C%2F%28udp%7Ctcp%29%2F&type=code

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-10-15 12:42:15 +02:00
Sebastiaan van Stijn
f1506992e3 Merge pull request #48518 from thaJeztah/windows_daemon_nofatal
cmd/dockerd: windows: don't use Fatal log to prevent early exit
2024-10-04 15:03:48 +02:00
Sebastiaan van Stijn
92da1065f6 Merge pull request #48519 from thaJeztah/cleanup_daemon_start_step2
cmd/dockerd: runDaemon: extract platform-agnostic code
2024-09-17 19:11:00 +02:00
Sebastiaan van Stijn
8c598b1005 cmd/dockerd: runDaemon: extract platform-agnostic code
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-09-17 16:21:31 +02:00
Sebastiaan van Stijn
5228850225 cmd/dockerd: windows: don't use Fatal log to prevent early exit
cmd/dockerd: notifyShutdown: don't use Fatal log to prevent early exit
------------------------------------------------------------------------

Commit 40868e263d added this log for situations
where the daemon failed to start, and where no event-log was created
to discover the failure.

However, it used a `Fatal` log which, when using logrus, not only logs
a message, but also calls the [logger's Exit function][1], which defaults
[to `os.Exit`][2].

The error passed to the `notifyShutdown` function can be the result of
different steps in the service's lifecycle; `cli.start()` starts a long-
lived process, and the error returned can be either because it failed
to start the service, or an error produced while shutting down the service.

We should reduce ambiguity here (which could be for `cli.Start()` to return
whether the service was started in the first place). Regardless, we want
code following the log-entry to be executed, to make sure that codepaths
following the `notifyShutdown` (which could be (defer) statements or cleanup
steps) are executed.

This patch changes the log to an `Error`, which is non-fatal, and should
make sure that at least the `service.stopped` is executed to signal the
service no longer running. The logging is also moved out of the
`notifyShutdown`.

Disclaimer: this is with the assumption that calling `service.stopped` is
always acceptable, even if the service is not running, or in other states.

cmd/dockerd: preNotifyReady: return error instead of logging and exit
------------------------------------------------------------------------

Commit 57aef3b490 added support for running
the daemon as a Windows service. As part of this, it introduced a log
for situations where the service failed to start. However, it used a
`Fatal` log for this purpose which, when using logrus, not only logs
a message, but also calls the [logger's Exit function][1], which defaults
[to `os.Exit`][2].

A result of this is that the daemon does an unclean shutdown, causing
other code (which could be (defer) statements or cleanup steps) not to
be executed.

This patch updates the `preNotifyReady` to return the error instead of
logging and exiting. `preNotifyReady` is executed as part of `cli.start()`,
which has an error-return, and the error that is returned, is already
logged by `runDaemon` (so logging it as part of `preNotifyReady` would
result in the error being logged twice).

[1]: 5098132d84/vendor/github.com/sirupsen/logrus/entry.go (L336-L339)
[2]: 5098132d84/vendor/github.com/sirupsen/logrus/logger.go (L342-L348)

- relates to https://github.com/moby/moby/pull/22340

cmd/dockerd: preNotifyReady: return error instead of logging and exit

Commit 57aef3b490 added support for running
the daemon as a Windows service. As part of this, it introduced a log
for situations where the service failed to start. However, it used a
`Fatal` log for this purpose which, when using logrus, not only logs
a message, but also calls the [logger's Exit function][1], which defaults
[to `os.Exit`][2].

A result of this is that the daemon does an unclean shutdown, causing
other code (which could be (defer) statements or cleanup steps) not to
be executed.

This patch changes the `preNotifyReady` to

[1]: 5098132d84/vendor/github.com/sirupsen/logrus/entry.go (L336-L339)
[2]: 5098132d84/vendor/github.com/sirupsen/logrus/logger.go (L342-L348)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-09-17 16:08:26 +02:00
Sebastiaan van Stijn
0aebbd0ba9 cmd/dockerd: use golang.org/x/sys/windows/service param-change consts
- The `ParamChange` const was introduced in [golang/sys@e62c3de][1]
- The `AcceptParamChange` const was introduced in [golang/sys@f7928cf][2]

Both are part of golang.org/x/sys v0.1.0 and higher.

[1]: e62c3de784
[2]: f7928cfef4

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-09-17 16:02:53 +02:00
Sebastiaan van Stijn
b186261b84 cmd/dockerd: un-export DaemonCli, NewDaemonCli
They're only used within this package, and are not expected to be used
externally. Some exported functions also take non-exported types as
argument, so would not be usable outside of this package either way.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-09-17 12:44:25 +02:00
Sebastiaan van Stijn
6f83fda310 cmd/dockerd: construct context in main
Construct the context we use in the main function, and set it as context
for the root-command.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-09-17 12:44:25 +02:00
Sebastiaan van Stijn
52694ebe16 cmd/dockerd: windows: move setting PIDFile location to setPlatformOptions
Unlike Linux, which uses fixed locations as default, the Windows daemon uses
paths relative to the data-root as defaults for storing both the PIDFile, and
the daemon configuration file (daemon.json).

The data-root is configurable both through command-line options (`--data-root`),
and through the daemon configuration file (daemon.json). This patch moves Windows-
specific config handling to config-related code.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-09-17 12:44:25 +02:00
Sebastiaan van Stijn
44a3bba2a2 cmd/dockerd: apply options when creating daemonCLI, not when starting
Validate and apply options when creating the CLI, so that starting the
CLI does not have to mutate the config, and to have a clearer separation
between "creating", "validating", and starting the daemon.

This also allows skipping the service-registration code in situations
where we only want to validate the config.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-09-17 12:44:24 +02:00
Sebastiaan van Stijn
5c1b037ff5 cmd/dockerd: rename loadCLIPlatformConfig to setPlatformOptions
Make it more explicit that this function is mutating the passed
configuration.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-09-17 12:44:24 +02:00
Sebastiaan van Stijn
1388d959bc cmd/dockerd: set default configfile location as part of newDaemonOptions
Make creating the options slightly more atomic, and set the defaults when
instancing the options.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-09-17 12:44:24 +02:00
Sebastiaan van Stijn
19a8e7ff7e cmd/dockerd: getDefaultDaemonConfigFile: add GoDoc for Windows implementation
Document why we cannot return a default on Windows.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-09-17 12:44:24 +02:00
Sebastiaan van Stijn
388c0a8cda cmd/dockerd: remove unused error-returns
getDefaultDaemonConfigDir would never return an error and because of that,
neither would getDefaultDaemonConfigFile, so we can remove these error returns.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-09-17 12:44:24 +02:00
Sebastiaan van Stijn
1624ae197e cmd/dockerd: move Windows code for data-root
This patch moves Windows-specific config for the config-file location to config-
related code to help discoverability.

Unlike Linux, which uses fixed locations as default, the Windows daemon uses
paths relative to the data-root as defaults for storing both the PIDFile, and
the daemon configuration file (daemon.json).

For the PIDfile, additional changes will be needed, as using a PIDfile depends
on whether the daemon is run as a service or not.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-09-17 12:44:21 +02:00
Derek McGowan
f13c08246d Add feature to daemon flags
Signed-off-by: Derek McGowan <derek@mcg.dev>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-09-12 15:35:15 +02:00
Nathan Baulch
59eba0ae13 Fix typos
Signed-off-by: Nathan Baulch <nathan.baulch@gmail.com>
2024-09-06 21:53:09 +10:00
Sebastiaan van Stijn
06bfe8bab3 cmd/dockerd: fix non-constant format string in call (govet)
cmd/dockerd/required.go:17:24: printf: non-constant format string in call to github.com/docker/docker/vendor/github.com/pkg/errors.Errorf (govet)
            return errors.Errorf("\n" + strings.TrimRight(cmd.UsageString(), "\n"))
                                 ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-08-27 10:23:39 +02:00
Rob Murray
cdea750966 Tell RootlessKit about port mappings when --userland-proxy=false
The daemon was modified to tell RootlessKit about host port
mappings directly, rather than by running rootlesskit-docker-proxy
to make those updates.

DNAT rules created in rootless mode referred to the host IP address,
rather than the address seen as host address in the rootless network
namespace.

With these changes, port mappings work in rootless mode when
--userland-proxy=false - so, don't gate the RootlessKit API calls
on starting docker-proxy.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-08-05 14:04:05 +01:00
Cory Snider
7a8663c9ea cmd/docker-proxy: drop FrontendAddr() method
It was only used in tests.

Signed-off-by: Cory Snider <csnider@mirantis.com>
2024-08-05 14:04:05 +01:00
Cory Snider
88fb0c9fec cmd/docker-proxy: drop unused BackendAddr() method
Signed-off-by: Cory Snider <csnider@mirantis.com>
2024-08-05 14:04:05 +01:00
Rob Murray
ba2f3c0a98 cmd/docker-proxy: pass open listener to proxy impl
In preparation for the daemon passing a listen fd, add command line
option -use-listen-fd to indicate that the fd is present (as fd 4).

If the new flag isn't given, open the listener as normal.

Refactor the TCP and UDP proxies to be constructed with an existing
TCPListener or UDPConn, respectively. Lift the responsibilty of opening
the listener to the entrypoint. Per the Single Responsibility Principle,
this structure affords changing how the listener is created without
having to touch the proxy implementations.

Co-authored-by: Cory Snider <csnider@mirantis.com>
Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-08-05 14:04:04 +01:00
Rob Murray
e0c7a839a8 Only build docker-proxy for Linux
Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-08-05 14:04:04 +01:00
Sebastiaan van Stijn
ae96ce866f remove support for setting CORS headers (deprecated)
Configuring CORS headers was deprecated in docker 27.0 through
7ea9acc97f, which disabled them by default
with a temporary `DOCKERD_DEPRECATED_CORS_HEADER` env-var to allow using
the option.

This patch removes the feature altogether; the flag is kept for one more
release to allow printing a more informative error, but can be removed in
the next release.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-07-22 21:29:44 +02:00
Paweł Gronowski
53bc396ef4 c8d/build: Log image tag event when image was built with Buildkit
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-07-02 12:34:53 +02:00
Paweł Gronowski
1506bbcfe8 builder-next: Add ImageNamedByBuildkit callback
When image is built with buildkit with containerd integration the image
service has no way of knowing that the image was tagged because buildkit
creates the image directly in containerd image store.

Add a callback that is called by the exporter wrapper.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-07-02 12:34:52 +02:00
Lei Jitang
fa150ca759 cleanup: Remove unnecessary return value
The return error of `installCommonConfigFlags` is unnecessary since
it only return nil.

Signed-off-by: Lei Jitang <leijitang@outlook.com>
2024-06-30 17:34:34 +08:00
Sebastiaan van Stijn
a9ab04603e cmd/dockerd: initMiddlewares: use containerd/logs
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-06-20 23:06:40 +02:00
Paweł Gronowski
7b8f4922a5 daemon: Emit Image Create event when image is built
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-06-17 14:05:12 +02:00
Gabriel Tomitsuka
44f19518f9 move the cli/debug package to cmd/dockerd/debug
Signed-off-by: Gabriel Tomitsuka <gabriel@tomitsuka.com>
2024-06-13 21:53:44 +00:00
Jonathan A. Sternberg
fa03db1b82 builder: Update detect usage for new detect API from buildkit
Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-06-06 11:20:17 +02:00
Sebastiaan van Stijn
ce0ccc09ff Merge pull request #45313 from akerouanton/deprecate-cors-headers
Deprecate dockerd api-cors-header parameter
2024-05-28 23:42:53 +02:00
Rob Murray
07ccaf028d Enable 'ip6tables' by default, don't require 'experimental'.
Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-05-10 09:21:21 +01:00
Albin Kerouanton
7ea9acc97f cmd/dockerd: deprecate api-cors-header
CORS headers were originally added by 6d5bdff.

These headers could be set without any Authz plugin enabled
beforehand, making this feature quite dangerous.

This commit marks the daemon flag `api-cors-header` as deprecated
and requires the env var `DOCKERD_DEPRECATED_CORS_HEADER` to be
set. When enabled, the daemon will write a deprecation warning to
the logs and the endpoint `GET /info` will return the same
deprecation warning.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-05-08 12:12:09 +02:00
Paweł Gronowski
bcb4794eea Be more explicit about non-TLS TCP access deprecation
Turn warnings into a deprecation notice and highlight that it will
prevent daemon startup in future releases.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-03-13 14:22:10 +01:00
Sebastiaan van Stijn
4adc40ac40 fix duplicate words (dupwords)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-03-07 10:57:03 +01:00
Paweł Gronowski
2d31532a00 otel: Default metrics protocol to http/protobuf
Buildkit added support for exporting metrics in:
7de2e4fb32

Explicitly set the protocol for exporting metrics like we do for the
traces. We need that because Buildkit defaults to grpc.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-02-27 11:27:12 +01:00
Paweł Gronowski
bc6d88c09a cmd/dockerd: Fix overriding OTEL resource
e358792815
changed that field to a function and added an `OverrideResource`
function that allows to override it.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-02-27 11:26:14 +01:00
Sebastiaan van Stijn
14503ccebd api/server/middleware: NewVersionMiddleware: add validation
Make sure the middleware cannot be initialized with out of range versions.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-02-06 18:44:45 +01:00
Sebastiaan van Stijn
ee6cbc540e Merge pull request #47188 from thaJeztah/cleanup_newRouterOptions
cmd/dockerd: newRouterOptions: pass cluster as argument, and slight cleanup
2024-01-26 16:49:19 +01:00
Sebastiaan van Stijn
e8346c53d9 Merge pull request #46786 from rumpl/c8d-userns-namespace
c8d: Use a specific containerd namespace when userns are remapped
2024-01-24 20:36:40 +01:00
Djordje Lukic
3a617e5463 c8d: Use a specific containerd namespace when userns are remapped
We need to isolate the images that we are remapping to a userns, we
can't mix them with "normal" images. In the graph driver case this means
we create a new root directory where we store the images and everything
else, in the containerd case we can use a new namespace.

Signed-off-by: Djordje Lukic <djordje.lukic@docker.com>
2024-01-24 15:46:16 +01:00