diff --git a/nomad/structs/actions.go b/nomad/structs/actions.go index db78efd395..231c04cbd2 100644 --- a/nomad/structs/actions.go +++ b/nomad/structs/actions.go @@ -9,11 +9,16 @@ package structs import ( "errors" + "fmt" + "regexp" "slices" "github.com/hashicorp/go-multierror" ) +// validJobActionName is used to validate a action name. +var validJobActionName = regexp.MustCompile(`^[^\x00\s]{1,128}$`) + type Action struct { Name string Command string @@ -80,6 +85,9 @@ func (a *Action) Validate() error { if a.Command == "" { mErr = multierror.Append(mErr, errors.New("command cannot be empty")) } + if !validJobActionName.MatchString(a.Name) { + mErr = multierror.Append(mErr, fmt.Errorf("invalid name '%s'", a.Name)) + } return mErr.ErrorOrNil() }