From 86974c511be947318ca4b274bbfbb68956a49f9c Mon Sep 17 00:00:00 2001 From: Dan Kortschak Date: Thu, 19 Oct 2023 12:34:43 +1030 Subject: [PATCH] x-pack/filebeat/input/cel: add support for digest authentication --- CHANGELOG.next.asciidoc | 1 + NOTICE.txt | 219 ++++++++++++++++++ go.mod | 2 + go.sum | 4 + .../filebeat/docs/inputs/input-cel.asciidoc | 43 +++- x-pack/filebeat/input/cel/config_auth.go | 46 +++- x-pack/filebeat/input/cel/config_test.go | 72 ++++-- x-pack/filebeat/input/cel/input.go | 14 ++ x-pack/filebeat/input/cel/input_test.go | 31 +++ 9 files changed, 408 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 37bb60d04e3f..34c861f1d494 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -240,6 +240,7 @@ is collected by it. - Add cache processor. {pull}36786[36786] - Avoid unwanted publication of Azure entity records. {pull}36753[36753] - Avoid unwanted publication of Okta entity records. {pull}36770[36770] +- Add support for Digest Authentication to CEL input. {issue}35514[35514] {pull}[] *Auditbeat* diff --git a/NOTICE.txt b/NOTICE.txt index 6ae9f58daba1..32d857819092 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -2719,6 +2719,194 @@ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +-------------------------------------------------------------------------------- +Dependency : github.com/abbot/go-http-auth +Version: v0.4.0 +Licence type (autodetected): Apache-2.0 +-------------------------------------------------------------------------------- + +Contents of probable licence file $GOMODCACHE/github.com/abbot/go-http-auth@v0.4.0/LICENSE: + + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + + -------------------------------------------------------------------------------- Dependency : github.com/aerospike/aerospike-client-go Version: v1.27.1-0.20170612174108-0f3b54da6bdc @@ -20004,6 +20192,37 @@ The above copyright notice and this permission notice shall be included in all c THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +-------------------------------------------------------------------------------- +Dependency : github.com/icholy/digest +Version: v0.1.22 +Licence type (autodetected): MIT +-------------------------------------------------------------------------------- + +Contents of probable licence file $GOMODCACHE/github.com/icholy/digest@v0.1.22/LICENSE: + +MIT License + +Copyright (c) 2020 Ilia Choly + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + + -------------------------------------------------------------------------------- Dependency : github.com/elastic/dhcp Version: v0.0.0-20200227161230-57ec251c7eb3 diff --git a/go.mod b/go.mod index e4955abcc912..10ff90039329 100644 --- a/go.mod +++ b/go.mod @@ -193,6 +193,7 @@ require ( github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/resources/armresources v1.0.0 github.com/Azure/azure-sdk-for-go/sdk/storage/azblob v1.0.0 github.com/Azure/go-autorest/autorest/adal v0.9.14 + github.com/abbot/go-http-auth v0.4.0 github.com/apache/arrow/go/v12 v12.0.1-0.20230605094802-c153c6d36ccf github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.12.17 github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.11.33 @@ -213,6 +214,7 @@ require ( github.com/googleapis/gax-go/v2 v2.7.0 github.com/gorilla/handlers v1.5.1 github.com/gorilla/mux v1.8.0 + github.com/icholy/digest v0.1.22 github.com/lestrrat-go/jwx/v2 v2.0.11 github.com/otiai10/copy v1.12.0 github.com/pierrec/lz4/v4 v4.1.16 diff --git a/go.sum b/go.sum index a1aecdb59dfd..b1faf776d400 100644 --- a/go.sum +++ b/go.sum @@ -214,6 +214,8 @@ github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMx github.com/StackExchange/wmi v1.2.1 h1:VIkavFPXSjcnS+O8yTq7NI32k0R5Aj+v39y29VYDOSA= github.com/StackExchange/wmi v1.2.1/go.mod h1:rcmrprowKIVzvc+NUiLncP2uuArMWLCbu9SBzvHz7e8= github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g= +github.com/abbot/go-http-auth v0.4.0 h1:QjmvZ5gSC7jm3Zg54DqWE/T5m1t2AfDu6QlXJT0EVT0= +github.com/abbot/go-http-auth v0.4.0/go.mod h1:Cz6ARTIzApMJDzh5bRMSUou6UMSp0IEXg9km/ci7TJM= github.com/adriansr/fsnotify v1.4.8-0.20211018144411-a81f2b630e7c h1:LpOCwE9oTg0+1Dm8rB06dKxQs7yu5tdnM6A/Zm/juQQ= github.com/adriansr/fsnotify v1.4.8-0.20211018144411-a81f2b630e7c/go.mod h1:onXS6zmTa1LJcurVsOkzywEV/Q3pdEqqu362/8OQzAI= github.com/aerospike/aerospike-client-go v1.27.1-0.20170612174108-0f3b54da6bdc h1:9iW/Fbn/R/nyUOiqo6AgwBe8uirqUIoTGF3vKG8qjoc= @@ -1196,6 +1198,8 @@ github.com/huandu/xstrings v1.0.0/go.mod h1:4qWG/gcEcfX4z/mBDHJ++3ReCw9ibxbsNJbc github.com/hudl/fargo v1.3.0/go.mod h1:y3CKSmjA+wD2gak7sUSXTAoopbhU08POFhmITJgmKTg= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= +github.com/icholy/digest v0.1.22 h1:dRIwCjtAcXch57ei+F0HSb5hmprL873+q7PoVojdMzM= +github.com/icholy/digest v0.1.22/go.mod h1:uLAeDdWKIWNFMH0wqbwchbTQOmJWhzSnL7zmqSPqEEc= github.com/imdario/mergo v0.3.4/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= github.com/imdario/mergo v0.3.6/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= diff --git a/x-pack/filebeat/docs/inputs/input-cel.asciidoc b/x-pack/filebeat/docs/inputs/input-cel.asciidoc index 35fbc4654f22..11a6248cbbb4 100644 --- a/x-pack/filebeat/docs/inputs/input-cel.asciidoc +++ b/x-pack/filebeat/docs/inputs/input-cel.asciidoc @@ -22,6 +22,7 @@ This input supports: * Auth ** Basic +** Digest ** OAuth2 * Retrieval at a configurable interval * Pagination @@ -239,7 +240,7 @@ As noted above the `cel` input provides functions, macros, and global variables In addition to the extensions provided in the packages listed above, a global variable `useragent` is also provided which gives the user CEL program access to the {beatname_lc} user-agent string. -Additionally, it supports authentication via Basic auth, HTTP Headers or oauth2. +Additionally, it supports authentication via Basic Authentication, Digest Authentication or OAuth2. Example configurations with authentication: @@ -248,10 +249,19 @@ Example configurations with authentication: filebeat.inputs: - type: cel resource.url: http://localhost - request.transforms: - - set: - target: header.Authorization - value: 'Basic aGVsbG86d29ybGQ=' + auth.basic: + user: user@domain.tld + password: P@$$W0₹D +---- + +["source","yaml",subs="attributes"] +---- +filebeat.inputs: +- type: cel + resource.url: http://localhost + auth.digest: + user: user@domain.tld + password: P@$$W0₹D ---- ["source","yaml",subs="attributes"] @@ -399,6 +409,29 @@ The user to authenticate with. The password to use. +[float] +==== `auth.digest.enabled` + +When set to `false`, disables the digest auth configuration. Default: `true`. + +NOTE: digest auth settings are disabled if either `enabled` is set to `false` or +the `auth.digest` section is missing. + +[float] +==== `auth.digest.user` + +The user to authenticate with. + +[float] +==== `auth.digest.password` + +The password to use. + +[float] +==== `auth.digest.no_reuse` + +When set to `true`, Digest Authentication challenges are not reused. + [float] ==== `auth.oauth2.enabled` diff --git a/x-pack/filebeat/input/cel/config_auth.go b/x-pack/filebeat/input/cel/config_auth.go index 5c80507fdadd..8c57ca70d088 100644 --- a/x-pack/filebeat/input/cel/config_auth.go +++ b/x-pack/filebeat/input/cel/config_auth.go @@ -24,12 +24,23 @@ import ( ) type authConfig struct { - Basic *basicAuthConfig `config:"basic"` - OAuth2 *oAuth2Config `config:"oauth2"` + Basic *basicAuthConfig `config:"basic"` + Digest *digestAuthConfig `config:"digest"` + OAuth2 *oAuth2Config `config:"oauth2"` } func (c authConfig) Validate() error { - if c.Basic.isEnabled() && c.OAuth2.isEnabled() { + var n int + if c.Basic.isEnabled() { + n++ + } + if c.Digest.isEnabled() { + n++ + } + if c.OAuth2.isEnabled() { + n++ + } + if n > 1 { return errors.New("only one kind of auth can be enabled") } return nil @@ -41,7 +52,7 @@ type basicAuthConfig struct { Password string `config:"password"` } -// IsEnabled returns true if the `enable` field is set to true in the yaml. +// isEnabled returns true if the `enable` field is set to true in the yaml. func (b *basicAuthConfig) isEnabled() bool { return b != nil && (b.Enabled == nil || *b.Enabled) } @@ -59,6 +70,31 @@ func (b *basicAuthConfig) Validate() error { return nil } +type digestAuthConfig struct { + Enabled *bool `config:"enabled"` + User string `config:"user"` + Password string `config:"password"` + NoReuse *bool `config:no_reuse"` +} + +// isEnabled returns true if the `enable` field is set to true in the yaml. +func (b *digestAuthConfig) isEnabled() bool { + return b != nil && (b.Enabled == nil || *b.Enabled) +} + +// Validate checks if oauth2 config is valid. +func (b *digestAuthConfig) Validate() error { + if !b.isEnabled() { + return nil + } + + if b.User == "" || b.Password == "" { + return errors.New("both user and password must be set") + } + + return nil +} + // An oAuth2Provider represents a supported oauth provider. type oAuth2Provider string @@ -107,7 +143,7 @@ type oAuth2Config struct { OktaJWKJSON common.JSONBlob `config:"okta.jwk_json"` } -// IsEnabled returns true if the `enable` field is set to true in the yaml. +// isEnabled returns true if the `enable` field is set to true in the yaml. func (o *oAuth2Config) isEnabled() bool { return o != nil && (o.Enabled == nil || *o.Enabled) } diff --git a/x-pack/filebeat/input/cel/config_test.go b/x-pack/filebeat/input/cel/config_test.go index e19c08399cbf..988acbefaf84 100644 --- a/x-pack/filebeat/input/cel/config_test.go +++ b/x-pack/filebeat/input/cel/config_test.go @@ -39,26 +39,45 @@ func TestGetProviderIsCanonical(t *testing.T) { } func TestIsEnabled(t *testing.T) { - oauth2 := oAuth2Config{} - if !oauth2.isEnabled() { - t.Errorf("OAuth2 not enabled by default") + type enabler interface { + isEnabled() bool + take(*bool) } + for _, test := range []struct { + name string + auth enabler + }{ + {name: "basic", auth: &basicAuthConfig{}}, + {name: "digest", auth: &digestAuthConfig{}}, + {name: "OAuth2", auth: &oAuth2Config{}}, + } { + t.Run(test.name, func(t *testing.T) { + if !test.auth.isEnabled() { + t.Errorf("auth not enabled by default") + } - var enabled bool - for i := 0; i < 4; i++ { - oauth2.Enabled = &enabled - if got := oauth2.isEnabled(); got != enabled { - t.Errorf("unexpected OAuth2 enabled state on iteration %d: got:%t want:%t", i, got, enabled) - } - enabled = !enabled - } + var enabled bool + for i := 0; i < 4; i++ { + test.auth.take(&enabled) + if got := test.auth.isEnabled(); got != enabled { + t.Errorf("unexpected auth enabled state on iteration %d: got:%t want:%t", i, got, enabled) + } + enabled = !enabled + } - oauth2.Enabled = nil - if !oauth2.isEnabled() { - t.Errorf("OAuth2 not enabled if nilled") + test.auth.take(nil) + if !test.auth.isEnabled() { + t.Errorf("auth not enabled if nilled") + } + }) } } +// take methods are for testing only. +func (c *basicAuthConfig) take(on *bool) { c.Enabled = on } +func (c *digestAuthConfig) take(on *bool) { c.Enabled = on } +func (c *oAuth2Config) take(on *bool) { c.Enabled = on } + func TestOAuth2GetTokenURL(t *testing.T) { const host = "http://localhost" for _, test := range []struct { @@ -143,6 +162,31 @@ var oAuth2ValidationTests = []struct { }, }, }, + { + name: "can't_set_oauth2_and_digest_auth_together", + wantErr: errors.New("only one kind of auth can be enabled accessing 'auth'"), + input: map[string]interface{}{ + "auth.digest.user": "user", + "auth.digest.password": "pass", + "auth.oauth2": map[string]interface{}{ + "token_url": "localhost", + "client": map[string]interface{}{ + "id": "a_client_id", + "secret": "a_client_secret", + }, + }, + }, + }, + { + name: "can't_set_basic_and_digest_auth_together", + wantErr: errors.New("only one kind of auth can be enabled accessing 'auth'"), + input: map[string]interface{}{ + "auth.basic.user": "user", + "auth.basic.password": "pass", + "auth.digest.user": "user", + "auth.digest.password": "pass", + }, + }, { name: "can_set_oauth2_and_basic_auth_together_if_oauth2_is_disabled", input: map[string]interface{}{ diff --git a/x-pack/filebeat/input/cel/input.go b/x-pack/filebeat/input/cel/input.go index ea4958b9c30e..499ae97f7fac 100644 --- a/x-pack/filebeat/input/cel/input.go +++ b/x-pack/filebeat/input/cel/input.go @@ -24,6 +24,7 @@ import ( "time" retryablehttp "github.com/hashicorp/go-retryablehttp" + "github.com/icholy/digest" "github.com/rcrowley/go-metrics" "go.elastic.co/ecszap" "go.uber.org/zap" @@ -688,6 +689,19 @@ func newClient(ctx context.Context, cfg config, log *logp.Logger) (*http.Client, return nil, err } + if cfg.Auth.Digest.isEnabled() { + var noReuse bool + if cfg.Auth.Digest.NoReuse != nil { + noReuse = *cfg.Auth.Digest.NoReuse + } + c.Transport = &digest.Transport{ + Transport: c.Transport, + Username: cfg.Auth.Digest.User, + Password: cfg.Auth.Digest.Password, + NoReuse: noReuse, + } + } + if cfg.Resource.Tracer != nil { w := zapcore.AddSync(cfg.Resource.Tracer) go func() { diff --git a/x-pack/filebeat/input/cel/input_test.go b/x-pack/filebeat/input/cel/input_test.go index bc0cf1714713..74ae5932ef8f 100644 --- a/x-pack/filebeat/input/cel/input_test.go +++ b/x-pack/filebeat/input/cel/input_test.go @@ -7,6 +7,7 @@ package cel import ( "context" + "flag" "fmt" "io" "math/rand" @@ -31,8 +32,11 @@ import ( "github.com/elastic/elastic-agent-libs/mapstr" ) +var runRemote = flag.Bool("run_remote", false, "run tests using remote endpoints") + var inputTests = []struct { name string + remote bool server func(*testing.T, http.HandlerFunc, map[string]interface{}) handler http.HandlerFunc config map[string]interface{} @@ -1055,6 +1059,30 @@ var inputTests = []struct { }, // Authenticated access tests. + { + { + // Test case modelled on `curl --digest -u test_user:secret_password https://httpbin.org/digest-auth/auth/test_user/secret_password/md5`. + name: "digest_remote", + remote: true, + server: func(_ *testing.T, _ http.HandlerFunc, _ map[string]interface{}) {}, + config: map[string]interface{}{ + "resource.url": "https://httpbin.org/digest-auth/auth/test_user/secret_password/md5", + "interval": 1, + "auth.digest.user": "test_user", + "auth.digest.password": "secret_password", + "program": ` + bytes(get(state.url).Body).as(body, { + "events": [body.decode_json()] + }) + `, + }, + want: []map[string]interface{}{ + { + "authenticated": true, + "user": "test_user", + }, + }, + }, { name: "OAuth2", server: func(t *testing.T, h http.HandlerFunc, config map[string]interface{}) { @@ -1248,6 +1276,9 @@ func TestInput(t *testing.T) { if reason, skip := skipOnWindows[test.name]; runtime.GOOS == "windows" && skip { t.Skip(reason) } + if test.remote && !*runRemote { + t.Skip("skipping remote endpoint test") + } if test.server != nil { test.server(t, test.handler, test.config)