Prevent user from deleting pre-defined networks
Signed-off-by: Madhu Venugopal <madhu@docker.com> Upstream-commit: ead62b59522bba132b9a14712e4350439e7fa2a5 Component: engine
This commit is contained in:
@ -13,6 +13,7 @@ import (
|
||||
"github.com/docker/docker/daemon"
|
||||
"github.com/docker/docker/daemon/network"
|
||||
"github.com/docker/docker/pkg/parsers/filters"
|
||||
"github.com/docker/docker/runconfig"
|
||||
"github.com/docker/libnetwork"
|
||||
)
|
||||
|
||||
@ -85,6 +86,11 @@ func (n *networkRouter) postNetworkCreate(ctx context.Context, w http.ResponseWr
|
||||
return err
|
||||
}
|
||||
|
||||
if runconfig.IsPreDefinedNetwork(create.Name) {
|
||||
return httputils.WriteJSON(w, http.StatusForbidden,
|
||||
fmt.Sprintf("%s is a pre-defined network and cannot be created", create.Name))
|
||||
}
|
||||
|
||||
nw, err := n.daemon.GetNetwork(create.Name, daemon.NetworkByName)
|
||||
if _, ok := err.(libnetwork.ErrNoSuchNetwork); err != nil && !ok {
|
||||
return err
|
||||
@ -161,6 +167,11 @@ func (n *networkRouter) deleteNetwork(ctx context.Context, w http.ResponseWriter
|
||||
return err
|
||||
}
|
||||
|
||||
if runconfig.IsPreDefinedNetwork(nw.Name()) {
|
||||
return httputils.WriteJSON(w, http.StatusForbidden,
|
||||
fmt.Sprintf("%s is a pre-defined network and cannot be removed", nw.Name()))
|
||||
}
|
||||
|
||||
return nw.Delete()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user