Skip to content

Commit

Permalink
x-pack/filebeat/input/{cel,websocket}: prevent addition of regexp ext…
Browse files Browse the repository at this point in the history
…ention when no patterns are provided

In the case of cel, the extension was always being added, and then was
conditionally added when a pattern was configured, resulting in an
failed configuration. In the case of websocket the conditional addition
was not being performed, so no failure occured, but additional look-up
load was being added. So unify the approaches to the correct conditional
addition.
  • Loading branch information
efd6 committed Mar 4, 2024
1 parent d23b4d3 commit 87d538d
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ fields added to events containing the Beats version. {pull}37553[37553]
- Fix a race condition that could crash Filebeat with a "negative WaitGroup counter" error {pull}38094[38094]
- Prevent HTTPJSON holding response bodies between executions. {issue}35219[35219] {pull}38116[38116]
- Fix "failed processing S3 event for object key" error on aws-s3 input when key contains the "+" character {issue}38012[38012] {pull}38125[38125]
- Fix duplicated addition of regexp extension in CEL input. {pull}38181[38181]

*Heartbeat*

Expand Down
14 changes: 14 additions & 0 deletions x-pack/filebeat/input/cel/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"os"
"reflect"
"testing"
"time"

"github.com/google/go-cmp/cmp"
"golang.org/x/oauth2/google"
Expand All @@ -38,6 +39,19 @@ func TestGetProviderIsCanonical(t *testing.T) {
}
}

func TestRegexpConfig(t *testing.T) {
cfg := config{
Interval: time.Minute,
Program: `{}`,
Resource: &ResourceConfig{URL: &urlConfig{URL: &url.URL{}}},
Regexps: map[string]string{"regex_cve": `[Cc][Vv][Ee]-[0-9]{4}-[0-9]{4,7}`},
}
err := cfg.Validate()
if err != nil {
t.Errorf("failed to validate config with regexps: %v", err)
}
}

func TestIsEnabled(t *testing.T) {
type enabler interface {
isEnabled() bool
Expand Down
1 change: 0 additions & 1 deletion x-pack/filebeat/input/cel/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,6 @@ func newProgram(ctx context.Context, src, root string, client *http.Client, limi
lib.Debug(debug(log, trace)),
lib.File(mimetypes),
lib.MIME(mimetypes),
lib.Regexp(patterns),
lib.Limit(limitPolicies),
lib.Globals(map[string]interface{}{
"useragent": userAgent,
Expand Down
4 changes: 3 additions & 1 deletion x-pack/filebeat/input/websocket/cel.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,13 @@ func newProgram(ctx context.Context, src, root string, patterns map[string]*rege
lib.Try(),
lib.Debug(debug(log)),
lib.MIME(mimetypes),
lib.Regexp(patterns),
lib.Globals(map[string]interface{}{
"useragent": userAgent,
}),
}
if len(patterns) != 0 {
opts = append(opts, lib.Regexp(patterns))
}

env, err := cel.NewEnv(opts...)
if err != nil {
Expand Down
13 changes: 13 additions & 0 deletions x-pack/filebeat/input/websocket/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package websocket

import (
"fmt"
"net/url"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -119,3 +120,15 @@ func TestConfig(t *testing.T) {
})
}
}

func TestRegexpConfig(t *testing.T) {
cfg := config{
Program: `{}`,
URL: &urlConfig{URL: &url.URL{Scheme: "ws"}},
Regexps: map[string]string{"regex_cve": `[Cc][Vv][Ee]-[0-9]{4}-[0-9]{4,7}`},
}
err := cfg.Validate()
if err != nil {
t.Errorf("failed to validate config with regexps: %v", err)
}
}

0 comments on commit 87d538d

Please sign in to comment.