diff options
author | Ilya Mashchenko <ilya@netdata.cloud> | 2024-06-20 19:53:26 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-06-20 19:53:26 +0300 |
commit | 7be6a6cb3630b3372b6c65f26c254d3b6d82b665 (patch) | |
tree | 0c65e82b2adf6f5788f90d3db9250c42bd74f305 /src | |
parent | 4b01a5a836a620d8fdc72f4ce909666bc6799260 (diff) |
go.d dyncfg add job name validation (#17971)
Diffstat (limited to 'src')
-rw-r--r-- | src/go/collectors/go.d.plugin/agent/jobmgr/dyncfg.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/go/collectors/go.d.plugin/agent/jobmgr/dyncfg.go b/src/go/collectors/go.d.plugin/agent/jobmgr/dyncfg.go index 953c6db58f..404f4bf3b4 100644 --- a/src/go/collectors/go.d.plugin/agent/jobmgr/dyncfg.go +++ b/src/go/collectors/go.d.plugin/agent/jobmgr/dyncfg.go @@ -5,12 +5,14 @@ package jobmgr import ( "context" "encoding/json" + "errors" "fmt" "log/slog" "reflect" "strconv" "strings" "time" + "unicode" "github.com/netdata/netdata/go/go.d.plugin/agent/confgroup" "github.com/netdata/netdata/go/go.d.plugin/agent/functions" @@ -211,6 +213,12 @@ func (m *Manager) dyncfgConfigTest(fn functions.Function) { jn = fn.Args[2] } + if err := validateJobName(jn); err != nil { + m.Warningf("dyncfg: test: module %s: unacceptable job name '%s': %v", mn, jn, err) + m.dyncfgRespf(fn, 400, "Unacceptable job name '%s': %v.", jn, err) + return + } + creator, ok := m.Modules.Lookup(mn) if !ok { m.Warningf("dyncfg: test: module %s not found", mn) @@ -547,6 +555,12 @@ func (m *Manager) dyncfgConfigAdd(fn functions.Function) { return } + if err := validateJobName(jn); err != nil { + m.Warningf("dyncfg: add: module %s: unacceptable job name '%s': %v", mn, jn, err) + m.dyncfgRespf(fn, 400, "Unacceptable job name '%s': %v.", jn, err) + return + } + cfg, err := configFromPayload(fn) if err != nil { m.Warningf("dyncfg: add: module %s job %s: failed to create config from payload: %v", mn, jn, err) @@ -823,3 +837,16 @@ func extractJobName(id string) (string, bool) { } return id[i+1:], true } + +func validateJobName(jobName string) error { + for _, r := range jobName { + if unicode.IsSpace(r) { + return errors.New("contains spaces") + } + switch r { + case '.', ':': + return fmt.Errorf("contains '%c'", r) + } + } + return nil +} |