Commit Graph

1705 Commits

Author SHA1 Message Date
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
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
9699284e8f Add iptablesdoc for a swarm network
Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-12-17 09:14:25 +00:00
Rob Murray
3bf9a80818 Rename L3Segment Host.Run -> Host.MustRun
Like netip.MustParseIP, it fails on error.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-12-17 09:14:25 +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
Sebastiaan van Stijn
53a9127349 integration/build: make TestBuildEmitsImageCreateEvent less noisy
This test by default was outputing the build-progress output, and printing
a log for every event received, which made the test output rather noisy;

    === RUN   TestBuildEmitsImageCreateEvent
    === RUN   TestBuildEmitsImageCreateEvent/v1
        build_test.go:765: {"stream":"Step 1/2 : FROM busybox"}

            {"stream":"\n"}

            {"stream":" ---\u003e 19d689bc58fd\n"}

            {"stream":"Step 2/2 : RUN echo hello \u003e /hello"}

            {"stream":"\n"}

            {"stream":" ---\u003e Running in 538c10d10d69\n"}

            {"stream":" ---\u003e ca6d3b3e2dea\n"}

            {"aux":{"ID":"sha256:ca6d3b3e2dea645eeddd838da65fd06986da1392b6091dd3d3b89f239dc44f57"}}

            {"stream":"Successfully built ca6d3b3e2dea\n"}

        build_test.go:776: Got event type: container action: create
        build_test.go:776: Got event type: container action: attach
        build_test.go:776: Got event type: network action: connect
        build_test.go:776: Got event type: container action: start
        build_test.go:776: Got event type: network action: disconnect
        build_test.go:776: Got event type: container action: die
        build_test.go:776: Got event type: image action: create
    === RUN   TestBuildEmitsImageCreateEvent/v2
        build_test.go:765: {"id":"moby.buildkit.trace","aux":"Cm8KR3NoYTI1NjowZWViNmZmNTg0ZDJhODEwODhjMTJlNmVkODMxZDcyNWVhMjZmNTg2NjcyNDQ0MzU3NTNkNmZiOGVhMDBiNGFiGiRbaW50ZXJuYWxdIGxvYWQgcmVtb3RlIGJ1aWxkIGNvbnRleHQ="}

            {"id":"moby.buildkit.trace","aux":"CnwKR3NoYTI1NjowZWViNmZmNTg0ZDJhODEwODhjMTJlNmVkODMxZDcyNWVhMjZmNTg2NjcyNDQ0MzU3NTNkNmZiOGVhMDBiNGFiGiRbaW50ZXJuYWxdIGxvYWQgcmVtb3RlIGJ1aWxkIGNvbnRleHQqCwj+tIC7BhCxkpNl"}

            {"id":"moby.buildkit.trace","aux":"CokBCkdzaGEyNTY6MGVlYjZmZjU4NGQyYTgxMDg4YzEyZTZlZDgzMWQ3MjVlYTI2ZjU4NjY3MjQ0NDM1NzUzZDZmYjhlYTAwYjRhYhokW2ludGVybmFsXSBsb2FkIHJlbW90ZSBidWlsZCBjb250ZXh0KgsI/rSAuwYQsZKTZTILCP60gLsGELmTrHg="}

            {"id":"moby.buildkit.trace","aux":"CokBCkdzaGEyNTY6MGVlYjZmZjU4NGQyYTgxMDg4YzEyZTZlZDgzMWQ3MjVlYTI2ZjU4NjY3MjQ0NDM1NzUzZDZmYjhlYTAwYjRhYhokW2ludGVybmFsXSBsb2FkIHJlbW90ZSBidWlsZCBjb250ZXh0KgsI/rSAuwYQpZC3eDILCP60gLsGELbLuXg="}

            {"id":"moby.buildkit.trace","aux":"CqMBCkdzaGEyNTY6MzFjMGEyZDk1N2Q2MTQ2ZjE0NDEyNTM4YTc2YTAxNjhlOWQ5NzY2ZjA0ZjNmMDM4OGQ1YzdjNjQ1ODQ0NDQ3YxJHc2hhMjU2OjBlZWI2ZmY1ODRkMmE4MTA4OGMxMmU2ZWQ4MzFkNzI1ZWEyNmY1ODY2NzI0NDQzNTc1M2Q2ZmI4ZWEwMGI0YWIaD2NvcHkgL2NvbnRleHQgLw=="}

            {"id":"moby.buildkit.trace","aux":"CrABCkdzaGEyNTY6MzFjMGEyZDk1N2Q2MTQ2ZjE0NDEyNTM4YTc2YTAxNjhlOWQ5NzY2ZjA0ZjNmMDM4OGQ1YzdjNjQ1ODQ0NDQ3YxJHc2hhMjU2OjBlZWI2ZmY1ODRkMmE4MTA4OGMxMmU2ZWQ4MzFkNzI1ZWEyNmY1ODY2NzI0NDQzNTc1M2Q2ZmI4ZWEwMGI0YWIaD2NvcHkgL2NvbnRleHQgLyoLCP60gLsGEIyYn3s="}

            {"id":"moby.buildkit.trace","aux":"Cr4BCkdzaGEyNTY6MzFjMGEyZDk1N2Q2MTQ2ZjE0NDEyNTM4YTc2YTAxNjhlOWQ5NzY2ZjA0ZjNmMDM4OGQ1YzdjNjQ1ODQ0NDQ3YxJHc2hhMjU2OjBlZWI2ZmY1ODRkMmE4MTA4OGMxMmU2ZWQ4MzFkNzI1ZWEyNmY1ODY2NzI0NDQzNTc1M2Q2ZmI4ZWEwMGI0YWIaD2NvcHkgL2NvbnRleHQgLyoLCP60gLsGEIyYn3syDAj+tIC7BhCrvMGHAQ=="}

            {"id":"moby.buildkit.trace","aux":"CpYBCkdzaGEyNTY6OTQxZDA2ZjIwMTljOWJmN2FjM2MyZjc5MThhNDQ3ZTU5ZmRkNTEwM2IzMDg0NGRhZmQ5OGFlODE3NjRjYzk4ZBo9W2ludGVybmFsXSBsb2FkIG1ldGFkYXRhIGZvciBkb2NrZXIuaW8vbGlicmFyeS9idXN5Ym94OmxhdGVzdCoMCP60gLsGEPzY+IgB"}

            {"id":"moby.buildkit.trace","aux":"CqQBCkdzaGEyNTY6OTQxZDA2ZjIwMTljOWJmN2FjM2MyZjc5MThhNDQ3ZTU5ZmRkNTEwM2IzMDg0NGRhZmQ5OGFlODE3NjRjYzk4ZBo9W2ludGVybmFsXSBsb2FkIG1ldGFkYXRhIGZvciBkb2NrZXIuaW8vbGlicmFyeS9idXN5Ym94OmxhdGVzdCoMCP60gLsGEPzY+IgBMgwI/rSAuwYQk9mDiQE="}

            {"id":"moby.buildkit.trace","aux":"CrEBCkdzaGEyNTY6ZTNmZGU0ZDc3MmYxZjUyMGVlMzllNzA3YTcyNGNhNjRiN2VhM2IyMGYwOTc2ZDJmN2NiNDBkY2Q5MWU2NTk1YRJHc2hhMjU2OjIyNzAwYzkxMGNmY2I3MjNjZGYyZmNjMGYxNzQ1MjAzMDQxNzk1NmY0ZDhiZjEzZjZkZmRkZWM3NjgxZDcxODAaHVsyLzJdIFJVTiBlY2hvIGhlbGxvID4gL2hlbGxvCnYKR3NoYTI1NjoyMjcwMGM5MTBjZmNiNzIzY2RmMmZjYzBmMTc0NTIwMzA0MTc5NTZmNGQ4YmYxM2Y2ZGZkZGVjNzY4MWQ3MTgwGitbMS8yXSBGUk9NIGRvY2tlci5pby9saWJyYXJ5L2J1c3lib3g6bGF0ZXN0"}

            {"id":"moby.buildkit.trace","aux":"CoQBCkdzaGEyNTY6MjI3MDBjOTEwY2ZjYjcyM2NkZjJmY2MwZjE3NDUyMDMwNDE3OTU2ZjRkOGJmMTNmNmRmZGRlYzc2ODFkNzE4MBorWzEvMl0gRlJPTSBkb2NrZXIuaW8vbGlicmFyeS9idXN5Ym94OmxhdGVzdCoMCP60gLsGEKKYuYkB"}

            {"id":"moby.buildkit.trace","aux":"CpIBCkdzaGEyNTY6MjI3MDBjOTEwY2ZjYjcyM2NkZjJmY2MwZjE3NDUyMDMwNDE3OTU2ZjRkOGJmMTNmNmRmZGRlYzc2ODFkNzE4MBorWzEvMl0gRlJPTSBkb2NrZXIuaW8vbGlicmFyeS9idXN5Ym94OmxhdGVzdCoMCP60gLsGEKKYuYkBMgwI/rSAuwYQhurIiQE="}

            {"id":"moby.buildkit.trace","aux":"CoQBCkdzaGEyNTY6MjI3MDBjOTEwY2ZjYjcyM2NkZjJmY2MwZjE3NDUyMDMwNDE3OTU2ZjRkOGJmMTNmNmRmZGRlYzc2ODFkNzE4MBorWzEvMl0gRlJPTSBkb2NrZXIuaW8vbGlicmFyeS9idXN5Ym94OmxhdGVzdCoMCP60gLsGEPGI0YkB"}

            {"id":"moby.buildkit.trace","aux":"CpIBCkdzaGEyNTY6MjI3MDBjOTEwY2ZjYjcyM2NkZjJmY2MwZjE3NDUyMDMwNDE3OTU2ZjRkOGJmMTNmNmRmZGRlYzc2ODFkNzE4MBorWzEvMl0gRlJPTSBkb2NrZXIuaW8vbGlicmFyeS9idXN5Ym94OmxhdGVzdCoMCP60gLsGEPGI0YkBMgwI/rSAuwYQv9CgkAE="}

            {"id":"moby.buildkit.trace","aux":"Cr8BCkdzaGEyNTY6ZTNmZGU0ZDc3MmYxZjUyMGVlMzllNzA3YTcyNGNhNjRiN2VhM2IyMGYwOTc2ZDJmN2NiNDBkY2Q5MWU2NTk1YRJHc2hhMjU2OjIyNzAwYzkxMGNmY2I3MjNjZGYyZmNjMGYxNzQ1MjAzMDQxNzk1NmY0ZDhiZjEzZjZkZmRkZWM3NjgxZDcxODAaHVsyLzJdIFJVTiBlY2hvIGhlbGxvID4gL2hlbGxvKgwI/rSAuwYQwvqtkgE="}

            {"id":"moby.buildkit.trace","aux":"Cs0BCkdzaGEyNTY6ZTNmZGU0ZDc3MmYxZjUyMGVlMzllNzA3YTcyNGNhNjRiN2VhM2IyMGYwOTc2ZDJmN2NiNDBkY2Q5MWU2NTk1YRJHc2hhMjU2OjIyNzAwYzkxMGNmY2I3MjNjZGYyZmNjMGYxNzQ1MjAzMDQxNzk1NmY0ZDhiZjEzZjZkZmRkZWM3NjgxZDcxODAaHVsyLzJdIFJVTiBlY2hvIGhlbGxvID4gL2hlbGxvKgwI/rSAuwYQwvqtkgEyDAj+tIC7BhDshP7sAQ=="}

            {"id":"moby.buildkit.trace","aux":"CmsKR3NoYTI1NjpmMWM5ZDIzNTNhOWRlZjgwOTI2OGRmMjhhMjU4YzExNTA2ODcxMWE0ZmFiYzM1MjNkOGJhZDIxOTgyMDc3MjFjGhJleHBvcnRpbmcgdG8gaW1hZ2UqDAj+tIC7BhC6trLuARJ3ChBleHBvcnRpbmcgbGF5ZXJzEkdzaGEyNTY6ZjFjOWQyMzUzYTlkZWY4MDkyNjhkZjI4YTI1OGMxMTUwNjg3MTFhNGZhYmMzNTIzZDhiYWQyMTk4MjA3NzIxYzIMCP60gLsGEIe6s+4BOgwI/rSAuwYQq7az7gE="}

            {"id":"moby.buildkit.trace","aux":"EoUBChBleHBvcnRpbmcgbGF5ZXJzEkdzaGEyNTY6ZjFjOWQyMzUzYTlkZWY4MDkyNjhkZjI4YTI1OGMxMTUwNjg3MTFhNGZhYmMzNTIzZDhiYWQyMTk4MjA3NzIxYzIMCP60gLsGEOz5ovsBOgwI/rSAuwYQq7az7gFCDAj+tIC7BhDV8qL7AQ=="}

            {"id":"moby.buildkit.trace","aux":"ErwBClV3cml0aW5nIGltYWdlIHNoYTI1Njo5YjIzODY3ODkzZGMyZDVlM2UxNDBhYjBlY2Y1ZGI4MzlhYjA0YzQ0NjRiNjMyZTQ5ZTg3YzBmOThkZDEyYzFhEkdzaGEyNTY6ZjFjOWQyMzUzYTlkZWY4MDkyNjhkZjI4YTI1OGMxMTUwNjg3MTFhNGZhYmMzNTIzZDhiYWQyMTk4MjA3NzIxYzIMCP60gLsGEPHIq/sBOgwI/rSAuwYQ38Wr+wE="}

            {"id":"moby.buildkit.trace","aux":"EsoBClV3cml0aW5nIGltYWdlIHNoYTI1Njo5YjIzODY3ODkzZGMyZDVlM2UxNDBhYjBlY2Y1ZGI4MzlhYjA0YzQ0NjRiNjMyZTQ5ZTg3YzBmOThkZDEyYzFhEkdzaGEyNTY6ZjFjOWQyMzUzYTlkZWY4MDkyNjhkZjI4YTI1OGMxMTUwNjg3MTFhNGZhYmMzNTIzZDhiYWQyMTk4MjA3NzIxYzIMCP60gLsGEOuB7vwBOgwI/rSAuwYQ38Wr+wFCDAj+tIC7BhCT/+38AQ=="}

            {"id":"moby.buildkit.trace","aux":"CnkKR3NoYTI1NjpmMWM5ZDIzNTNhOWRlZjgwOTI2OGRmMjhhMjU4YzExNTA2ODcxMWE0ZmFiYzM1MjNkOGJhZDIxOTgyMDc3MjFjGhJleHBvcnRpbmcgdG8gaW1hZ2UqDAj+tIC7BhC6trLuATIMCP60gLsGEJG6x4QC"}

            {"id":"moby.image.id","aux":{"ID":"sha256:9b23867893dc2d5e3e140ab0ecf5db839ab04c4464b632e49e87c0f98dd12c1a"}}

        build_test.go:776: Got event type: image action: create

This patch preserves both, but only prints them if the test failed to
help debugging failures.

With this patch:

On success:

    === RUN   TestBuildEmitsImageCreateEvent
    === RUN   TestBuildEmitsImageCreateEvent/v1
    === RUN   TestBuildEmitsImageCreateEvent/v2
    --- PASS: TestBuildEmitsImageCreateEvent (1.53s)
        --- PASS: TestBuildEmitsImageCreateEvent/v1 (0.48s)
        --- PASS: TestBuildEmitsImageCreateEvent/v2 (1.03s)
    PASS

When failing:

    === Failed
    === FAIL: arm64.integration.build TestBuildEmitsImageCreateEvent/v1 (0.97s)
        build_test.go:789: assertion failed: 1 (int) != 0 (imageCreateEvts int)
        build_test.go:790: build-logs:
            {"stream":"Step 1/2 : FROM busybox"}
            {"stream":"\n"}
            {"stream":" ---\u003e 19d689bc58fd\n"}
            {"stream":"Step 2/2 : RUN echo hello \u003e /hello"}
            {"stream":"\n"}
            {"stream":" ---\u003e Running in 119e771bcb1a\n"}
            {"stream":" ---\u003e 289982143d91\n"}
            {"aux":{"ID":"sha256:289982143d912b1c11d95dddfb59640c175fb29a9a00f0223a1ad18972b6df74"}}
            {"stream":"Successfully built 289982143d91\n"}

        build_test.go:791: events received:
            type: container, action: create
            type: container, action: attach
            type: network, action: connect
            type: container, action: start
            type: network, action: disconnect
            type: container, action: die
            type: image, action: create
        --- FAIL: TestBuildEmitsImageCreateEvent/v1 (0.97s)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-12-16 13:43:05 +01:00
Sebastiaan van Stijn
01b98afeb6 Merge pull request #49054 from maggie44/apiversion
Accurately reflect the canonical casing of `API-Version` and `OS-Type` headers
2024-12-16 13:06:31 +01:00
Paweł Gronowski
899360b649 integration/build_traces: Create own tracer provider
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-12-12 18:32:05 +01:00
maggie44
76a5ca1d4d Accurately reflect the canonical casing of API-Version and OS-Type headers
Go automatically canonicalises HTTP headers, meaning the string `API-Version` passed as a header has always been returned as `Api-Version`. Similarly, `OSType` is returned as `Ostype`.

This commit updates the documentation to reflect this behaviour and modifies the codebase to ensure that input strings are aligned with their canonical output values.

Signed-off-by: maggie44 <64841595+maggie44@users.noreply.github.com>
2024-12-08 22:23:57 +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
0eb3d431c0 Run tests that change docker0 in their own netns
These tests create iptables rules for different addresses on
docker0 but, unlike tests that do that for user-defined bridges,
those rules aren't removed when the test deletes the network,
because the default bridge network can't be deleted.

So, use (abuse) the L3Segment code to run the tests in their
own network namespace.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-12-04 12:02:03 +00:00
Sebastiaan van Stijn
24fd633ebb Merge pull request #48597 from robmry/nat-unprotected
Add gateway mode "nat-unprotected"
2024-11-29 16:42:28 +01: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
Albin Kerouanton
5b752fab32 api: add Priority field to EndpointSettings
This new field is used by libnetwork to determine which endpoint
provides the default gateway for a container.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
2024-11-28 17:06:26 +01:00
Sebastiaan van Stijn
b8db6d143a Merge pull request #48956 from thaJeztah/poll_default_delay
integration: remove default poll delay and timeouts
2024-11-27 22:20:36 +01:00
Sebastiaan van Stijn
8277fc78e9 Merge pull request #48940 from thaJeztah/integration_add_wait
integration: add wait
2024-11-27 22:20:08 +01:00
Akihiro Suda
fb6e650ab9 integration: add wait
Cherry-picked several WIP commits from
b0a592798f/

Originally-authored-by: Rodrigo Campos <rodrigoca@microsoft.com>
Co-Authored-by: Kir Kolyshkin <kolyshkin@gmail.com>
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-27 15:52:49 +01:00
Sebastiaan van Stijn
b57aa7f3b7 integration: remove default poll delay and timeouts
The default delay is 100ms and default timeout is 10s, so we can
remove cases where we are setting the defaults;

d8fa0581ee/vendor/gotest.tools/v3/poll/poll.go (L115)
d8fa0581ee/vendor/gotest.tools/v3/poll/poll.go (L39-L40)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-26 14:05:02 +01:00
Rob Murray
c9a1e4dc8c Test host-gateway addresses from docker0
Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-11-26 11:47:31 +00:00
Rob Murray
01e2168c1e Move Linux-only integration/network tests into Linux-only file
Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-11-26 11:47:31 +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
Rob Murray
cc538b2bf0 Drop fixed-cidr if not within user-managed bridge subnet
When a user-managed bridge is used for the default network (--bridge),
an address from the bridge determines the subnet for the network.

If a fixed-cidr is supplied, it should fall within that subnet. If it
doesn't, it's a misconfiguration - fixed-cidr is the range of
allocatable addresses, and they need to be in the network. (Either
the user's bridge is missing an address that matches their fixed-cidr
or the fixed-cidr is wrong.)

When this happens, because it's been allowed in the past (and, because
the address-pool implementation treats fixed-cidr/SubPool as an offset
into the network rather than an actual address range, so working IP
addresses would normally still be assigned to containers) ... don't
reject the config and cause daemon startup to fail. Just log a warning
and ignore fixed-cidr.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-11-25 18:28:37 +00:00
Rob Murray
311a8bc899 Allow increase of fixed-cidr subnet size
For a docker-managed default bridge (docker0), when no --bip is
supplied, the gateway address and subnet size can be inferred
from existing bridge addresses.

But, if fixed-cidr's subnet size is increased so that it's biggger
than the subnet of the bridge's existing address - the bridge's
subnet needs to be incresed to match. (fixed-cidr determines the
range of addresses that can be automatically allocated, and these
should not fall outside the default bridge's subnet.)

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-11-25 18:28:37 +00:00
Rob Murray
85159ce09f Allow non-overlapping change of fixed-cidr
When a docker-managed default bridge (docker0) already has an
address, and the fixed-cidr subnet fits within the subnet defined
by that address, the existing address should be used as the
gateway and to define the subnet.

But, when fixed-cidr is changed, no --bip is supplied, and no
existing bridge network includes fixed-cidr ... the existing
bridge address needs to be updated.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-11-25 18:28:37 +00:00
Rob Murray
90baa2bc36 Fix selection of subnet from user-managed default bridge
When a user-managed bridge is used instead of docker0 (--bridge), with
a fixed-cidr - the bridge should have an IP address/subnet that
encompasses fixed-cidr ... the bridge address's subnet then defines
the network's subnet, and fixed-cidr defines the allocatable range
within that.

But, selection of the correct subnet/address from the bridge depended
on the address being within fixed-cidr (within the allocatable range).

This change removes that assumption. So, a bridge address with a
subnet that includes fixed-cidr is selected.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-11-25 18:28:37 +00:00
Rob Murray
facb2323a0 Add tests for IPAM Config of default bridge
Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-11-25 18:28:37 +00:00
Rob Murray
4a2bd1085e Move default bridge test into linux-only file
Becuase I'm about to add tests that use netlink, and the netlink
package breaks compilation under Windows.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-11-25 18:28:37 +00:00
Aleksa Sarai
caae3c051d tests: migrate to assert.ErrorContains when possible
If we have an error type that we're checking a substring against, we
should really be checking using ErrorContains to indicate the right
semantics to assert.

Mostly done using these transforms:

  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r 'assert.Assert(t, is.ErrorContains(e, s)) -> assert.ErrorContains(t, e, s)'
  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r 'assert.Assert(t, is.Contains(err.Error(), s)) -> assert.ErrorContains(t, err, s)'
  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r 'assert.Check(t, is.Contains(err.Error(), s)) -> assert.Check(t, is.ErrorContains(err, s))'

As well as some small fixups to helpers that were doing
strings.Contains explicitly.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2024-11-22 23:59:21 +11: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
Aleksa Sarai
0553d3d994 tests: migrate away from assert.Assert(err == nil)
Unfortunately, gofmt doesn't know about types so it was necessary to
find all of the err == nil statements through trial and error. Note that
there is no is.NilError, so for assert.Check(t, err == nil) we need to
switch to just doing assert.Check(t, err). If err is an error type, this
is equivalent (and there isn't another trivial way of doing it). Here
are the full set of rules used:

Generic "err == nil":

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

Generic, but with a different variable name:

  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r "assert.Assert(t, sr.err == nil) -> assert.NilError(t, sr.err)"
  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r "assert.Check(t, sr.err == nil) -> assert.Check(t, sr.err)"
  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r "assert.Assert(t, err2 == nil) -> assert.NilError(t, err2)"
  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r "assert.Check(t, err2 == nil) -> assert.Check(t, err2)"

JSON-related error assertions:

  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r "assert.Assert(t, json.Unmarshal(a, b) == nil) -> assert.NilError(t, json.Unmarshal(a, b))"
  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r "assert.Check(t, json.Unmarshal(a, b) == nil) -> assert.Check(t, json.Unmarshal(a, b))"
  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r "assert.Assert(t, json.NewDecoder(a).Decode(b) == nil) -> assert.NilError(t, json.NewDecoder(a).Decode(b))"
  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r "assert.Check(t, json.NewDecoder(a).Decode(b) == nil) -> assert.Check(t, json.NewDecoder(a).Decode(b))"
  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r "assert.Assert(t, json.NewEncoder(a).Encode(b) == nil) -> assert.NilError(t, json.NewEncoder(a).Encode(b))"
  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r "assert.Check(t, json.NewEncoder(a).Encode(b) == nil) -> assert.Check(t, json.NewEncoder(a).Encode(b))"

Process-related error assertions:

  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r "assert.Assert(t, a.Start() == nil) -> assert.NilError(t, a.Start())"
  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r "assert.Check(t, a.Start() == nil) -> assert.Check(t, a.Start())"
  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r "assert.Assert(t, a.Kill() == nil) -> assert.NilError(t, a.Kill())"
  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r "assert.Check(t, a.Kill() == nil) -> assert.Check(t, a.Kill())"
  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r "assert.Assert(t, a.Signal(b) == nil) -> assert.NilError(t, a.Signal(b))"
  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r "assert.Check(t, a.Signal(b) == nil) -> assert.Check(t, a.Signal(b))"

waitInspect:

  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r "assert.Assert(t, waitInspect(a, b, c, d) == nil) -> assert.NilError(t, waitInspect(a, b, c, d))"
  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r "assert.Check(t, waitInspect(a, b, c, d) == nil) -> assert.Check(t, waitInspect(a, b, c, d))"

File closing error assertions:

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

mount.MakeRShared:

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

daemon.SwarmLeave:

  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r "assert.Assert(t, d.SwarmLeave(a, b, c) == nil) -> assert.NilError(t, d.SwarmLeave(a, b, c))"
  find . -type f -name "*_test.go" | \
    xargs gofmt -w -r "assert.Check(t, d.SwarmLeave(a, b, c) == nil) -> assert.Check(t, d.SwarmLeave(a, b, c))"

os.MkdirAll:

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

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2024-11-22 23:59:20 +11:00
Aleksa Sarai
5e4e34a966 tests: migrate strings.Contains -> is.Contains in assertions
Migrated using

  find . -type f -name "*_test.go" |
    xargs gofmt -w \
      -r "assert.Check(t, strings.Contains(a, b)) -> assert.Check(t, is.Contains(a, b))"

  find . -type f -name "*_test.go" |
    xargs gofmt -w \
      -r "assert.Assert(t, strings.Contains(a, b)) -> assert.Assert(t, is.Contains(a, b))"

Using a boolean in assert.Assert or assert.Check results in error
messages that don't contain the actual problematic string, and when
running the integration suite on an actual machine (where the source
code parsing doesn't work) this makes it almost impossible to figure out
what the actual error is.

Signed-off-by: Aleksa Sarai <cyphar@cyphar.com>
2024-11-22 23:59:20 +11:00
Sebastiaan van Stijn
b9a904c48a integration/container: TestCDISpecDirsAreInSystemInfo: use fixtures
Set the daemon.json config as a string-literal in the tests, instead of
using a map[string]interface{} as intermediary format.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-22 10:55:55 +01:00
Sebastiaan van Stijn
968213c763 Merge pull request #48902 from thaJeztah/save_load_multiplat
client: support multiple platforms on save and load
2024-11-20 15:24:51 +01:00
Rob Murray
069e41afd9 Merge pull request #48596 from robmry/48526_gateway_routed_inc
Make containers on routed-mode networks accessible from other bridge networks
2024-11-19 16:24:22 +00:00
Sebastiaan van Stijn
d3609fa9c2 Merge pull request #48855 from vvoland/c8d-inspect-imagemanifest
c8d/container/inspect: Return `ImageManifestDescriptor`
2024-11-19 16:47:47 +01:00
Rob Murray
223929a44d Test routed n/w inter-network communication
Add an integration test to check that a container on a network
with gateway-mode=nat can access a container on a network with
gateway-mode=routed, but not vice-versa.

Signed-off-by: Rob Murray <rob.murray@docker.com>
2024-11-19 15:28:42 +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
Sebastiaan van Stijn
9c9eccfb23 client: support multiple platforms on save and load
We don't yet support this at the API level, so for now it returns
an error when trying to set multiple, but this makes sure that the
client types are already ready for this.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-19 15:56:28 +01:00
Paweł Gronowski
44ed3067ca c8d/container/inspect: Return ImageManifestDescriptor
`ImageManifestDescriptor` will contain an OCI descriptor of
platform-specific manifest of the image that was picked when creating
the container.

Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-11-19 13:55:56 +01:00
Rodrigo Campos
f96994ec17 Skip tests that are flaky for 4 already
Some other tests on this file where skipped with this same line. Let's
skip this one, that seems to be flaky too.

Signed-off-by: Rodrigo Campos <rodrigoca@microsoft.com>
2024-11-19 12:44:25 +01:00
Paweł Gronowski
d88ab0f3a2 c8d/image/inspect: Return Descriptor
Signed-off-by: Paweł Gronowski <pawel.gronowski@docker.com>
2024-11-18 13:00:44 +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
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
Albin Kerouanton
4c19680fc5 Merge pull request #48854 from robmry/12632_noproxy_masquerade
Only masquerade access to own published ports for userland-proxy=false
2024-11-15 09:38:32 +01:00
Sebastiaan van Stijn
3350920788 integration/service: remove redundant capturing of loop vars (copyloopvar)
integration/service/update_test.go:290:3: The copy of the 'for' variable "tc" can be deleted (Go 1.22+) (copyloopvar)
            tc := tc
            ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-12 14:02:19 +01:00
Sebastiaan van Stijn
04d8766d4e integration/network/bridge: remove redundant capturing of loop vars (copyloopvar)
integration/network/bridge/bridge_linux_test.go:177:3: The copy of the 'for' variable "tc" can be deleted (Go 1.22+) (copyloopvar)
            tc := tc
            ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-12 14:02:18 +01:00
Sebastiaan van Stijn
243442280e integration/system: remove redundant capturing of loop vars (copyloopvar)
integration/system/disk_usage_test.go:261:5: The copy of the 'for' variable "tc" can be deleted (Go 1.22+) (copyloopvar)
                    tc := tc
                    ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-12 14:02:18 +01:00
Sebastiaan van Stijn
a19b892c29 integration/volume: remove redundant capturing of loop vars (copyloopvar)
integration/volume/volume_test.go:202:3: The copy of the 'for' variable "ep" can be deleted (Go 1.22+) (copyloopvar)
            ep := ep
            ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-12 14:02:17 +01:00
Sebastiaan van Stijn
08dbb7a593 integration/build: remove redundant capturing of loop vars (copyloopvar)
integration/build/build_test.go:95:3: The copy of the 'for' variable "c" can be deleted (Go 1.22+) (copyloopvar)
            c := c
            ^
    integration/build/build_test.go:615:3: The copy of the 'for' variable "tc" can be deleted (Go 1.22+) (copyloopvar)
            tc := tc
            ^
    integration/build/build_test.go:743:3: The copy of the 'for' variable "builderVersion" can be deleted (Go 1.22+) (copyloopvar)
            builderVersion := builderVersion
            ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2024-11-12 14:02:17 +01:00