diff options
author | Paul Holzinger <pholzing@redhat.com> | 2021-09-16 11:01:52 +0200 |
---|---|---|
committer | Paul Holzinger <pholzing@redhat.com> | 2021-09-16 11:01:52 +0200 |
commit | 5c7935057c34cbdb27be3a584d35bff3fcd81202 (patch) | |
tree | 6fd4ff71cc95308d655a0d52bf01affae13f2c92 /pkg/domain/infra/abi | |
parent | 9119a578e782b92bd344f093f5491c318bc20d69 (diff) | |
download | podman-5c7935057c34cbdb27be3a584d35bff3fcd81202.tar.gz podman-5c7935057c34cbdb27be3a584d35bff3fcd81202.tar.bz2 podman-5c7935057c34cbdb27be3a584d35bff3fcd81202.zip |
Do not allow network modes to be used as network names
`podman network create` should not allow users to create networks with a
name which is already used for a network mode in `podman run --network`.
Fixes #11448
Signed-off-by: Paul Holzinger <pholzing@redhat.com>
Diffstat (limited to 'pkg/domain/infra/abi')
-rw-r--r-- | pkg/domain/infra/abi/network.go | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/pkg/domain/infra/abi/network.go b/pkg/domain/infra/abi/network.go index 45d2c6925..d792226a8 100644 --- a/pkg/domain/infra/abi/network.go +++ b/pkg/domain/infra/abi/network.go @@ -107,12 +107,15 @@ func (ic *ContainerEngine) NetworkRm(ctx context.Context, namesOrIds []string, o return reports, nil } -func (ic *ContainerEngine) NetworkCreate(ctx context.Context, network types.Network) (*entities.NetworkCreateReport, error) { +func (ic *ContainerEngine) NetworkCreate(ctx context.Context, network types.Network) (*types.Network, error) { + if util.StringInSlice(network.Name, []string{"none", "host", "bridge", "private", "slirp4netns", "container", "ns"}) { + return nil, errors.Errorf("cannot create network with name %q because it conflicts with a valid network mode", network.Name) + } network, err := ic.Libpod.Network().NetworkCreate(network) if err != nil { return nil, err } - return &entities.NetworkCreateReport{Name: network.Name}, nil + return &network, nil } // NetworkDisconnect removes a container from a given network |