x-pack/filebeat/input/entityanalytics/provider/azuread: legacy provider membership and state fixes
Correctness bugs in the legacy Entra ID (azure-ad) provider (use_minimal_state: false). These matter for standalone users and for Fleet users on stacks before 9.5.
- Direct and transitive memberships share one map.
u.TransitiveMemberOf = u.MemberOfcopies a struct that wraps a map, so both fields share it. Transitive groups are written into the directMemberOfand persisted, and removing a nesting never removes the membership. Devices have the same problem (azure.go:460, :529). - Deleted groups stay in
MemberOf. A deleted group is removed from the relationship graph but not from users'MemberOf(azure.go:390-397). - A full sync never removes anything. It merges into the existing state, and
User.Mergeonly adds memberships (user.go:77-88). Stale memberships, and users deleted between updates, survive for good. This is the same accumulate pattern that #53134 fixed for device owners. - Deleted users and devices are never pruned, and are republished as deleted on every full sync.
- No retry. Any non-200 response fails with no retry and ignores
Retry-After, so one 429 fails the whole sync (graph.go:537-544). Each device also costs two extra requests (registered owners and users), so large tenants are likely to hit throttling. - No HTTP timeout unless
timeoutis set. The integration package sets 30s; standalone configs get none. - An expired delta link (410) is never reset, so incremental updates fail until the next full sync.
Backports to be decided on the PR.
Relates #41492.
Pinging @elastic/security-service-integrations (Team:Security-Service Integrations)
One more for the legacy provider. publishUser adds azure_ad.mfa and azure_ad.signInActivity by Put into u.Fields, which changes the stored user in place (azure.go:598, :602). The full sync saves the users with their Fields (statestore.go:211), and User.Merge keeps keys the next delta doesn't carry (fetcher/user.go:81). So the reset of u.MFA and u.SignInActivity before each enrichment pass (azure.go:477, :501) doesn't clear the published values. If the MFA or sign-in fetch fails, a user leaves the MFA report, or enrich_with is changed to none, the old values keep being published from the stored fields.
Fix: build the published azure_ad map as a copy of u.Fields, as the minimal-state provider now does (elastic/entcollect#22).
Found by reading the code; not reproduced end to end.
Hi @efd6, I'd like to work on this. Plan: in x-pack/filebeat/input/entityanalytics/provider/azuread/azure.go, deep-copy MemberOf into TransitiveMemberOf for users and devices (L460, L529) instead of sharing the wrapped map, drop deleted groups from users' MemberOf when they leave the graph (L390-L397), make a full sync replace state rather than merge through User.Merge in fetcher/user.go, and stop publishUser from Putting azure_ad.mfa/signInActivity into the stored u.Fields by publishing from a copy. Testing: table tests in the provider's azure_test.go for nesting removal, group deletion and a full sync that drops a user, run with go test ./x-pack/filebeat/input/entityanalytics/provider/azuread/.... Would you prefer one PR or one per bug? Could you assign it to me?
Thanks @rahulsjha. This is part of an epic that has a number of dependencies in flight and needs to integrate with other work, so I would like to keep it as part of the work I'm doing. I appreciate the offer though.
Understood, thanks @efd6.