1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

daemon/config: Validate(): validate hosts

The config.Validate() function did not validate hosts that were configured in
the daemon.json configuration file, resulting in `--validate` to pass, but the
daemon failing to start.

before this patch:

    echo '{"hosts":["127.0.0.1:2375/path"]}' > /etc/docker/daemon.json

    dockerd --validate
    configuration OK

    dockerd
    INFO[2022-04-03T11:42:22.162366200Z] Starting up
    failed to load listeners: error parsing -H 127.0.0.1:2375/path: invalid bind address (127.0.0.1:2375/path): should not contain a path element

with this patch:

    echo '{"hosts":["127.0.0.1:2375/path"]}' > /etc/docker/daemon.json

    dockerd --validate
    unable to configure the Docker daemon with file /etc/docker/daemon.json: configuration validation from file failed: invalid bind address (127.0.0.1:2375/path): should not contain a path element

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2022-04-04 15:18:01 +02:00
parent ecbfe73193
commit a35b4ac54a
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
2 changed files with 23 additions and 0 deletions

View file

@ -601,6 +601,12 @@ func Validate(config *Config) error {
}
}
for _, h := range config.Hosts {
if _, err := opts.ValidateHost(h); err != nil {
return err
}
}
// validate platform-specific settings
return config.ValidatePlatformConfig()
}

View file

@ -336,6 +336,15 @@ func TestValidateConfigurationErrors(t *testing.T) {
},
expectedErr: "could not parse GenericResource: mixed discrete and named resources in expression 'foo=[bar 1]'",
},
{
name: "with invalid hosts",
config: &Config{
CommonConfig: CommonConfig{
Hosts: []string{"127.0.0.1:2375/path"},
},
},
expectedErr: "invalid bind address (127.0.0.1:2375/path): should not contain a path element",
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
@ -420,6 +429,14 @@ func TestValidateConfiguration(t *testing.T) {
},
},
},
{
name: "with hosts",
config: &Config{
CommonConfig: CommonConfig{
Hosts: []string{"tcp://127.0.0.1:2375"},
},
},
},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {