Skip to content

Commit

Permalink
[8.13](backport #38962) x-pack/filebeat/input/{cel,httpjson}: fix oau…
Browse files Browse the repository at this point in the history
…th2 config validation (#38995)

* x-pack/filebeat/input/{cel,httpjson}: fix oauth2 config validation (#38962)

The logic for validation assumed that client.id and client.secret must
be present, but this is not the case for password grant, so relax the
requirement.

(cherry picked from commit aae9185)

* remove irrelevant changelog entries

---------

Co-authored-by: Dan Kortschak <[email protected]>
  • Loading branch information
mergify[bot] and efd6 authored Apr 17, 2024
1 parent ff392ca commit 851159a
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff]
- Fix Filebeat Cisco module with missing escape character {issue}36325[36325] {pull}36326[36326]
- Added a fix for Crowdstrike pipeline handling process arrays {pull}36496[36496]
- Fix indexing failures by re-enabling event normalisation in netflow input. {issue}38703[38703] {pull}38780[38780]
- Fix config validation for CEL and HTTPJSON inputs when using password grant authentication and `client.id` or `client.secret` are not present. {pull}38962[38962]

*Heartbeat*

Expand Down
6 changes: 3 additions & 3 deletions x-pack/filebeat/input/cel/config_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,12 +263,12 @@ func (o *oAuth2Config) Validate() error {
case oAuth2ProviderOkta:
return o.validateOktaProvider()
case oAuth2ProviderDefault:
if o.TokenURL == "" || o.ClientID == "" || o.ClientSecret == nil {
return errors.New("both token_url and client credentials must be provided")
}
if (o.User != "" && o.Password == "") || (o.User == "" && o.Password != "") {
return errors.New("both user and password credentials must be provided")
}
if o.TokenURL == "" || ((o.ClientID == "" || o.ClientSecret == nil) && (o.User == "" || o.Password == "")) {
return errors.New("both token_url and client credentials must be provided")
}
default:
return fmt.Errorf("unknown provider %q", o.getProvider())
}
Expand Down
10 changes: 10 additions & 0 deletions x-pack/filebeat/input/cel/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,16 @@ var oAuth2ValidationTests = []struct {
},
},
},
{
name: "if_password_is_set_credentials_may_be_missing_for_user-password_authentication",
input: map[string]interface{}{
"auth.oauth2": map[string]interface{}{
"user": "a_client_user",
"password": "a_client_password",
"token_url": "localhost",
},
},
},
{
name: "must_fail_with_an_unknown_provider",
wantErr: errors.New("unknown provider \"unknown\" accessing 'auth.oauth2'"),
Expand Down
6 changes: 3 additions & 3 deletions x-pack/filebeat/input/httpjson/config_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,12 @@ func (o *oAuth2Config) Validate() error {
case oAuth2ProviderOkta:
return o.validateOktaProvider()
case oAuth2ProviderDefault:
if o.TokenURL == "" || o.ClientID == "" || o.ClientSecret == nil {
return errors.New("both token_url and client credentials must be provided")
}
if (o.User != "" && o.Password == "") || (o.User == "" && o.Password != "") {
return errors.New("both user and password credentials must be provided")
}
if o.TokenURL == "" || ((o.ClientID == "" || o.ClientSecret == nil) && (o.User == "" || o.Password == "")) {
return errors.New("both token_url and client credentials must be provided")
}
default:
return fmt.Errorf("unknown provider %q", o.getProvider())
}
Expand Down
10 changes: 10 additions & 0 deletions x-pack/filebeat/input/httpjson/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,16 @@ func TestConfigOauth2Validation(t *testing.T) {
},
},
},
{
name: "if password is set credentials may be missing for user-password authentication",
input: map[string]interface{}{
"auth.oauth2": map[string]interface{}{
"user": "a_client_user",
"password": "a_client_password",
"token_url": "localhost",
},
},
},
{
name: "must fail with an unknown provider",
expectedErr: "unknown provider \"unknown\" accessing 'auth.oauth2'",
Expand Down

0 comments on commit 851159a

Please sign in to comment.