Skip to content

entityanalytics_ad: map user group details to ecs fields #13550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 30, 2025

Conversation

efd6
Copy link
Contributor

@efd6 efd6 commented Apr 15, 2025

Proposed commit message

See title.

Checklist

  • I have reviewed tips for building integrations and this pull request is aligned with them.
  • I have verified that all data streams collect metrics or logs.
  • I have added an entry to my package's changelog.yml file.
  • I have verified that Kibana version constraints are current according to guidelines.
  • I have verified that any added dashboard complies with Kibana's Dashboard good practices

Author's Checklist

  • [ ]

How to test this PR locally

Related issues

Screenshots

@efd6 efd6 added enhancement New feature or request Team:Security-Service Integrations Security Service Integrations team [elastic/security-service-integrations] Integration:entityanalytics_ad Active Directory Entity Analytics labels Apr 15, 2025
@efd6 efd6 self-assigned this Apr 15, 2025
@efd6 efd6 force-pushed the 13511-entityanalytics_ad branch from 63b02af to bccafc2 Compare April 15, 2025 23:59
@efd6 efd6 marked this pull request as ready for review April 16, 2025 00:21
@efd6 efd6 requested a review from a team as a code owner April 16, 2025 00:21
@elasticmachine
Copy link

Pinging @elastic/security-service-integrations (Team:Security-Service Integrations)

@efd6
Copy link
Contributor Author

efd6 commented Apr 16, 2025

@jaredburgettelastic I did not include the user.group.domain field in this mapping since this would just be a copy of user.domain which seems somewhat pointless. If you disagree, please let me know and I will add it.

@jaredburgettelastic
Copy link

@efd6 Based on the data we have seen, copying further into the user.group.domain field is not necessary for our purposes.

@@ -358,21 +348,39 @@ processors:
'549': true
'551': true
source: |-
ctx.user = ctx.user ?: [:];
ctx.user.group = ctx.user.group ?: [:];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please correct me if I'm wrong, I'm not a Painless expert, but looks like we're setting user.group.id and user.group.name to a collection (set) of values.
I think in ECS both id and name are keywords, so they only hold a single value.
For our use case, I think we would like these fields to contain the data from the group in the primary_group_id

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting point from an ECS perspective.

Functionality-wise, we (and customers) definitely need the full list of groups for a given entity, not only the primary group.

I believe I've seen a precedent in our integrations for handling multiple values for a given field, which similarly populates multiple values onto a single field, @efd6 can you confirm?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Elasticsearch, any field that can take a single value can take multiple values. A keyword field can have a single string or multiple strings in it.

ECS says some field must be arrays, but otherwise it's open, and we often put multiple values, or even a single value in an array when we expect multiple.

Users of _source will see this difference and will sometimes need to handle both single and array values, but most documents will usually have one or the other in a given field.

Copy link

@jaredburgettelastic jaredburgettelastic Apr 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it, so if I were to give a contrived example document:

user:
  group:
    name:
      - first_group
      - second_group
    id:
      - id_1
      - id_2 

Is it correct to say we should expect the values in the document to correlate to one another through their position in the arrays?

In the example above, that means first_group has an id of id_1, and second_group has an id of id_2?

Copy link
Contributor Author

@efd6 efd6 Apr 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where it gets confusing is in export of documents that use our interpretation of ECS which as Chris says is relaxed; other implementations based on ECS do not allow vector values in scalar fields. In this situation, because we can, and from a security perspective (as you note) it is needed, I've made them vectors.

The ECS definition of these fields is a little underwhelming; there is no indication that the fields are scalar, but this is because the convention for indication of scalar v vector fields in the docs is by omission (vector fields are marked with the text "This field should contain an array of values" while scalar fields have nothing.) Because of this, in the ES ecosystem we see quite a few fields raised from scalar to vector on the basis of "that which is not forbidden is allowed". This is unfortunate in one sense, but happy in many others.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jaredburgettelastic For your question with the example, that depends on the type of the user.group field which in ECS is a group type. This means that there is no correlation between user.group.name and user.group.id in the example you gave. The order is retained so some correlation can be obtained, but it's not apparent when you only use a query.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Thank you for the explanation. From my perspective, I think this is appropriate. @tiansivive do you have any concerns?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nope, and loads of TIL on this one! Thanks a lot!

Comment on lines 356 to 358
if (ctx.user.group.name == null) {
ctx.user.group.name = new HashSet();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can use the ctx.user.group.name = ctx.user.group.name ?: [:]; syntax as above.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also below

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's really interesting. This was a case of fast thinking blindness (Kahneman). Thanks.

@elastic-vault-github-plugin-prod

🚀 Benchmarks report

To see the full report comment with /test benchmark fullreport

@elasticmachine
Copy link

💚 Build Succeeded

History

cc @efd6

Copy link

Copy link

@tiansivive tiansivive left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM from EA 🚢

@efd6 efd6 merged commit efb45ca into elastic:main Apr 30, 2025
7 checks passed
@elastic-vault-github-plugin-prod

Package entityanalytics_ad - 0.13.0 containing this change is available at https://epr.elastic.co/package/entityanalytics_ad/0.13.0/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Integration:entityanalytics_ad Active Directory Entity Analytics Team:Security-Service Integrations Security Service Integrations team [elastic/security-service-integrations]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[EA Active Directory 0.12.0]: Add support for ECS user.group fields
5 participants