Remove hostname validation as it seems to break users
Validation is still done by swarmkit on the service side. Signed-off-by: Vincent Demeester <vincent@sbr.pm>
This commit is contained in:
parent
d77269a802
commit
bfd123b2a9
11 changed files with 26 additions and 85 deletions
|
@ -32,17 +32,17 @@ type copyBackend interface {
|
|||
|
||||
// stateBackend includes functions to implement to provide container state lifecycle functionality.
|
||||
type stateBackend interface {
|
||||
ContainerCreate(config types.ContainerCreateConfig, validateHostname bool) (types.ContainerCreateResponse, error)
|
||||
ContainerCreate(config types.ContainerCreateConfig) (types.ContainerCreateResponse, error)
|
||||
ContainerKill(name string, sig uint64) error
|
||||
ContainerPause(name string) error
|
||||
ContainerRename(oldName, newName string) error
|
||||
ContainerResize(name string, height, width int) error
|
||||
ContainerRestart(name string, seconds int) error
|
||||
ContainerRm(name string, config *types.ContainerRmConfig) error
|
||||
ContainerStart(name string, hostConfig *container.HostConfig, validateHostname bool) error
|
||||
ContainerStart(name string, hostConfig *container.HostConfig) error
|
||||
ContainerStop(name string, seconds int) error
|
||||
ContainerUnpause(name string) error
|
||||
ContainerUpdate(name string, hostConfig *container.HostConfig, validateHostname bool) ([]string, error)
|
||||
ContainerUpdate(name string, hostConfig *container.HostConfig) ([]string, error)
|
||||
ContainerWait(name string, timeout time.Duration) (int, error)
|
||||
}
|
||||
|
||||
|
|
|
@ -151,8 +151,7 @@ func (s *containerRouter) postContainersStart(ctx context.Context, w http.Respon
|
|||
hostConfig = c
|
||||
}
|
||||
|
||||
validateHostname := versions.GreaterThanOrEqualTo(version, "1.24")
|
||||
if err := s.backend.ContainerStart(vars["name"], hostConfig, validateHostname); err != nil {
|
||||
if err := s.backend.ContainerStart(vars["name"], hostConfig); err != nil {
|
||||
return err
|
||||
}
|
||||
w.WriteHeader(http.StatusNoContent)
|
||||
|
@ -312,7 +311,6 @@ func (s *containerRouter) postContainerUpdate(ctx context.Context, w http.Respon
|
|||
return err
|
||||
}
|
||||
|
||||
version := httputils.VersionFromContext(ctx)
|
||||
var updateConfig container.UpdateConfig
|
||||
|
||||
decoder := json.NewDecoder(r.Body)
|
||||
|
@ -326,8 +324,7 @@ func (s *containerRouter) postContainerUpdate(ctx context.Context, w http.Respon
|
|||
}
|
||||
|
||||
name := vars["name"]
|
||||
validateHostname := versions.GreaterThanOrEqualTo(version, "1.24")
|
||||
warnings, err := s.backend.ContainerUpdate(name, hostConfig, validateHostname)
|
||||
warnings, err := s.backend.ContainerUpdate(name, hostConfig)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -354,14 +351,13 @@ func (s *containerRouter) postContainersCreate(ctx context.Context, w http.Respo
|
|||
version := httputils.VersionFromContext(ctx)
|
||||
adjustCPUShares := versions.LessThan(version, "1.19")
|
||||
|
||||
validateHostname := versions.GreaterThanOrEqualTo(version, "1.24")
|
||||
ccr, err := s.backend.ContainerCreate(types.ContainerCreateConfig{
|
||||
Name: name,
|
||||
Config: config,
|
||||
HostConfig: hostConfig,
|
||||
NetworkingConfig: networkingConfig,
|
||||
AdjustCPUShares: adjustCPUShares,
|
||||
}, validateHostname)
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -116,7 +116,7 @@ type Backend interface {
|
|||
// ContainerAttachRaw attaches to container.
|
||||
ContainerAttachRaw(cID string, stdin io.ReadCloser, stdout, stderr io.Writer, stream bool) error
|
||||
// ContainerCreate creates a new Docker container and returns potential warnings
|
||||
ContainerCreate(config types.ContainerCreateConfig, validateHostname bool) (types.ContainerCreateResponse, error)
|
||||
ContainerCreate(config types.ContainerCreateConfig) (types.ContainerCreateResponse, error)
|
||||
// ContainerRm removes a container specified by `id`.
|
||||
ContainerRm(name string, config *types.ContainerRmConfig) error
|
||||
// Commit creates a new Docker image from an existing Docker container.
|
||||
|
@ -124,7 +124,7 @@ type Backend interface {
|
|||
// ContainerKill stops the container execution abruptly.
|
||||
ContainerKill(containerID string, sig uint64) error
|
||||
// ContainerStart starts a new container
|
||||
ContainerStart(containerID string, hostConfig *container.HostConfig, validateHostname bool) error
|
||||
ContainerStart(containerID string, hostConfig *container.HostConfig) error
|
||||
// ContainerWait stops processing until the given container is stopped.
|
||||
ContainerWait(containerID string, timeout time.Duration) (int, error)
|
||||
// ContainerUpdateCmdOnBuild updates container.Path and container.Args
|
||||
|
|
|
@ -181,7 +181,7 @@ func (b *Builder) runContextCommand(args []string, allowRemote bool, allowLocalD
|
|||
return nil
|
||||
}
|
||||
|
||||
container, err := b.docker.ContainerCreate(types.ContainerCreateConfig{Config: b.runConfig}, true)
|
||||
container, err := b.docker.ContainerCreate(types.ContainerCreateConfig{Config: b.runConfig})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -508,7 +508,7 @@ func (b *Builder) create() (string, error) {
|
|||
c, err := b.docker.ContainerCreate(types.ContainerCreateConfig{
|
||||
Config: b.runConfig,
|
||||
HostConfig: hostConfig,
|
||||
}, true)
|
||||
})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
@ -552,7 +552,7 @@ func (b *Builder) run(cID string) (err error) {
|
|||
}
|
||||
}()
|
||||
|
||||
if err := b.docker.ContainerStart(cID, nil, true); err != nil {
|
||||
if err := b.docker.ContainerStart(cID, nil); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -23,8 +23,8 @@ type Backend interface {
|
|||
FindNetwork(idName string) (libnetwork.Network, error)
|
||||
SetupIngress(req clustertypes.NetworkCreateRequest, nodeIP string) error
|
||||
PullImage(ctx context.Context, image, tag string, metaHeaders map[string][]string, authConfig *types.AuthConfig, outStream io.Writer) error
|
||||
CreateManagedContainer(config types.ContainerCreateConfig, validateHostname bool) (types.ContainerCreateResponse, error)
|
||||
ContainerStart(name string, hostConfig *container.HostConfig, validateHostname bool) error
|
||||
CreateManagedContainer(config types.ContainerCreateConfig) (types.ContainerCreateResponse, error)
|
||||
ContainerStart(name string, hostConfig *container.HostConfig) error
|
||||
ContainerStop(name string, seconds int) error
|
||||
ConnectContainerToNetwork(containerName, networkName string, endpointConfig *network.EndpointSettings) error
|
||||
UpdateContainerServiceConfig(containerName string, serviceConfig *clustertypes.ServiceConfig) error
|
||||
|
|
|
@ -10,11 +10,9 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/docker/docker/api/server/httputils"
|
||||
executorpkg "github.com/docker/docker/daemon/cluster/executor"
|
||||
"github.com/docker/engine-api/types"
|
||||
"github.com/docker/engine-api/types/events"
|
||||
"github.com/docker/engine-api/types/versions"
|
||||
"github.com/docker/libnetwork"
|
||||
"github.com/docker/swarmkit/api"
|
||||
"github.com/docker/swarmkit/log"
|
||||
|
@ -119,8 +117,6 @@ func (c *containerAdapter) removeNetworks(ctx context.Context) error {
|
|||
func (c *containerAdapter) create(ctx context.Context, backend executorpkg.Backend) error {
|
||||
var cr types.ContainerCreateResponse
|
||||
var err error
|
||||
version := httputils.VersionFromContext(ctx)
|
||||
validateHostname := versions.GreaterThanOrEqualTo(version, "1.24")
|
||||
|
||||
if cr, err = backend.CreateManagedContainer(types.ContainerCreateConfig{
|
||||
Name: c.container.name(),
|
||||
|
@ -128,7 +124,7 @@ func (c *containerAdapter) create(ctx context.Context, backend executorpkg.Backe
|
|||
HostConfig: c.container.hostConfig(),
|
||||
// Use the first network in container create
|
||||
NetworkingConfig: c.container.createNetworkingConfig(),
|
||||
}, validateHostname); err != nil {
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -152,9 +148,7 @@ func (c *containerAdapter) create(ctx context.Context, backend executorpkg.Backe
|
|||
}
|
||||
|
||||
func (c *containerAdapter) start(ctx context.Context) error {
|
||||
version := httputils.VersionFromContext(ctx)
|
||||
validateHostname := versions.GreaterThanOrEqualTo(version, "1.24")
|
||||
return c.backend.ContainerStart(c.container.name(), nil, validateHostname)
|
||||
return c.backend.ContainerStart(c.container.name(), nil)
|
||||
}
|
||||
|
||||
func (c *containerAdapter) inspect(ctx context.Context) (types.ContainerJSON, error) {
|
||||
|
|
|
@ -3,7 +3,6 @@ package daemon
|
|||
import (
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/container"
|
||||
|
@ -203,7 +202,7 @@ func (daemon *Daemon) setHostConfig(container *container.Container, hostConfig *
|
|||
|
||||
// verifyContainerSettings performs validation of the hostconfig and config
|
||||
// structures.
|
||||
func (daemon *Daemon) verifyContainerSettings(hostConfig *containertypes.HostConfig, config *containertypes.Config, update bool, validateHostname bool) ([]string, error) {
|
||||
func (daemon *Daemon) verifyContainerSettings(hostConfig *containertypes.HostConfig, config *containertypes.Config, update bool) ([]string, error) {
|
||||
|
||||
// First perform verification of settings common across all platforms.
|
||||
if config != nil {
|
||||
|
@ -220,18 +219,6 @@ func (daemon *Daemon) verifyContainerSettings(hostConfig *containertypes.HostCon
|
|||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
// Validate if the given hostname is RFC 1123 (https://tools.ietf.org/html/rfc1123) compliant.
|
||||
if validateHostname && len(config.Hostname) > 0 {
|
||||
// RFC1123 specifies that 63 bytes is the maximium length
|
||||
// Windows has the limitation of 63 bytes in length
|
||||
// Linux hostname is limited to HOST_NAME_MAX=64, not including the terminating null byte.
|
||||
// We limit the length to 63 bytes here to match RFC1035 and RFC1123.
|
||||
matched, _ := regexp.MatchString("^(([[:alnum:]]|[[:alnum:]][[:alnum:]\\-]*[[:alnum:]])\\.)*([[:alnum:]]|[[:alnum:]][[:alnum:]\\-]*[[:alnum:]])$", config.Hostname)
|
||||
if len(config.Hostname) > 63 || !matched {
|
||||
return nil, fmt.Errorf("invalid hostname format: %s", config.Hostname)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if hostConfig == nil {
|
||||
|
|
|
@ -20,21 +20,21 @@ import (
|
|||
)
|
||||
|
||||
// CreateManagedContainer creates a container that is managed by a Service
|
||||
func (daemon *Daemon) CreateManagedContainer(params types.ContainerCreateConfig, validateHostname bool) (types.ContainerCreateResponse, error) {
|
||||
return daemon.containerCreate(params, true, validateHostname)
|
||||
func (daemon *Daemon) CreateManagedContainer(params types.ContainerCreateConfig) (types.ContainerCreateResponse, error) {
|
||||
return daemon.containerCreate(params, true)
|
||||
}
|
||||
|
||||
// ContainerCreate creates a regular container
|
||||
func (daemon *Daemon) ContainerCreate(params types.ContainerCreateConfig, validateHostname bool) (types.ContainerCreateResponse, error) {
|
||||
return daemon.containerCreate(params, false, validateHostname)
|
||||
func (daemon *Daemon) ContainerCreate(params types.ContainerCreateConfig) (types.ContainerCreateResponse, error) {
|
||||
return daemon.containerCreate(params, false)
|
||||
}
|
||||
|
||||
func (daemon *Daemon) containerCreate(params types.ContainerCreateConfig, managed bool, validateHostname bool) (types.ContainerCreateResponse, error) {
|
||||
func (daemon *Daemon) containerCreate(params types.ContainerCreateConfig, managed bool) (types.ContainerCreateResponse, error) {
|
||||
if params.Config == nil {
|
||||
return types.ContainerCreateResponse{}, fmt.Errorf("Config cannot be empty in order to create a container")
|
||||
}
|
||||
|
||||
warnings, err := daemon.verifyContainerSettings(params.HostConfig, params.Config, false, validateHostname)
|
||||
warnings, err := daemon.verifyContainerSettings(params.HostConfig, params.Config, false)
|
||||
if err != nil {
|
||||
return types.ContainerCreateResponse{Warnings: warnings}, err
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ import (
|
|||
)
|
||||
|
||||
// ContainerStart starts a container.
|
||||
func (daemon *Daemon) ContainerStart(name string, hostConfig *containertypes.HostConfig, validateHostname bool) error {
|
||||
func (daemon *Daemon) ContainerStart(name string, hostConfig *containertypes.HostConfig) error {
|
||||
container, err := daemon.GetContainer(name)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -68,7 +68,7 @@ func (daemon *Daemon) ContainerStart(name string, hostConfig *containertypes.Hos
|
|||
|
||||
// check if hostConfig is in line with the current system settings.
|
||||
// It may happen cgroups are umounted or the like.
|
||||
if _, err = daemon.verifyContainerSettings(container.HostConfig, nil, false, validateHostname); err != nil {
|
||||
if _, err = daemon.verifyContainerSettings(container.HostConfig, nil, false); err != nil {
|
||||
return err
|
||||
}
|
||||
// Adapt for old containers in case we have updates in this function and
|
||||
|
|
|
@ -7,10 +7,10 @@ import (
|
|||
)
|
||||
|
||||
// ContainerUpdate updates configuration of the container
|
||||
func (daemon *Daemon) ContainerUpdate(name string, hostConfig *container.HostConfig, validateHostname bool) ([]string, error) {
|
||||
func (daemon *Daemon) ContainerUpdate(name string, hostConfig *container.HostConfig) ([]string, error) {
|
||||
var warnings []string
|
||||
|
||||
warnings, err := daemon.verifyContainerSettings(hostConfig, nil, true, validateHostname)
|
||||
warnings, err := daemon.verifyContainerSettings(hostConfig, nil, true)
|
||||
if err != nil {
|
||||
return warnings, err
|
||||
}
|
||||
|
|
|
@ -4416,42 +4416,6 @@ func (s *DockerSuite) TestRunVolumeCopyFlag(c *check.C) {
|
|||
c.Assert(err, checker.NotNil, check.Commentf(out))
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestRunTooLongHostname(c *check.C) {
|
||||
// Test case in #21445
|
||||
hostname1 := "this-is-a-way-too-long-hostname-but-it-should-give-a-nice-error.local"
|
||||
out, _, err := dockerCmdWithError("run", "--hostname", hostname1, "busybox", "echo", "test")
|
||||
c.Assert(err, checker.NotNil, check.Commentf("Expected docker run to fail!"))
|
||||
c.Assert(out, checker.Contains, "invalid hostname format:", check.Commentf("Expected to have 'invalid hostname format:' in the output, get: %s!", out))
|
||||
|
||||
// Additional test cases
|
||||
validHostnames := map[string]string{
|
||||
"hostname": "hostname",
|
||||
"host-name": "host-name",
|
||||
"hostname123": "hostname123",
|
||||
"123hostname": "123hostname",
|
||||
"hostname-of-63-bytes-long-should-be-valid-and-without-any-error": "hostname-of-63-bytes-long-should-be-valid-and-without-any-error",
|
||||
}
|
||||
for hostname := range validHostnames {
|
||||
dockerCmd(c, "run", "--hostname", hostname, "busybox", "echo", "test")
|
||||
}
|
||||
|
||||
invalidHostnames := map[string]string{
|
||||
"^hostname": "invalid hostname format: ^hostname",
|
||||
"hostname%": "invalid hostname format: hostname%",
|
||||
"host&name": "invalid hostname format: host&name",
|
||||
"-hostname": "invalid hostname format: -hostname",
|
||||
"host_name": "invalid hostname format: host_name",
|
||||
"hostname-of-64-bytes-long-should-be-invalid-and-be-with-an-error": "invalid hostname format: hostname-of-64-bytes-long-should-be-invalid-and-be-with-an-error",
|
||||
}
|
||||
|
||||
for hostname, expectedError := range invalidHostnames {
|
||||
out, _, err = dockerCmdWithError("run", "--hostname", hostname, "busybox", "echo", "test")
|
||||
c.Assert(err, checker.NotNil, check.Commentf("Expected docker run to fail!"))
|
||||
c.Assert(out, checker.Contains, expectedError, check.Commentf("Expected to have '%s' in the output, get: %s!", expectedError, out))
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// Test case for #21976
|
||||
func (s *DockerSuite) TestRunDnsInHostMode(c *check.C) {
|
||||
testRequires(c, DaemonIsLinux, NotUserNamespace)
|
||||
|
|
Loading…
Reference in a new issue