Skip to content

Commit

Permalink
[8.15](backport #40487) x-pack/filebeat/input/entityanalytics/provide…
Browse files Browse the repository at this point in the history
…r/azuread: fix configuration ordering (#40493)

* x-pack/filebeat/input/entityanalytics/provider/azuread: fix configuration ordering (#40487)

Previously, the configuration was eager, this caused a panic when the request
trace logging option was turned on since it was started without a context.

Move the construction of components to when we have all the parts we need.

(cherry picked from commit dd73639)

* remove irrelevant changelog entry

---------

Co-authored-by: Dan Kortschak <[email protected]>
  • Loading branch information
mergify[bot] and efd6 authored Aug 13, 2024
1 parent c3c40c6 commit 79206dd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff]
- Updated Websocket input title to align with existing inputs {pull}39006[39006]
- Relax requirements in Okta entity analytics provider user and device profile data shape. {pull}40359[40359]
- Fix bug in Okta entity analytics rate limit logic. {issue}40106[40106] {pull}40267[40267]
- Fix order of configuration for EntraID entity analytics provider. {pull}40487[40487]

*Heartbeat*

Expand Down
26 changes: 15 additions & 11 deletions x-pack/filebeat/input/entityanalytics/provider/azuread/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ var _ provider.Provider = &azure{}
type azure struct {
*kvstore.Manager

cfg *config.C
conf conf

metrics *inputMetrics
Expand Down Expand Up @@ -74,8 +75,20 @@ func (p *azure) Test(testCtx v2.TestContext) error {
func (p *azure) Run(inputCtx v2.Context, store *kvstore.Store, client beat.Client) error {
p.logger = inputCtx.Logger.With("tenant_id", p.conf.TenantID, "provider", Name)
p.ctx = inputCtx

var err error
p.auth, err = oauth2.New(p.cfg, p.Manager.Logger)
if err != nil {
return fmt.Errorf("unable to create authenticator: %w", err)
}
p.auth.SetLogger(p.logger)

p.fetcher, err = graph.New(ctxtool.FromCanceller(p.ctx.Cancelation), p.ctx.ID, p.cfg, p.Manager.Logger, p.auth)
if err != nil {
return fmt.Errorf("unable to create fetcher: %w", err)
}
p.fetcher.SetLogger(p.logger)

p.metrics = newMetrics(inputCtx.ID, nil)
defer p.metrics.Close()

Expand Down Expand Up @@ -569,19 +582,10 @@ func (p *azure) publishDevice(d *fetcher.Device, state *stateStore, inputID stri

// configure configures this provider using the given configuration.
func (p *azure) configure(cfg *config.C) (kvstore.Input, error) {
var err error

if err = cfg.Unpack(&p.conf); err != nil {
if err := cfg.Unpack(&p.conf); err != nil {
return nil, fmt.Errorf("unable to unpack %s input config: %w", Name, err)
}

if p.auth, err = oauth2.New(cfg, p.Manager.Logger); err != nil {
return nil, fmt.Errorf("unable to create authenticator: %w", err)
}
if p.fetcher, err = graph.New(ctxtool.FromCanceller(p.ctx.Cancelation), p.ctx.ID, cfg, p.Manager.Logger, p.auth); err != nil {
return nil, fmt.Errorf("unable to create fetcher: %w", err)
}

p.cfg = cfg
return p, nil
}

Expand Down

0 comments on commit 79206dd

Please sign in to comment.