Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making SSL default #1336

Merged
merged 2 commits into from
Jun 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ __BACKWARDS INCOMPATIBILITIES:__
eval-status -monitor`.
* config: Consul configuration has been moved from client options map to
consul block under client configuration
* driver/docker: Enabled SSL by default for pulling images from docker
registries. [GH-1336]

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

Expand Down
44 changes: 23 additions & 21 deletions client/driver/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,7 @@ type DockerDriverConfig struct {
ShmSize int64 `mapstructure:"shm_size"` // Size of /dev/shm of the container in bytes
}

func (c *DockerDriverConfig) Init() error {
if strings.Contains(c.ImageName, "https://") {
c.SSL = true
c.ImageName = strings.Replace(c.ImageName, "https://", "", 1)
}

return nil
}

// Validate validates a docker driver config
func (c *DockerDriverConfig) Validate() error {
if c.ImageName == "" {
return fmt.Errorf("Docker Driver needs an image name")
Expand All @@ -118,6 +110,24 @@ func (c *DockerDriverConfig) Validate() error {
return nil
}

// NewDockerDriverConfig returns a docker driver config by parsing the HCL
// config
func NewDockerDriverConfig(task *structs.Task) (*DockerDriverConfig, error) {
var driverConfig DockerDriverConfig
driverConfig.SSL = true
if err := mapstructure.WeakDecode(task.Config, &driverConfig); err != nil {
return nil, err
}
if strings.Contains(driverConfig.ImageName, "https://") {
driverConfig.ImageName = strings.Replace(driverConfig.ImageName, "https://", "", 1)
}

if err := driverConfig.Validate(); err != nil {
return nil, err
}
return &driverConfig, nil
}

type dockerPID struct {
Version string
ImageID string
Expand Down Expand Up @@ -657,16 +667,8 @@ func (d *DockerDriver) loadImage(driverConfig *DockerDriverConfig, client *docke
}

func (d *DockerDriver) Start(ctx *ExecContext, task *structs.Task) (DriverHandle, error) {
var driverConfig DockerDriverConfig
if err := mapstructure.WeakDecode(task.Config, &driverConfig); err != nil {
return nil, err
}

if err := driverConfig.Init(); err != nil {
return nil, err
}

if err := driverConfig.Validate(); err != nil {
driverConfig, err := NewDockerDriverConfig(task)
if err != nil {
return nil, err
}

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

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

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

config, err := d.createContainer(ctx, task, &driverConfig, ss.Addr)
config, err := d.createContainer(ctx, task, driverConfig, ss.Addr)
if err != nil {
d.logger.Printf("[ERR] driver.docker: failed to create container configuration for image %s: %s", image, err)
pluginClient.Kill()
Expand Down
2 changes: 1 addition & 1 deletion website/source/docs/drivers/docker.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ The following options are available for use in the job specification.
to use.

* `SSL` - (Optional) If this is set to true, Nomad uses SSL to talk to the
repository. The default value is `false`.
repository. The default value is `true`.

* `port_map` - (Optional) A key/value map of port labels (see below).

Expand Down