Skip to content

Commit

Permalink
[8.13](backport #39420) x-pack/filebeat/input/entityanalytics/provide…
Browse files Browse the repository at this point in the history
…r/azuread: fix query handling (#39461)

* x-pack/filebeat/input/entityanalytics/provider/azuread: fix query handling (#39420)

(cherry picked from commit f5bb642)

* remove irrelevant backport changes
  * changelog entries
  * aws import

---------

Co-authored-by: Dan Kortschak <dan.kortschak@elastic.co>
  • Loading branch information
mergify[bot] and efd6 authored May 9, 2024
1 parent 31cc4b2 commit fe3d4cd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff]
- Fix handling of Juniper SRX structured data when there is no leading junos element. {issue}36270[36270] {pull}36308[36308]
- 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 EntraID query handling. {issue}39419[39419] {pull}39420[39420]

*Heartbeat*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ import (
const (
defaultAPIEndpoint = "https://graph.microsoft.com/v1.0"

defaultGroupsQuery = "$select=displayName,members"
defaultUsersQuery = "$select=accountEnabled,userPrincipalName,mail,displayName,givenName,surname,jobTitle,officeLocation,mobilePhone,businessPhones"
defaultDevicesQuery = "$select=accountEnabled,deviceId,displayName,operatingSystem,operatingSystemVersion,physicalIds,extensionAttributes,alternativeSecurityIds"
queryName = "$select"
defaultGroupsQuery = "displayName,members"
defaultUsersQuery = "accountEnabled,userPrincipalName,mail,displayName,givenName,surname,jobTitle,officeLocation,mobilePhone,businessPhones"
defaultDevicesQuery = "accountEnabled,deviceId,displayName,operatingSystem,operatingSystemVersion,physicalIds,extensionAttributes,alternativeSecurityIds"

apiGroupType = "#microsoft.graph.group"
apiUserType = "#microsoft.graph.user"
Expand Down Expand Up @@ -353,21 +354,21 @@ func New(cfg *config.C, logger *logp.Logger, auth authenticator.Authenticator) (
if err != nil {
return nil, fmt.Errorf("invalid groups URL endpoint: %w", err)
}
groupsURL.RawQuery = url.QueryEscape(formatQuery(c.Select.GroupQuery, defaultGroupsQuery))
groupsURL.RawQuery = formatQuery(queryName, c.Select.GroupQuery, defaultGroupsQuery)
f.groupsURL = groupsURL.String()

usersURL, err := url.Parse(f.conf.APIEndpoint + "/users/delta")
if err != nil {
return nil, fmt.Errorf("invalid users URL endpoint: %w", err)
}
usersURL.RawQuery = url.QueryEscape(formatQuery(c.Select.UserQuery, defaultUsersQuery))
usersURL.RawQuery = formatQuery(queryName, c.Select.UserQuery, defaultUsersQuery)
f.usersURL = usersURL.String()

devicesURL, err := url.Parse(f.conf.APIEndpoint + "/devices/delta")
if err != nil {
return nil, fmt.Errorf("invalid devices URL endpoint: %w", err)
}
devicesURL.RawQuery = url.QueryEscape(formatQuery(c.Select.DeviceQuery, defaultDevicesQuery))
devicesURL.RawQuery = formatQuery(queryName, c.Select.DeviceQuery, defaultDevicesQuery)
f.devicesURL = devicesURL.String()

// The API takes a departure from the query approach here, so we
Expand All @@ -382,11 +383,12 @@ func New(cfg *config.C, logger *logp.Logger, auth authenticator.Authenticator) (
return &f, nil
}

func formatQuery(query []string, dflt string) string {
if len(query) == 0 {
return dflt
func formatQuery(name string, query []string, dflt string) string {
q := dflt
if len(query) != 0 {
q = strings.Join(query, ",")
}
return "$select=" + strings.Join(query, ",")
return url.Values{name: []string{q}}.Encode()
}

// newUserFromAPI translates an API-representation of a user to a fetcher.User.
Expand Down

0 comments on commit fe3d4cd

Please sign in to comment.