diff --git a/nomad/structs/structs.go b/nomad/structs/structs.go index 64039cf511f..761b3d88dd1 100644 --- a/nomad/structs/structs.go +++ b/nomad/structs/structs.go @@ -1741,6 +1741,9 @@ func (t *Task) Validate() error { if t.Name == "" { mErr.Errors = append(mErr.Errors, errors.New("Missing task name")) } + if strings.ContainsAny(t.Name, `/\`) { + mErr.Errors = append(mErr.Errors, errors.New("Task name can not include slashes")) + } if t.Driver == "" { mErr.Errors = append(mErr.Errors, errors.New("Missing task driver")) } diff --git a/nomad/structs/structs_test.go b/nomad/structs/structs_test.go index 01b828ae835..e60ceadcfa7 100644 --- a/nomad/structs/structs_test.go +++ b/nomad/structs/structs_test.go @@ -258,6 +258,13 @@ func TestTask_Validate(t *testing.T) { t.Fatalf("err: %s", err) } + task = &Task{Name: "web/foo"} + err = task.Validate() + mErr = err.(*multierror.Error) + if !strings.Contains(mErr.Errors[0].Error(), "slashes") { + t.Fatalf("err: %s", err) + } + task = &Task{ Name: "web", Driver: "docker",