Skip to content

libnet: Make sure network names are unique#46251

Merged
thaJeztah merged 1 commit intomoby:masterfrom
akerouanton:libnet-forbid-duplicated-network-names
Sep 12, 2023
Merged

libnet: Make sure network names are unique#46251
thaJeztah merged 1 commit intomoby:masterfrom
akerouanton:libnet-forbid-duplicated-network-names

Conversation

@akerouanton
Copy link
Copy Markdown
Member

@akerouanton akerouanton commented Aug 17, 2023

- What I did

Fixes #18864, #20648, #33561, #40901 (and probably more).

This GH comment makes clear network name uniqueness has never been enforced due to the eventually consistent nature of Classic Swarm datastores:

there is no guaranteed way to check for duplicates across a cluster of docker hosts.

And this is further confirmed by other comments made by @mrjana in that same issue, eg. this one:

we want to adopt a schema which can pave the way in the future for a completely decentralized cluster of docker hosts (if scalability is needed).

This decentralized model is what Classic Swarm was trying to be. It's been superseded since then by Docker Swarm, which has a centralized control plane.

To circumvent this drawback, the NetworkCreate endpoint accepts a CheckDuplicate flag. However it's not perfectly reliable as it won't catch concurrent requests.

Due to this design decision, API clients like Compose have to implement workarounds to make sure names are really unique (eg. docker/compose#9585). And the daemon itself has seen a string of issues due to that decision, including some that aren't fixed to this day (for instance #40901):

The problem is, that if you specify a network for a container using the ID, it will add that network to the container but it will then change it to reference the network by using the name.

To summarize, this "feature" is broken, has no practical use and is a source of pain for Docker users and API consumers. So let's just remove it for all API versions.

- A picture of a cute animal (not mandatory but encouraged)

Comment thread integration/network/network_test.go Outdated
@akerouanton akerouanton force-pushed the libnet-forbid-duplicated-network-names branch from f4bd1ba to 280795e Compare August 17, 2023 13:30
Comment thread api/swagger.yaml Outdated
Comment thread docs/api/version-history.md Outdated
akerouanton added a commit to akerouanton/docker-py that referenced this pull request Aug 19, 2023
moby/moby#46251 marks CheckDuplicate as deprecated. Any NetworkCreate
request with a conflicting network name will now return an error.

Signed-off-by: Albin Kerouanton <[email protected]>
akerouanton added a commit to akerouanton/docker-py that referenced this pull request Aug 19, 2023
moby/moby#46251 marks CheckDuplicate as deprecated. Any NetworkCreate
request with a conflicting network name will now return an error.

Signed-off-by: Albin Kerouanton <[email protected]>
akerouanton added a commit to akerouanton/docker-py that referenced this pull request Aug 19, 2023
moby/moby#46251 marks CheckDuplicate as deprecated. Any NetworkCreate
request with a conflicting network name will now return an error.

Signed-off-by: Albin Kerouanton <[email protected]>
akerouanton added a commit to akerouanton/docker-py that referenced this pull request Aug 19, 2023
moby/moby#46251 marks CheckDuplicate as deprecated. Any NetworkCreate
request with a conflicting network name will now return an error.

Signed-off-by: Albin Kerouanton <[email protected]>
milas pushed a commit to docker/docker-py that referenced this pull request Aug 21, 2023
integration: check_duplicate is now the default behavior

moby/moby#46251 marks CheckDuplicate as deprecated. Any NetworkCreate
request with a conflicting network name will now return an error.

Signed-off-by: Albin Kerouanton <[email protected]>
@akerouanton akerouanton force-pushed the libnet-forbid-duplicated-network-names branch from 280795e to 07dcf62 Compare September 8, 2023 17:01
@akerouanton akerouanton marked this pull request as ready for review September 8, 2023 17:07
@akerouanton akerouanton force-pushed the libnet-forbid-duplicated-network-names branch 2 times, most recently from bcbec62 to c8ba829 Compare September 8, 2023 17:30
@akerouanton akerouanton requested a review from tianon as a code owner September 8, 2023 17:30
@akerouanton
Copy link
Copy Markdown
Member Author

CI failed on a unrelated flake:

=== Failed
=== FAIL: amd64.integration.daemon TestLiveRestore/volume_references/local_volume_with_mount_options (2.54s)
    daemon_test.go:513: assertion failed: error is not nil: Error response from daemon: remove test-live-restore-volume-references-local: volume has active mounts
        --- FAIL: TestLiveRestore/volume_references/local_volume_with_mount_options (2.54s)

=== FAIL: amd64.integration.daemon TestLiveRestore/volume_references (18.62s)
    --- FAIL: TestLiveRestore/volume_references (18.62s)

=== FAIL: amd64.integration.daemon TestLiveRestore (0.00s)

Comment thread api/types/types.go Outdated
Comment thread client/network_create_test.go
@akerouanton akerouanton force-pushed the libnet-forbid-duplicated-network-names branch from c8ba829 to fbb011e Compare September 11, 2023 11:40
Comment thread client/network_create.go Outdated
Comment thread api/types/types.go Outdated
@akerouanton akerouanton force-pushed the libnet-forbid-duplicated-network-names branch from fbb011e to e77601b Compare September 11, 2023 12:24
Comment thread client/network_create.go
NetworkCreate: options,
Name: name,
}
if versions.LessThan(cli.version, "1.44") {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self; I'm actually wondering now if these checks we have in the client work, as we moved negotiating the API version to be as late as possible, which (I think) in this case could mean that we postpone it to cli.post (which calls cli.sendRequest, which calls cli.getAPIPath (which handles the negotiation)) 🙈

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(It's probably fine to keep this as-is for now, as it looks like it's something to fix for other parts as well)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread hack/make/test-docker-py
}

func TestForbidDuplicateNetworkNames(t *testing.T) {
skip.If(t, testEnv.DaemonInfo.OSType == "windows")
Copy link
Copy Markdown
Member

@thaJeztah thaJeztah Sep 11, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you know why this didn't fail on Windows?

(didn't fail => why the test didn't work?)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I force pushed my commit to check what's the error, and here it is:

=== Failed
=== FAIL: github.com/docker/docker/integration/network TestForbidDuplicateNetworkNames (0.01s)
    network_test.go:266: [d46d27c88db30] failed to start daemon with arguments [--data-root D:\a\moby\moby\go\src\github.com\docker\docker\bundles\tmp\TestForbidDuplicateNetworkNames\d46d27c88db30\root --exec-root C:\Users\RUNNER~1\AppData\Local\Temp\dxr\d46d27c88db30 --pidfile D:\a\moby\moby\go\src\github.com\docker\docker\bundles\tmp\TestForbidDuplicateNetworkNames\d46d27c88db30\docker.pid --userland-proxy=true --containerd-namespace d46d27c88db30 --containerd-plugins-namespace d46d27c88db30p --containerd /var/run/docker/containerd/containerd.sock --host unix://C:\Users\RUNNER~1\AppData\Local\Temp\docker-integration\d46d27c88db30.sock --debug] : protocol not available

So, it's totally unrelated to this change. I'll create a follow-up PR addressing that.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting; thanks!

(mostly commented because we have many tests with a skip, and for some nobody even remembers "why" 😂)

@akerouanton akerouanton force-pushed the libnet-forbid-duplicated-network-names branch 2 times, most recently from 9b58911 to a5c0d9b Compare September 11, 2023 13:56
@thaJeztah
Copy link
Copy Markdown
Member

🙈 I think one of your other PRs conflicted; looks like this needs a rebase now (changes LGTM though)

Fixes moby#18864, moby#20648, moby#33561, moby#40901.

[This GH comment][1] makes clear network name uniqueness has never been
enforced due to the eventually consistent nature of Classic Swarm
datastores:

> there is no guaranteed way to check for duplicates across a cluster of
> docker hosts.

And this is further confirmed by other comments made by @mrjana in that
same issue, eg. [this one][2]:

> we want to adopt a schema which can pave the way in the future for a
> completely decentralized cluster of docker hosts (if scalability is
> needed).

This decentralized model is what Classic Swarm was trying to be. It's
been superseded since then by Docker Swarm, which has a centralized
control plane.

To circumvent this drawback, the `NetworkCreate` endpoint accepts a
`CheckDuplicate` flag. However it's not perfectly reliable as it won't
catch concurrent requests.

Due to this design decision, API clients like Compose have to implement
workarounds to make sure names are really unique (eg.
docker/compose#9585). And the daemon itself has seen a string of issues
due to that decision, including some that aren't fixed to this day (for
instance moby#40901):

> The problem is, that if you specify a network for a container using
> the ID, it will add that network to the container but it will then
> change it to reference the network by using the name.

To summarize, this "feature" is broken, has no practical use and is a
source of pain for Docker users and API consumers. So let's just remove
it for _all_ API versions.

[1]: moby#18864 (comment)
[2]: moby#18864 (comment)

Signed-off-by: Albin Kerouanton <[email protected]>
@akerouanton akerouanton force-pushed the libnet-forbid-duplicated-network-names branch from a5c0d9b to 78479b1 Compare September 12, 2023 08:50
@thaJeztah thaJeztah added this to the 25.0.0 milestone Sep 12, 2023
Copy link
Copy Markdown
Member

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@thaJeztah thaJeztah merged commit 3b04fd1 into moby:master Sep 12, 2023
@akerouanton akerouanton deleted the libnet-forbid-duplicated-network-names branch September 12, 2023 14:53
openstack-mirroring pushed a commit to openstack/kuryr-libnetwork that referenced this pull request Sep 25, 2024
Docker has disallowed multiple networks with the same name:
moby/moby#46251

Change-Id: I4e5979dcf15b5270a0fc47a204b3a63405663809
openstack-mirroring pushed a commit to openstack/openstack that referenced this pull request Sep 25, 2024
* Update kuryr-libnetwork from branch 'master'
  to a4b276cfff1b2d88a58fd6c6a1c99e3761984ebd
  - Remove test_create_network_with_same_name
    
    Docker has disallowed multiple networks with the same name:
    moby/moby#46251
    
    Change-Id: I4e5979dcf15b5270a0fc47a204b3a63405663809
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/api API area/networking Networking impact/api impact/changelog kind/enhancement Enhancements are not bugs or new features but can improve usability or performance. status/2-code-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The docker daemon API lets you create two networks with the same name

3 participants