Skip to content

Commit e73463a

Browse files
authored
Merge pull request #1336 from hashicorp/f-default-ssl-docker-registry
Making SSL default
2 parents 49c272c + c655ba1 commit e73463a

File tree

3 files changed

+28
-22
lines changed

3 files changed

+28
-22
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ __BACKWARDS INCOMPATIBILITIES:__
66
eval-status -monitor`.
77
* config: Consul configuration has been moved from client options map to
88
consul block under client configuration
9+
* driver/docker: Enabled SSL by default for pulling images from docker
10+
registries. [GH-1336]
911

1012
IMPROVEMENTS:
1113
* core: Scheduler reuses blocked evaluations to avoid unbounded creation of
@@ -34,6 +36,8 @@ IMPROVEMENTS:
3436
if the artifact exists inside a chrooted directory [GH-1262]
3537
* driver/docker: Added a client options to set SELinux labels for container
3638
bind mounts. [GH-788]
39+
* driver/docker: Enabled SSL by default for pulling images from docker
40+
registries. [GH-1336]
3741
* server: If Consul is available, automatically bootstrap Nomad Servers
3842
using the `_nomad` service in Consul. [GH-1276]
3943

client/driver/docker.go

+23-21
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,7 @@ type DockerDriverConfig struct {
9898
ShmSize int64 `mapstructure:"shm_size"` // Size of /dev/shm of the container in bytes
9999
}
100100

101-
func (c *DockerDriverConfig) Init() error {
102-
if strings.Contains(c.ImageName, "https://") {
103-
c.SSL = true
104-
c.ImageName = strings.Replace(c.ImageName, "https://", "", 1)
105-
}
106-
107-
return nil
108-
}
109-
101+
// Validate validates a docker driver config
110102
func (c *DockerDriverConfig) Validate() error {
111103
if c.ImageName == "" {
112104
return fmt.Errorf("Docker Driver needs an image name")
@@ -118,6 +110,24 @@ func (c *DockerDriverConfig) Validate() error {
118110
return nil
119111
}
120112

113+
// NewDockerDriverConfig returns a docker driver config by parsing the HCL
114+
// config
115+
func NewDockerDriverConfig(task *structs.Task) (*DockerDriverConfig, error) {
116+
var driverConfig DockerDriverConfig
117+
driverConfig.SSL = true
118+
if err := mapstructure.WeakDecode(task.Config, &driverConfig); err != nil {
119+
return nil, err
120+
}
121+
if strings.Contains(driverConfig.ImageName, "https://") {
122+
driverConfig.ImageName = strings.Replace(driverConfig.ImageName, "https://", "", 1)
123+
}
124+
125+
if err := driverConfig.Validate(); err != nil {
126+
return nil, err
127+
}
128+
return &driverConfig, nil
129+
}
130+
121131
type dockerPID struct {
122132
Version string
123133
ImageID string
@@ -657,16 +667,8 @@ func (d *DockerDriver) loadImage(driverConfig *DockerDriverConfig, client *docke
657667
}
658668

659669
func (d *DockerDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle, error) {
660-
var driverConfig DockerDriverConfig
661-
if err := mapstructure.WeakDecode(task.Config, &driverConfig); err != nil {
662-
return nil, err
663-
}
664-
665-
if err := driverConfig.Init(); err != nil {
666-
return nil, err
667-
}
668-
669-
if err := driverConfig.Validate(); err != nil {
670+
driverConfig, err := NewDockerDriverConfig(task)
671+
if err != nil {
670672
return nil, err
671673
}
672674

@@ -683,7 +685,7 @@ func (d *DockerDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle
683685
return nil, fmt.Errorf("Failed to connect to docker daemon: %s", err)
684686
}
685687

686-
if err := d.createImage(&driverConfig, client, taskDir); err != nil {
688+
if err := d.createImage(driverConfig, client, taskDir); err != nil {
687689
return nil, fmt.Errorf("failed to create image: %v", err)
688690
}
689691

@@ -723,7 +725,7 @@ func (d *DockerDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle
723725
return nil, fmt.Errorf("failed to start syslog collector: %v", err)
724726
}
725727

726-
config, err := d.createContainer(ctx, task, &driverConfig, ss.Addr)
728+
config, err := d.createContainer(ctx, task, driverConfig, ss.Addr)
727729
if err != nil {
728730
d.logger.Printf("[ERR] driver.docker: failed to create container configuration for image %s: %s", image, err)
729731
pluginClient.Kill()

website/source/docs/drivers/docker.html.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ The following options are available for use in the job specification.
9494
to use.
9595
9696
* `SSL` - (Optional) If this is set to true, Nomad uses SSL to talk to the
97-
repository. The default value is `false`.
97+
repository. The default value is `true`.
9898
9999
* `port_map` - (Optional) A key/value map of port labels (see below).
100100

0 commit comments

Comments
 (0)