network create: do not allow default as name

`default` is already used as network mode, i.e. podman run --network
default will choose the default mode not a network named `default`.

We already block names from other network modes, default was forgotten.

Fixes #17169

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
Paul Holzinger
2023-01-20 14:52:07 +01:00
parent 8f0a0f3ec3
commit 86699954b1
2 changed files with 2 additions and 2 deletions

View File

@ -151,7 +151,7 @@ func (ic *ContainerEngine) NetworkRm(ctx context.Context, namesOrIds []string, o
func (ic *ContainerEngine) NetworkCreate(ctx context.Context, network types.Network, createOptions *types.NetworkCreateOptions) (*types.Network, error) { func (ic *ContainerEngine) NetworkCreate(ctx context.Context, network types.Network, createOptions *types.NetworkCreateOptions) (*types.Network, error) {
// TODO (5.0): Stop accepting "pasta" as value here // TODO (5.0): Stop accepting "pasta" as value here
if util.StringInSlice(network.Name, []string{"none", "host", "bridge", "private", "slirp4netns", "container", "ns"}) { if util.StringInSlice(network.Name, []string{"none", "host", "bridge", "private", "slirp4netns", "container", "ns", "default"}) {
return nil, fmt.Errorf("cannot create network with name %q because it conflicts with a valid network mode", network.Name) return nil, fmt.Errorf("cannot create network with name %q because it conflicts with a valid network mode", network.Name)
} }
network, err := ic.Libpod.Network().NetworkCreate(network, createOptions) network, err := ic.Libpod.Network().NetworkCreate(network, createOptions)

View File

@ -366,7 +366,7 @@ var _ = Describe("Podman network create", func() {
}) })
It("podman network create with invalid name", func() { It("podman network create with invalid name", func() {
for _, name := range []string{"none", "host", "bridge", "private", "slirp4netns", "container", "ns"} { for _, name := range []string{"none", "host", "bridge", "private", "slirp4netns", "container", "ns", "default"} {
nc := podmanTest.Podman([]string{"network", "create", name}) nc := podmanTest.Podman([]string{"network", "create", name})
nc.WaitWithDefaultTimeout() nc.WaitWithDefaultTimeout()
Expect(nc).To(Exit(125)) Expect(nc).To(Exit(125))