Commit Graph

54274 Commits

Author SHA1 Message Date
Sebastiaan van Stijn
77bf85647c contrib: add docker_client SELinux policy module to access socket in container
When running the docker daemon with `--selinux-enabled`, access to the docker
socket is prevented by SELinux. To access the socket, the container must be
started with `--privileged`, with SELinux disabled (`--security-opt label=disable`),
or with (e.g.) `--security-opt label=type:container_runtime_t`, which gives
it access to files restricted to the runtime ( `dockerd` daemon) itself.

While having access to the docker socket grants full `root` permissions on
the host (e.g. through starting a privileged container using the socket),
it may be preferable to restrict the container to just the socket.

This patch adds a `docker_client.process` SELinux CIL policy module that
defines a container domain (process type). It inherits the base container
template and grants the permissions needed to use the docker socket.

Without this (and the daemon running with `--selinux-enabled`);

    docker run -it --rm -v /var/run/docker.sock:/var/run/docker.sock docker:cli -H unix:///var/run/docker.sock version
    Client:
     Version:           28.4.0
     API version:       1.51
     Go version:        go1.24.7
     Git commit:        d8eb465
     Built:             Wed Sep  3 20:56:28 2025
     OS/Arch:           linux/amd64
     Context:           default
    permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.51/version": dial unix /var/run/docker.sock: connect: permission denied

With this:

    semodule -i /usr/share/udica/templates/base_container.cil
    semodule -i ./contrib/selinux/docker_client.cil

    docker run -it --rm -v /var/run/docker.sock:/var/run/docker.sock --security-opt label=type:docker_client.process docker:cli -H unix:///var/run/docker.sock version
    Client:
     Version:           28.4.0
     API version:       1.51
     Go version:        go1.24.7
     Git commit:        d8eb465
     Built:             Wed Sep  3 20:56:28 2025
     OS/Arch:           linux/amd64
     Context:           default

    Server: Docker Engine - Community
     Engine:
      Version:          28.4.0
      API version:      1.51 (minimum version 1.24)
      Go version:       go1.24.7

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-26 17:38:36 +02:00
Paweł Gronowski
2670796a01 Merge pull request #51045 from thaJeztah/t_context
use t.Context() instead of context.TODO() in various tests
2025-09-26 09:09:01 +00:00
Sebastiaan van Stijn
3912ffacd6 integration/nw: TestEmptyPortBindingsBC use context
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-25 22:53:49 +02:00
Sebastiaan van Stijn
e80e2908ba dockerversion: use t.Context() in tests
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-25 22:53:49 +02:00
Sebastiaan van Stijn
aca0adfb97 daemon: use t.Context() in tests
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-25 22:53:48 +02:00
Sebastiaan van Stijn
8905c3052b daemon/libnetwork: use t.Context() in tests
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-25 22:53:41 +02:00
Sebastiaan van Stijn
01f9186d6d daemon/logger: use t.Context() in tests
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-25 21:15:02 +02:00
Sebastiaan van Stijn
c1c9087404 daemon/containerd: use t.Context() in tests
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-25 21:15:02 +02:00
Sebastiaan van Stijn
544f8f53ed daemon/builder: use t.Context() in tests
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-25 21:15:02 +02:00
Sebastiaan van Stijn
4809fe0ffa Merge pull request #51043 from thaJeztah/bump_go_systemd
vendor: github.com/coreos/go-systemd/v22 v22.6.0
2025-09-25 21:01:19 +02:00
Sebastiaan van Stijn
73a30d9a2b Merge pull request #51031 from thaJeztah/bump_runtime_tools
vendor: opencontainers/runtime-tools v0.9.1-0.20250523060157-0ea5ed0382a2
2025-09-25 21:01:01 +02:00
Sebastiaan van Stijn
73ed41ef79 vendor: github.com/coreos/go-systemd/v22 v22.6.0
notable changes:

- journal: fix return types inside C wrapper functions
- dlopen: make error handling thread safe
- dbus: add AttachProcessesToUnit
- dbus: Add a comment about result channel behaviour

full diff: https://github.com/coreos/go-systemd/compare/v22.5.0...v22.6.0

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-25 13:45:26 +02:00
Sebastiaan van Stijn
0f393630f8 vendor: opencontainers/runtime-tools v0.9.1-0.20250523060157-0ea5ed0382a2
full diff: 2e043c6bd6...0ea5ed0382

Notable changes:

- Revert "Change /dev to be mounted by default with /noexec".  Mounting /dev
  with 'noexec' option triggers problems when containers try to create Intel
  SGX enclaves: [runtime-tools@0524bb2]
- Switch to github.com/moby/sys/capability [runtime-tools@c2dadba]

[runtime-tools@0524bb2]: 0524bb2cf6
[runtime-tools@c2dadba]: c2dadba13f

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-25 13:33:34 +02:00
Paweł Gronowski
22016b516b Merge pull request #51024 from thaJeztah/custom_metaheaders
daemon/containerd: pass custom metaHeaders to resolver
2025-09-25 11:26:44 +00:00
Paweł Gronowski
4181d934be Merge pull request #50869 from vvoland/c8d-fix-windows-migration
daemon: Fix unwanted c8d migration on Windows
2025-09-25 11:13:39 +00:00
Sebastiaan van Stijn
dcf5db2464 Merge pull request #51029 from tonistiigi/update-buildkit-v0.25.0-rc1
vendor: update buildkit to v0.25.0-rc1
2025-09-24 13:51:38 +02:00
Tonis Tiigi
e8d3609031 hack: use custom ref for buildkit tests
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2025-09-24 13:19:48 +02:00
Tonis Tiigi
21d2d55500 vendor: update buildkit to v0.25.0-rc1
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
2025-09-23 13:33:46 -07:00
Sebastiaan van Stijn
e98849831f Merge pull request #51021 from robmry/setuposcontext_leaks
testutil:SetupTestOSContext - fix ns/netlink handle leaks
2025-09-23 21:03:48 +02:00
Sebastiaan van Stijn
ddcc286e36 Merge pull request #51027 from thaJeztah/api_rm_BridgeNfIptables
api: docs: remove deprecated BridgeNfIptables, BridgeNfIp6tables
2025-09-23 20:53:13 +02:00
Rob Murray
de5e64b3bd Add option WithSetNsHandles for testutil SetupTestOSContextEx
Allow tests to run in parallel with separate network namespaces,
without modifying the global-state namespace/netlink handles in
the "ns" package ... only useful for tests that don't depend on
package "ns".

Use the new option in iptabler/nftabler tests.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2025-09-23 17:35:58 +01:00
Sebastiaan van Stijn
0fb46d08ad api: docs: remove deprecated BridgeNfIptables, BridgeNfIp6tables
The `BridgeNfIptables` and `BridgeNfIp6tables` were removed in API v1.50
in commit 6505d3877c, and only returned in
lower API versions.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-23 18:17:25 +02:00
Rob Murray
362d4d9538 testutil:SetupTestOSContext - don't leak namespaces, netlink handles
SetupTestOSContextEx calls 'ns.Init' (which, outside tests, is protected
by a sync.Once), and it's called again by the returned OSContext.Cleanup
method. That overwrites the ns package's namespace and netlink handles
(initNs and initNl) without closing them.

Because SetupTestOSContextEx changes that shared state, it should not
be used in parallel tests. So, rather than trying to close the handles
in ns.Init if already open - un-export Init so it's always called via
its sync.Once, and add a reset function for tests to use. Have
SetupTestOSContextEx claim a mutex to avoid crashy surprises or
hard to catch issues where the ns package isn't using the expected
namespace if it is used in parallel tests.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2025-09-23 16:16:00 +01:00
Sebastiaan van Stijn
b2320da428 Merge pull request #51019 from thaJeztah/client_commit_no_pause
client: ContainerCommitOptions: change "Pause" to "NoPause"
2025-09-23 12:50:50 +02:00
Sebastiaan van Stijn
5a6f13824a Merge pull request #51025 from thaJeztah/backend_push_pull_options
daemon/server/imagebackend: add PullOptions, PushOptions structs
2025-09-23 12:10:16 +02:00
Sebastiaan van Stijn
a32a53ae01 daemon/containerd: pass custom metaHeaders to resolver
Similar to how [distribution.newRepository] in the legacy distribution code
passes the (custom) http-headers. User-Agent is always set, and can't be
overridden, so we apply it after setting the custom headers.

[distribution.newRepository]: 9ce272f804/daemon/internal/distribution/registry.go (L74-L97)

Before this patch:

    docker run --rm -d --name debugger -p 127.0.0.1:5001:8080 mendhak/http-https-echo
    DOCKER_CUSTOM_HEADERS=X-Meta-Hello=thaJeztah docker pull localhost:5001/myimage:latest
    docker logs debugger
    ...
    "headers": {
        "host": "localhost:5001",
        "user-agent": "docker/dev go/go1.24.7 git-commit/8e89fe7e8cbb3048f640846590175cbae4719b25 kernel/6.10.14-linuxkit os/linux arch/arm64 containerd-client/2.1.4+unknown storage-driver/overlayfs UpstreamClient(Docker-Client/28.3.2 \\(linux\\))",
        "accept": "application/json, */*",
        "accept-encoding": "zstd;q=1.0, gzip;q=0.8, deflate;q=0.5",
        "baggage": "trigger=api"
    },

With this patch:

    docker run --rm -d --name debugger -p 127.0.0.1:5001:8080 mendhak/http-https-echo
    DOCKER_CUSTOM_HEADERS=X-Meta-Hello=thaJeztah docker pull localhost:5001/myimage:latest
    docker logs debugger
    ...
    "headers": {
        "host": "localhost:5001",
        "user-agent": "docker/dev go/go1.24.7 git-commit/8e89fe7e8cbb3048f640846590175cbae4719b25 kernel/6.10.14-linuxkit os/linux arch/arm64 containerd-client/2.1.4+unknown storage-driver/overlayfs UpstreamClient(Docker-Client/28.3.2 \\(linux\\))",
        "accept": "application/json, */*",
        "accept-encoding": "zstd;q=1.0, gzip;q=0.8, deflate;q=0.5",
        "baggage": "trigger=api",
        "x-meta-hello": "thaJeztah"
    },

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-23 11:42:10 +02:00
Sebastiaan van Stijn
0498c54577 Merge pull request #51023 from thaJeztah/integration_rename_client
integration/service: rename var to prevent shadowing
2025-09-23 10:50:56 +02:00
Sebastiaan van Stijn
2223b7f582 daemon/server/imagebackend: add PushOptions struct
The PushImage method for the ImageService used positional arguments for its
options, which made it more difficult to introduce new options. This patch
introduces a `PushOptions` struct to specify the options. As part of these
changes, the `platform` option was already adjusted to accept a slice of
platforms, which currently is not supported, but may be in the near future.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-23 09:57:22 +02:00
Sebastiaan van Stijn
9d53093db6 daemon/server/imagebackend: add PullOptions struct
The PullImage method for the ImageService used positional arguments for its
options, which made it more difficult to introduce new options. This patch
introduces a `PullOptions` struct to specify the options. As part of these
changes, the `platform` option was already adjusted to accept a slice of
platforms, which currently is not supported, but may be in the near future.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-23 09:43:03 +02:00
Austin Vazquez
9ce272f804 Merge pull request #51022 from thaJeztah/bump_xx
Dockerfile: update xx to v1.7.0
2025-09-22 12:02:49 -07:00
Sebastiaan van Stijn
69d5112c72 Merge pull request #50529 from mdaffad/50159-migrate-test-api-network-defaults-and-filter
test: migrate test api network get defaults and filter
2025-09-22 18:46:02 +02:00
Sebastiaan van Stijn
3985a66ef9 Merge pull request #51018 from thaJeztah/EOL_23
project: mark 23.0 branch as unmaintained (EOL)
2025-09-22 18:26:11 +02:00
Sebastiaan van Stijn
98a9e85536 Merge pull request #51020 from thaJeztah/clean_ping_version
client: Client.negotiateAPIVersionPing: trim v-prefix before handling
2025-09-22 18:25:38 +02:00
Sebastiaan van Stijn
cbafff64e4 project: mark 23.0 branch as unmaintained (EOL)
Mirantis Container Runtime 23.0 reached EOL on May 19, and the 23.0
branch is no longer maintained.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-22 15:36:42 +02:00
Sebastiaan van Stijn
5d22d9bec9 integration/service: rename var to prevent shadowing
Use "apiClient" for the client (most places use either `apiClient`
or `c`) to prevent shadowing the `client` import.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-22 14:34:39 +02:00
Sebastiaan van Stijn
471f24bafc daemon/server/backend: CreateImageConfig: change "Pause" to "NoPause"
Commit [moby@17d870b] (API v1.13, docker v1.1.0) changed the default to pause
containers during commit, keeping the behavior opt-in for older API versions.
This version-gate was removed in [moby@1b1147e] because API versions lower
than v1.23 were no longer supported.

However, the `CreateImageConfig` struct still used `Pause`, and required opting-
in to enable pausing. This patch changes the struct to reflect the default.
after this change, we should also consider changing the API make disabling
pause a more explicit option, and to change the "pause" argument to a
"no-pause".

[moby@17d870b]: 17d870bed5
[moby@1b1147e]: 1b1147e46b

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-22 13:59:56 +02:00
Sebastiaan van Stijn
bad3dfe9cb client: ContainerCommitOptions: change "Pause" to "NoPause"
Commit [moby@17d870b] (API v1.13, docker v1.1.0) changed the default to pause
containers during commit, keeping the behavior opt-in for older API versions.
This version-gate was removed in [moby@1b1147e] because API versions lower
than v1.23 were no longer supported.

However, the client still required opting-in to pausing containers, which
is handled by setting the `Pause` field to true by default. This patch changes
the client option to reflect the default; after this change, we should also
consider changing the API make disabling pause a more explicit option, and
to change the "pause" argument to a "no-pause".

[moby@17d870b]: 17d870bed5
[moby@1b1147e]: 1b1147e46b

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-22 13:59:02 +02:00
Sebastiaan van Stijn
19ee177635 Merge pull request #50530 from thaJeztah/explicit_state
explicitly access Container.State instead of through embedded struct
2025-09-22 13:58:09 +02:00
Sebastiaan van Stijn
1135ab0283 Dockerfile: update xx to v1.7.0
full diff: https://github.com/tonistiigi/xx/compare/v1.6.1...v1.7.0

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-22 13:06:51 +02:00
Sebastiaan van Stijn
f5847040cc client: Client.negotiateAPIVersionPing: trim v-prefix before handling
Trim any v-prefix passed to this function to make sure we detect empty
API versions.

In most cases, the ping-response will originate from the API server, but
the exported `Client.NegotiateAPIVersionPing` allows a ping-response to
be passed manually.

While updating, also update the signature to only accept the version, as
only the `PingResponse.APIVersion` is used by this function.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-22 11:31:16 +02:00
Sebastiaan van Stijn
af3f971431 client: TestNegotiateAPIVersionAutomatic: gofumpt
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-22 11:30:52 +02:00
Sebastiaan van Stijn
a8cb35f01a client: TestPingHeadFallback: check method, path, and fix example response
Validate that the client is connecting with the expected endpoint path and
method(s). Also fix the Api-Version response to align with the actual format
returned, which doesn't include a "v" prefix;

    curl -sI --unix-socket /var/run/docker.sock 'http://localhost/_ping' | grep 'Api-Version'
    Api-Version: 1.51

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-22 11:30:52 +02:00
Sebastiaan van Stijn
2613bb0c25 Merge pull request #51011 from thaJeztah/client_rm_httpclient
client: remove unused Client.HTTPClient() method
2025-09-22 11:28:48 +02:00
Muhammad Daffa Dinaya
87d1da50f0 test: migrate test api network get defaults and filter
Signed-off-by: Muhammad Daffa Dinaya <muhammaddaffadinaya@gmail.com>
2025-09-20 05:58:35 +00:00
Sebastiaan van Stijn
d9cdfd2887 client: remove unused Client.HTTPClient() method
This method was introduced in [moby@5a84124] related to the (now removed)
support for "compose on kubernetes" in the CLI. This functionality extended
the CLI with endpoints that are not part of the engine API, but re-using
the HTTP-client with the same (TLS) config as the CLI itself.

While such scenarios may be something to consider in future (i.e. more easily
extend the API with custom endpoints), this method is not currently used,
but defined as part of the CLI's interface. This patch removes the method
for now, so that we can design from a clean slate in case we need this
extensibility, instead of keeping methods that were added ad-hoc around.

[moby@5a84124]: 5a84124739

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-19 17:07:39 +02:00
Sebastiaan van Stijn
d4d93bf558 daemon/container: remove State.ExitCode() method
This method did not provide any special handling for accessing the
field, and did not handle locking. Let's remove it for now to
not pretend we're doing anything more safe than directly accessing
the field.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-19 15:33:36 +01:00
Sebastiaan van Stijn
ee4b7a8374 daemon/container: remove NewState() constructor
This constructor did not do anything other than creating an empty struct
for an exported type. While we should look at initializing with a proper
state, we currently do not, so let's not pretend we do some magic here,
and leave it for a future exercise to create a proper constructor if we
need one.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-19 15:33:36 +01:00
Sebastiaan van Stijn
d06f0d008d explicitly access Container.State.Health.Health
The State.Health struct has a mutex, but in various places
we access the embedded Health struct directly.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-19 15:33:36 +01:00
Rob Murray
2f87bb4410 Merge pull request #51009 from olljanat/legacy-remote-ipam-support
ipams: Re-enable legacy remote plugins support
2025-09-19 15:26:05 +01:00
Sebastiaan van Stijn
0df791cb72 explicitly access Container.State instead of through embedded struct
The Container.State struct holds the container's state, and most of
its fields are expected to change dynamically. Some o these state-changes
are explicit, for example, setting the container to be "stopped". Other
state changes can be more explicit, for example due to the containers'
process exiting or being "OOM" killed by the kernel.

The distinction between explicit ("desired") state changes and "state"
("actual state") is sometimes vague; for some properties, we clearly
separated them, for example if a user requested the container to be
stopped or restarted, we store state in the Container object itself;

    HasBeenManuallyStopped   bool // used for unless-stopped restart policy
    HasBeenManuallyRestarted bool `json:"-"` // used to distinguish restart caused by restart policy from the manual one

Other properties are more ambiguous. such as "HasBeenStartedBefore" and
"RestartCount", which are stored on the Container (and persisted to
disk), but may be more related to "actual" state, and likely should
not be persisted;

    RestartCount             int
    HasBeenStartedBefore     bool

Given that (per the above) concurrency must be taken into account, most
changes to the `container.State` struct should be protected; here's where
things get blurry. While the `State` type provides various accessor methods,
only some of them take concurrency into account; for example, [State.IsRunning]
and [State.GetPID] acquire a lock, whereas [State.ExitCodeValue] does not.
Even the (commonly used) [State.StateString] has no locking at all.

The way to handle this is error-prone; [container.State] contains a mutex,
and it's exported. Given that its embedded in the [container.Container]
struct, it's also exposed as an exported mutex for the container. The
assumption here is that by "merging" the two, the caller to acquire a lock
when either the container _or_ its state must be mutated. However, because
some methods on `container.State` handle their own locking, consumers must
be deeply familiar with the internals; if both changes to the `Container`
AND `Container.State` must be made. This gets amplified more as some
(exported!) methods, such as [container.SetRunning] mutate multiple fields,
but don't acquire a lock (so expect the caller to hold one), but their
(also exported) counterpart (e.g. [State.IsRunning]) do.

It should be clear from the above, that this needs some architectural
changes; a clearer separation between "desired" and "actual" state (opening
the potential to update the container's config without manually touching
its `State`), possibly a method to obtain a read-only copy of the current
state (for those querying state), and reviewing which fields belong where
(and should be persisted to disk, or only remain in memory).

This PR preserves the status quo; it makes no structural changes, other
than exposing where we access the container's state. Where previously the
State fields and methods were referred to as "part of the container"
(e.g. `ctr.IsRunning()` or `ctr.Running`), we now explicitly reference
the embedded `State` (`ctr.State.IsRunning`, `ctr.State.Running`).

The exception (for now) is the mutex, which is still referenced through
the embedded struct (`ctr.Lock()` instead of `ctr.State.Lock()`), as this
is (mostly) by design to protect the container, and what's in it (including
its `State`).

[State.IsRunning]: c4afa77157/daemon/container/state.go (L205-L209)
[State.GetPID]: c4afa77157/daemon/container/state.go (L211-L216)
[State.ExitCodeValue]: c4afa77157/daemon/container/state.go (L218-L228)
[State.StateString]: c4afa77157/daemon/container/state.go (L102-L131)
[container.State]: c4afa77157/daemon/container/state.go (L15-L23)
[container.Container]: c4afa77157/daemon/container/container.go (L67-L75)
[container.SetRunning]: c4afa77157/daemon/container/state.go (L230-L277)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-09-19 16:02:14 +02:00