Skip to content
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

[m365_defender] Add support for Incident data-stream with new Security Graph API #4435

Merged
merged 7 commits into from
Nov 8, 2022

Conversation

vinit-chauhan
Copy link
Contributor

@vinit-chauhan vinit-chauhan commented Oct 10, 2022

What does this PR do?

  • Added a data stream.
  • Added data collection logic to the data stream.
  • Added the ingest pipeline for the data stream.
  • Mapped fields according to the ECS schema and added Fields metadata in the appropriate yml files.
  • Added dashboards and visualizations.
  • Added test for pipeline for the data stream.
  • Added system test cases for the data stream.

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.
  • If I'm introducing a new feature, I have modified the Kibana version constraint in my package's manifest.yml file to point to the latest Elastic stack release (e.g. ^7.16.0).

How to test this PR locally

  • Clone integrations repo.
  • Install elastic package locally.
  • Start elastic stack using elastic-package.
  • Move to integrations/packages/m365_defender directory.
  • Run the following command to run tests.

elastic-package test

Related issues

Screenshots

image
image
image
image
image
image

@vinit-chauhan vinit-chauhan requested a review from a team as a code owner October 10, 2022 14:02
@elasticmachine
Copy link

Pinging @elastic/security-external-integrations (Team:Security-External Integrations)

@elasticmachine
Copy link

🚀 Benchmarks report

To see the full report comment with /test benchmark fullreport

@elasticmachine
Copy link

elasticmachine commented Oct 10, 2022

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2022-11-08T05:02:40.310+0000

  • Duration: 16 min 53 sec

Test stats 🧪

Test Results
Failed 0
Passed 15
Skipped 0
Total 15

🤖 GitHub comments

Expand to view the GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

@elasticmachine
Copy link

elasticmachine commented Oct 10, 2022

🌐 Coverage report

Name Metrics % (covered/total) Diff
Packages 100.0% (2/2) 💚
Files 100.0% (2/2) 💚 2.698
Classes 100.0% (2/2) 💚 2.698
Methods 96.667% (29/30) 👍 6.094
Lines 93.776% (2275/2426) 👍 2.197
Conditionals 100.0% (0/0) 💚

@vinit-chauhan vinit-chauhan changed the title [m365_defender] Add support for Alert and Incident data-stream [m365_defender] Add support for Alert and Incident data-stream with new Security Graph API v2 Oct 11, 2022
@vinit-chauhan vinit-chauhan changed the title [m365_defender] Add support for Alert and Incident data-stream with new Security Graph API v2 [m365_defender] Add support for Alert and Incident data-stream with new Security Graph API Oct 11, 2022
@@ -0,0 +1,20 @@
- name: data_stream.type
Copy link
Contributor

Choose a reason for hiding this comment

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

Move the fields to ecs.yml and use external definitions where possible.

  • data_stream.type
  • data_stream.dataset
  • data_stream.namespace
  • @timestamp

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey @efd6 ,
Also, there is an agent.yml which contains an ECS field description. So, should we remove that file and provide those field descriptions in ecs.yml?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, that has confused me in the past. @P1llus WDYT?

Copy link
Member

Choose a reason for hiding this comment

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

base-fields.yml is the correct approach, all integrations currently have those, so we shouldn't move them out of that file, unless there is any specific plans to do this on all integrations.

agent.yml needs to stay and usually have all the agent fields populated by the agent, so it should be fairly large. If its very small for some reason then feel free to copy it from any of the other integrations.

Comment on lines 67 to 72
if (!eventType.isEmpty()) {
ctx.event.type = eventType;
}
if (!eventCategory.isEmpty()) {
ctx.event.category = eventCategory;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I've found that this can be a cause of test failures due to changes in iteration order in the HashSet type. See #4296. The fix is to copy the elements to an array list and then sort it (this is done in the linked PR).

Comment on lines 2107 to 2133
if (!cloudProvider.isEmpty()) {
ctx.cloud.provider = cloudProvider;
}
if (!groupName.isEmpty()) {
ctx.group.name = groupName;
}
if (!hostId.isEmpty()) {
ctx.host.id = hostId;
}
if (!userDomain.isEmpty()) {
ctx.user.domain = userDomain;
}
if (!userId.isEmpty()) {
ctx.user.id = userId;
}
if (!userName.isEmpty()) {
ctx.user.name = userName;
}
if (!userEmail.isEmpty()) {
ctx.user.email = userEmail;
}
if (!processUserId.isEmpty()) {
ctx.process.user.id = processUserId;
}
if (!processUserName.isEmpty()) {
ctx.process.user.name = processUserName;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Same issue here. Given the number of cases a helper function to convert a hash set to a canonically ordered list would probably be best.

Comment on lines 2165 to 2173
if (!fileSize.isEmpty()) {
ctx.file.size = fileSize;
}
if (!processPid.isEmpty()) {
ctx.process.pid = processPid;
}
if (!processParentPid.isEmpty()) {
ctx.process.parent.pid = processParentPid;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

And here.

Comment on lines 2245 to 2271
if (!cloudProvider.isEmpty()) {
ctx.cloud.provider = cloudProvider;
}
if (!groupName.isEmpty()) {
ctx.group.name = groupName;
}
if (!hostId.isEmpty()) {
ctx.host.id = hostId;
}
if (!userDomain.isEmpty()) {
ctx.user.domain = userDomain;
}
if (!userId.isEmpty()) {
ctx.user.id = userId;
}
if (!userName.isEmpty()) {
ctx.user.name = userName;
}
if (!userEmail.isEmpty()) {
ctx.user.email = userEmail;
}
if (!processUserId.isEmpty()) {
ctx.process.user.id = processUserId;
}
if (!processUserName.isEmpty()) {
ctx.process.user.name = processUserName;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Ordering.

Comment on lines 2303 to 2311
if (!fileSize.isEmpty()) {
ctx.file.size = fileSize;
}
if (!processPid.isEmpty()) {
ctx.process.pid = processPid;
}
if (!processParentPid.isEmpty()) {
ctx.process.parent.pid = processParentPid;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Ordering.

@@ -1,4 +1,9 @@
# newer versions go on top
- version: "2.0.0"
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason this needs to bump the major version? I don't see any breaking change here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As discussed, the existing log data stream will be deprecated and will be replaced by a new alert and incident data stream that supports the latest Microsoft Security Graph API. 
@P1llus Should we include a note in the readme or do you have other suggestions?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah this is a breaking change and would need a major bump, but I believe there is also a few other things that needs to be discussed.

Comment on lines 2125 to 2133
ctx.cloud.provider = convertToOrderedArray(cloudProvider);
ctx.group.name = convertToOrderedArray(groupName);
ctx.host.id = convertToOrderedArray(hostId);
ctx.user.domain = convertToOrderedArray(userDomain);
ctx.user.id = convertToOrderedArray(userId);
ctx.user.name = convertToOrderedArray(userName);
ctx.user.email = convertToOrderedArray(userEmail);
ctx.process.user.id = convertToOrderedArray(processUserId);
ctx.process.user.name = convertToOrderedArray(processUserName);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think these and the similar calls below should still be conditional to avoid fruitless work here and in the empty value cleaning processor.

@vinit-chauhan vinit-chauhan changed the title [m365_defender] Add support for Alert and Incident data-stream with new Security Graph API [m365_defender] Add support for Incident data-stream with new Security Graph API Nov 4, 2022
@P1llus
Copy link
Member

P1llus commented Nov 7, 2022

Outside of the comments from @efd6 I have nothing else to add here, it seems good to me 👍

Copy link
Contributor

@efd6 efd6 left a comment

Choose a reason for hiding this comment

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

LGTM after conflict resolved.

@P1llus P1llus merged commit 020f3e3 into elastic:main Nov 8, 2022
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:m365_defender Microsoft M365 Defender
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Microsoft Defender | Full Support for All Defender Products
4 participants