Skip to content

Commit 3cb310c

Browse files
authored
Merge pull request moby#28988 from vdemeester/28985-dont-validate-hostname
Remove hostname validation as it seems to break users
2 parents 51c5718 + ef39256 commit 3cb310c

File tree

12 files changed

+27
-86
lines changed

12 files changed

+27
-86
lines changed

api/server/router/container/backend.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,17 @@ type copyBackend interface {
3232

3333
// stateBackend includes functions to implement to provide container state lifecycle functionality.
3434
type stateBackend interface {
35-
ContainerCreate(config types.ContainerCreateConfig, validateHostname bool) (container.ContainerCreateCreatedBody, error)
35+
ContainerCreate(config types.ContainerCreateConfig) (container.ContainerCreateCreatedBody, error)
3636
ContainerKill(name string, sig uint64) error
3737
ContainerPause(name string) error
3838
ContainerRename(oldName, newName string) error
3939
ContainerResize(name string, height, width int) error
4040
ContainerRestart(name string, seconds *int) error
4141
ContainerRm(name string, config *types.ContainerRmConfig) error
42-
ContainerStart(name string, hostConfig *container.HostConfig, validateHostname bool, checkpoint string, checkpointDir string) error
42+
ContainerStart(name string, hostConfig *container.HostConfig, checkpoint string, checkpointDir string) error
4343
ContainerStop(name string, seconds *int) error
4444
ContainerUnpause(name string) error
45-
ContainerUpdate(name string, hostConfig *container.HostConfig, validateHostname bool) (container.ContainerUpdateOKBody, error)
45+
ContainerUpdate(name string, hostConfig *container.HostConfig) (container.ContainerUpdateOKBody, error)
4646
ContainerWait(name string, timeout time.Duration) (int, error)
4747
}
4848

api/server/router/container/container_routes.go

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,7 @@ func (s *containerRouter) postContainersStart(ctx context.Context, w http.Respon
156156

157157
checkpoint := r.Form.Get("checkpoint")
158158
checkpointDir := r.Form.Get("checkpoint-dir")
159-
validateHostname := versions.GreaterThanOrEqualTo(version, "1.24")
160-
if err := s.backend.ContainerStart(vars["name"], hostConfig, validateHostname, checkpoint, checkpointDir); err != nil {
159+
if err := s.backend.ContainerStart(vars["name"], hostConfig, checkpoint, checkpointDir); err != nil {
161160
return err
162161
}
163162

@@ -332,7 +331,6 @@ func (s *containerRouter) postContainerUpdate(ctx context.Context, w http.Respon
332331
return err
333332
}
334333

335-
version := httputils.VersionFromContext(ctx)
336334
var updateConfig container.UpdateConfig
337335

338336
decoder := json.NewDecoder(r.Body)
@@ -346,8 +344,7 @@ func (s *containerRouter) postContainerUpdate(ctx context.Context, w http.Respon
346344
}
347345

348346
name := vars["name"]
349-
validateHostname := versions.GreaterThanOrEqualTo(version, "1.24")
350-
resp, err := s.backend.ContainerUpdate(name, hostConfig, validateHostname)
347+
resp, err := s.backend.ContainerUpdate(name, hostConfig)
351348
if err != nil {
352349
return err
353350
}
@@ -372,14 +369,13 @@ func (s *containerRouter) postContainersCreate(ctx context.Context, w http.Respo
372369
version := httputils.VersionFromContext(ctx)
373370
adjustCPUShares := versions.LessThan(version, "1.19")
374371

375-
validateHostname := versions.GreaterThanOrEqualTo(version, "1.24")
376372
ccr, err := s.backend.ContainerCreate(types.ContainerCreateConfig{
377373
Name: name,
378374
Config: config,
379375
HostConfig: hostConfig,
380376
NetworkingConfig: networkingConfig,
381377
AdjustCPUShares: adjustCPUShares,
382-
}, validateHostname)
378+
})
383379
if err != nil {
384380
return err
385381
}

builder/builder.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,15 @@ type Backend interface {
116116
// ContainerAttachRaw attaches to container.
117117
ContainerAttachRaw(cID string, stdin io.ReadCloser, stdout, stderr io.Writer, stream bool) error
118118
// ContainerCreate creates a new Docker container and returns potential warnings
119-
ContainerCreate(config types.ContainerCreateConfig, validateHostname bool) (container.ContainerCreateCreatedBody, error)
119+
ContainerCreate(config types.ContainerCreateConfig) (container.ContainerCreateCreatedBody, error)
120120
// ContainerRm removes a container specified by `id`.
121121
ContainerRm(name string, config *types.ContainerRmConfig) error
122122
// Commit creates a new Docker image from an existing Docker container.
123123
Commit(string, *backend.ContainerCommitConfig) (string, error)
124124
// ContainerKill stops the container execution abruptly.
125125
ContainerKill(containerID string, sig uint64) error
126126
// ContainerStart starts a new container
127-
ContainerStart(containerID string, hostConfig *container.HostConfig, validateHostname bool, checkpoint string, checkpointDir string) error
127+
ContainerStart(containerID string, hostConfig *container.HostConfig, checkpoint string, checkpointDir string) error
128128
// ContainerWait stops processing until the given container is stopped.
129129
ContainerWait(containerID string, timeout time.Duration) (int, error)
130130
// ContainerUpdateCmdOnBuild updates container.Path and container.Args

builder/dockerfile/dispatchers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ func workdir(b *Builder, args []string, attributes map[string]bool, original str
307307
return nil
308308
}
309309

310-
container, err := b.docker.ContainerCreate(types.ContainerCreateConfig{Config: b.runConfig}, true)
310+
container, err := b.docker.ContainerCreate(types.ContainerCreateConfig{Config: b.runConfig})
311311
if err != nil {
312312
return err
313313
}

builder/dockerfile/internals.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ func (b *Builder) runContextCommand(args []string, allowRemote bool, allowLocalD
180180
return nil
181181
}
182182

183-
container, err := b.docker.ContainerCreate(types.ContainerCreateConfig{Config: b.runConfig}, true)
183+
container, err := b.docker.ContainerCreate(types.ContainerCreateConfig{Config: b.runConfig})
184184
if err != nil {
185185
return err
186186
}
@@ -496,7 +496,7 @@ func (b *Builder) create() (string, error) {
496496
c, err := b.docker.ContainerCreate(types.ContainerCreateConfig{
497497
Config: b.runConfig,
498498
HostConfig: hostConfig,
499-
}, true)
499+
})
500500
if err != nil {
501501
return "", err
502502
}
@@ -537,7 +537,7 @@ func (b *Builder) run(cID string) (err error) {
537537
}
538538
}()
539539

540-
if err := b.docker.ContainerStart(cID, nil, true, "", ""); err != nil {
540+
if err := b.docker.ContainerStart(cID, nil, "", ""); err != nil {
541541
close(finished)
542542
if cancelErr := <-cancelErrCh; cancelErr != nil {
543543
logrus.Debugf("Build cancelled (%v) and got an error from ContainerStart: %v",

daemon/cluster/executor/backend.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ type Backend interface {
2828
FindNetwork(idName string) (libnetwork.Network, error)
2929
SetupIngress(req clustertypes.NetworkCreateRequest, nodeIP string) error
3030
PullImage(ctx context.Context, image, tag string, metaHeaders map[string][]string, authConfig *types.AuthConfig, outStream io.Writer) error
31-
CreateManagedContainer(config types.ContainerCreateConfig, validateHostname bool) (container.ContainerCreateCreatedBody, error)
32-
ContainerStart(name string, hostConfig *container.HostConfig, validateHostname bool, checkpoint string, checkpointDir string) error
31+
CreateManagedContainer(config types.ContainerCreateConfig) (container.ContainerCreateCreatedBody, error)
32+
ContainerStart(name string, hostConfig *container.HostConfig, checkpoint string, checkpointDir string) error
3333
ContainerStop(name string, seconds *int) error
3434
ContainerLogs(context.Context, string, *backend.ContainerLogsConfig, chan struct{}) error
3535
ConnectContainerToNetwork(containerName, networkName string, endpointConfig *network.EndpointSettings) error

daemon/cluster/executor/container/adapter.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@ import (
1111

1212
"github.com/Sirupsen/logrus"
1313
"github.com/docker/distribution/digest"
14-
"github.com/docker/docker/api/server/httputils"
1514
"github.com/docker/docker/api/types"
1615
"github.com/docker/docker/api/types/backend"
1716
containertypes "github.com/docker/docker/api/types/container"
1817
"github.com/docker/docker/api/types/events"
19-
"github.com/docker/docker/api/types/versions"
2018
"github.com/docker/docker/daemon/cluster/convert"
2119
executorpkg "github.com/docker/docker/daemon/cluster/executor"
2220
"github.com/docker/docker/reference"
@@ -215,16 +213,14 @@ func (c *containerAdapter) waitForDetach(ctx context.Context) error {
215213
func (c *containerAdapter) create(ctx context.Context) error {
216214
var cr containertypes.ContainerCreateCreatedBody
217215
var err error
218-
version := httputils.VersionFromContext(ctx)
219-
validateHostname := versions.GreaterThanOrEqualTo(version, "1.24")
220216

221217
if cr, err = c.backend.CreateManagedContainer(types.ContainerCreateConfig{
222218
Name: c.container.name(),
223219
Config: c.container.config(),
224220
HostConfig: c.container.hostConfig(),
225221
// Use the first network in container create
226222
NetworkingConfig: c.container.createNetworkingConfig(),
227-
}, validateHostname); err != nil {
223+
}); err != nil {
228224
return err
229225
}
230226

@@ -263,9 +259,7 @@ func (c *containerAdapter) create(ctx context.Context) error {
263259
}
264260

265261
func (c *containerAdapter) start(ctx context.Context) error {
266-
version := httputils.VersionFromContext(ctx)
267-
validateHostname := versions.GreaterThanOrEqualTo(version, "1.24")
268-
return c.backend.ContainerStart(c.container.name(), nil, validateHostname, "", "")
262+
return c.backend.ContainerStart(c.container.name(), nil, "", "")
269263
}
270264

271265
func (c *containerAdapter) inspect(ctx context.Context) (types.ContainerJSON, error) {

daemon/container.go

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package daemon
33
import (
44
"fmt"
55
"path/filepath"
6-
"regexp"
76
"time"
87

98
"github.com/docker/docker/api/errors"
@@ -204,7 +203,7 @@ func (daemon *Daemon) setHostConfig(container *container.Container, hostConfig *
204203

205204
// verifyContainerSettings performs validation of the hostconfig and config
206205
// structures.
207-
func (daemon *Daemon) verifyContainerSettings(hostConfig *containertypes.HostConfig, config *containertypes.Config, update bool, validateHostname bool) ([]string, error) {
206+
func (daemon *Daemon) verifyContainerSettings(hostConfig *containertypes.HostConfig, config *containertypes.Config, update bool) ([]string, error) {
208207

209208
// First perform verification of settings common across all platforms.
210209
if config != nil {
@@ -222,18 +221,6 @@ func (daemon *Daemon) verifyContainerSettings(hostConfig *containertypes.HostCon
222221
}
223222
}
224223

225-
// Validate if the given hostname is RFC 1123 (https://tools.ietf.org/html/rfc1123) compliant.
226-
if validateHostname && len(config.Hostname) > 0 {
227-
// RFC1123 specifies that 63 bytes is the maximium length
228-
// Windows has the limitation of 63 bytes in length
229-
// Linux hostname is limited to HOST_NAME_MAX=64, not including the terminating null byte.
230-
// We limit the length to 63 bytes here to match RFC1035 and RFC1123.
231-
matched, _ := regexp.MatchString("^(([[:alnum:]]|[[:alnum:]][[:alnum:]\\-]*[[:alnum:]])\\.)*([[:alnum:]]|[[:alnum:]][[:alnum:]\\-]*[[:alnum:]])$", config.Hostname)
232-
if len(config.Hostname) > 63 || !matched {
233-
return nil, fmt.Errorf("invalid hostname format: %s", config.Hostname)
234-
}
235-
}
236-
237224
// Validate if Env contains empty variable or not (e.g., ``, `=foo`)
238225
for _, env := range config.Env {
239226
if _, err := opts.ValidateEnv(env); err != nil {

daemon/create.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,22 @@ import (
2525
)
2626

2727
// CreateManagedContainer creates a container that is managed by a Service
28-
func (daemon *Daemon) CreateManagedContainer(params types.ContainerCreateConfig, validateHostname bool) (containertypes.ContainerCreateCreatedBody, error) {
29-
return daemon.containerCreate(params, true, validateHostname)
28+
func (daemon *Daemon) CreateManagedContainer(params types.ContainerCreateConfig) (containertypes.ContainerCreateCreatedBody, error) {
29+
return daemon.containerCreate(params, true)
3030
}
3131

3232
// ContainerCreate creates a regular container
33-
func (daemon *Daemon) ContainerCreate(params types.ContainerCreateConfig, validateHostname bool) (containertypes.ContainerCreateCreatedBody, error) {
34-
return daemon.containerCreate(params, false, validateHostname)
33+
func (daemon *Daemon) ContainerCreate(params types.ContainerCreateConfig) (containertypes.ContainerCreateCreatedBody, error) {
34+
return daemon.containerCreate(params, false)
3535
}
3636

37-
func (daemon *Daemon) containerCreate(params types.ContainerCreateConfig, managed bool, validateHostname bool) (containertypes.ContainerCreateCreatedBody, error) {
37+
func (daemon *Daemon) containerCreate(params types.ContainerCreateConfig, managed bool) (containertypes.ContainerCreateCreatedBody, error) {
3838
start := time.Now()
3939
if params.Config == nil {
4040
return containertypes.ContainerCreateCreatedBody{}, fmt.Errorf("Config cannot be empty in order to create a container")
4141
}
4242

43-
warnings, err := daemon.verifyContainerSettings(params.HostConfig, params.Config, false, validateHostname)
43+
warnings, err := daemon.verifyContainerSettings(params.HostConfig, params.Config, false)
4444
if err != nil {
4545
return containertypes.ContainerCreateCreatedBody{Warnings: warnings}, err
4646
}

daemon/start.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
)
2020

2121
// ContainerStart starts a container.
22-
func (daemon *Daemon) ContainerStart(name string, hostConfig *containertypes.HostConfig, validateHostname bool, checkpoint string, checkpointDir string) error {
22+
func (daemon *Daemon) ContainerStart(name string, hostConfig *containertypes.HostConfig, checkpoint string, checkpointDir string) error {
2323
if checkpoint != "" && !daemon.HasExperimental() {
2424
return apierrors.NewBadRequestError(fmt.Errorf("checkpoint is only supported in experimental mode"))
2525
}
@@ -73,7 +73,7 @@ func (daemon *Daemon) ContainerStart(name string, hostConfig *containertypes.Hos
7373

7474
// check if hostConfig is in line with the current system settings.
7575
// It may happen cgroups are umounted or the like.
76-
if _, err = daemon.verifyContainerSettings(container.HostConfig, nil, false, validateHostname); err != nil {
76+
if _, err = daemon.verifyContainerSettings(container.HostConfig, nil, false); err != nil {
7777
return err
7878
}
7979
// Adapt for old containers in case we have updates in this function and

0 commit comments

Comments
 (0)