-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Filebeat CEL input - basic auth does not work #34609
Comments
Pinging @elastic/security-external-integrations (Team:Security-External Integrations) |
Thanks for finding this. The reason for the omission is in the origin of the auth code (originally from the HTTPJSON input where basic auth is handled per request and so I missed it). I need to think of a good way to thread this through to http lib, but in the meantime it is possible to work around the lack within CEL if username and password are passed into the CEL state. They can then be used to construct the request header as shown in this example. https://github.com/elastic/mito/blob/e6cd4d27d605c9a51d784926ed11cf085e59ced1/lib/http.go#L146-L164
The request can then be used with do_request. This is more involved and I will sort out a fix for the base case. |
I have a good path forward to making this work as documented. Depends on the mito/lib PR tagged above. diff --git a/x-pack/filebeat/input/cel/config.go b/x-pack/filebeat/input/cel/config.go
index 69f3512f13..13d9112b14 100644
--- a/x-pack/filebeat/input/cel/config.go
+++ b/x-pack/filebeat/input/cel/config.go
@@ -71,7 +71,7 @@ func (c config) Validate() error {
if len(c.Regexps) != 0 {
patterns = map[string]*regexp.Regexp{".": nil}
}
- _, err = newProgram(context.Background(), c.Program, root, client, nil, patterns)
+ _, err = newProgram(context.Background(), c.Program, root, client, nil, nil, patterns)
if err != nil {
return fmt.Errorf("failed to check program: %w", err)
}
diff --git a/x-pack/filebeat/input/cel/input.go b/x-pack/filebeat/input/cel/input.go
index b2a7acd41a..b9f4a2e868 100644
--- a/x-pack/filebeat/input/cel/input.go
+++ b/x-pack/filebeat/input/cel/input.go
@@ -122,7 +122,14 @@ func (input) run(env v2.Context, src *source, cursor map[string]interface{}, pub
return err
}
- prg, err := newProgram(ctx, cfg.Program, root, client, limiter, patterns)
+ var auth *lib.BasicAuth
+ if cfg.Auth.Basic.isEnabled() {
+ auth = &lib.BasicAuth{
+ Username: cfg.Auth.Basic.User,
+ Password: cfg.Auth.Basic.Password,
+ }
+ }
+ prg, err := newProgram(ctx, cfg.Program, root, client, limiter, auth, patterns)
if err != nil {
return err
}
@@ -808,7 +815,7 @@ var (
}
)
-func newProgram(ctx context.Context, src, root string, client *http.Client, limiter *rate.Limiter, patterns map[string]*regexp.Regexp) (cel.Program, error) {
+func newProgram(ctx context.Context, src, root string, client *http.Client, limiter *rate.Limiter, auth *lib.BasicAuth, patterns map[string]*regexp.Regexp) (cel.Program, error) {
opts := []cel.EnvOption{
cel.Declarations(decls.NewVar(root, decls.Dyn)),
lib.Collections(),
@@ -825,7 +832,7 @@ func newProgram(ctx context.Context, src, root string, client *http.Client, limi
}),
}
if client != nil {
- opts = append(opts, lib.HTTPWithContext(ctx, client, limiter))
+ opts = append(opts, lib.HTTPWithContext(ctx, client, limiter, auth))
}
if len(patterns) != 0 {
opts = append(opts, lib.Regexp(patterns)) |
Version: 8.6.2
Operating System: MacOS Venture 13.2.1
Discuss Forum URL:
Steps to Reproduce:
a. https://www.elastic.co/guide/en/beats/filebeat/8.6/filebeat-input-cel.html#_auth_basic_enabled
b. x-pack/filebeat/input/cel: new input #31233
a. https://github.com/elastic/beats/blob/main/x-pack/filebeat/input/cel/input.go
b.
func newClient
has logic for OAuth but not basicmetricbeat.yml
logs
The text was updated successfully, but these errors were encountered: