mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Prevent network connect/disconnect on swarm scoped networks
Swarm handles service updates quite differently and also it doesnt support worker driver network operations. Hence prevent containers from connecting to swarm scoped networks Signed-off-by: Madhu Venugopal <madhu@docker.com>
This commit is contained in:
parent
9c1be541ff
commit
8f9066c468
1 changed files with 23 additions and 0 deletions
|
@ -2,6 +2,7 @@ package network
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"golang.org/x/net/context"
|
"golang.org/x/net/context"
|
||||||
|
@ -119,6 +120,10 @@ func (n *networkRouter) postNetworkConnect(ctx context.Context, w http.ResponseW
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if nw.Info().Dynamic() {
|
||||||
|
return newNetworkForbiddenError("Operation not supported for swarm scoped networks")
|
||||||
|
}
|
||||||
|
|
||||||
return n.backend.ConnectContainerToNetwork(connect.Container, nw.Name(), connect.EndpointConfig)
|
return n.backend.ConnectContainerToNetwork(connect.Container, nw.Name(), connect.EndpointConfig)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,6 +146,10 @@ func (n *networkRouter) postNetworkDisconnect(ctx context.Context, w http.Respon
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if nw.Info().Dynamic() {
|
||||||
|
return newNetworkForbiddenError("Operation not supported for swarm scoped networks")
|
||||||
|
}
|
||||||
|
|
||||||
return n.backend.DisconnectContainerFromNetwork(disconnect.Container, nw, disconnect.Force)
|
return n.backend.DisconnectContainerFromNetwork(disconnect.Container, nw, disconnect.Force)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -283,3 +292,17 @@ func buildEndpointResource(e libnetwork.Endpoint) types.EndpointResource {
|
||||||
}
|
}
|
||||||
return er
|
return er
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// networkForbiddenError represents an authorization deny error
|
||||||
|
type networkForbiddenError struct {
|
||||||
|
error
|
||||||
|
}
|
||||||
|
|
||||||
|
// HTTPErrorStatusCode returns the authorization error status code (forbidden)
|
||||||
|
func (e networkForbiddenError) HTTPErrorStatusCode() int {
|
||||||
|
return http.StatusForbidden
|
||||||
|
}
|
||||||
|
|
||||||
|
func newNetworkForbiddenError(msg string) networkForbiddenError {
|
||||||
|
return networkForbiddenError{error: fmt.Errorf("%s", msg)}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue