From f4529485563924462dbdccdd1b4cacbd9d68616e Mon Sep 17 00:00:00 2001 From: Phil Renaud Date: Thu, 12 Dec 2024 15:58:26 -0600 Subject: [PATCH] Character restrictions in action names were unduly oppressive (#24642) * Character restrictions in action names were unduly oppressive * OK but what about SOME oppression * Test updates for our new action name rules --- .changelog/24642.txt | 3 +++ nomad/structs/actions.go | 4 ++-- nomad/structs/actions_test.go | 22 +++++++++++++++++++--- 3 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 .changelog/24642.txt diff --git a/.changelog/24642.txt b/.changelog/24642.txt new file mode 100644 index 000000000..ef21ae4af --- /dev/null +++ b/.changelog/24642.txt @@ -0,0 +1,3 @@ +```release-note:improvement +actions: Nomad Actions names now accept a wider range of names +``` diff --git a/nomad/structs/actions.go b/nomad/structs/actions.go index 2791d825e..231c04cbd 100644 --- a/nomad/structs/actions.go +++ b/nomad/structs/actions.go @@ -16,8 +16,8 @@ import ( "github.com/hashicorp/go-multierror" ) -// validJobActionName is used to validate a job action name. -var validJobActionName = regexp.MustCompile("^[a-zA-Z0-9-]{1,128}$") +// validJobActionName is used to validate a action name. +var validJobActionName = regexp.MustCompile(`^[^\x00\s]{1,128}$`) type Action struct { Name string diff --git a/nomad/structs/actions_test.go b/nomad/structs/actions_test.go index 3c7e20714..03102362d 100644 --- a/nomad/structs/actions_test.go +++ b/nomad/structs/actions_test.go @@ -178,12 +178,28 @@ func TestAction_Validate(t *testing.T) { expectedError: errors.New(`invalid name 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa'`), }, { - name: "invalid character name", + name: "invalid character name with spaces", inputAction: &Action{ - Name: `\//?|?|?%&%@$&£@$)`, + Name: "invalid name with spaces", Command: "env", }, - expectedError: errors.New(`invalid name '\//?|?|?%&%@$&£@$)'`), + expectedError: errors.New(`invalid name 'invalid name with spaces'`), + }, + { + name: "invalid character name with nulls", + inputAction: &Action{ + Name: "invalid\x00name", + Command: "env", + }, + expectedError: fmt.Errorf("1 error occurred:\n\t* invalid name 'invalid\x00name'\n\n"), // had to use fmt.Errorf to show the null character + }, + { + name: "Emoji characters are valid", + inputAction: &Action{ + Name: "🇳🇴🇲🇦🇩", + Command: "env", + }, + expectedError: nil, }, { name: "valid",