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

[Security Solution] Add host.os.name.caseless mapping and runtime field #111455

Merged
merged 7 commits into from
Sep 10, 2021

Conversation

marshallmain
Copy link
Contributor

@marshallmain marshallmain commented Sep 7, 2021

Summary

Closes #110130

Elastic Endpoint only recently started populating host.os.type, and instead was populating host.os.name. The logs-endpoint indices had host.os.name.caseless as a multifield on host.os.name with a lowercase normalizer. Endpoint exceptions were recently fixed to add a filter based on the os_type (linux | macos | windows), and that filter checks both host.os.type and host.os.name.caseless for the os_type to ensure it works against old Endpoint alerts that don't populate host.os.type and new alerts that do.

However, host.os.name.caseless was not mapped in the signals indices so the Close all alerts matching this exception checkbox will not close signals based on Endpoint alerts that don't populate host.os.type. These signals could be existing signals from before 7.15, or they could be signals based on new alerts coming in from endpoints that haven't been upgraded to 7.15 yet. This PR fixes the issue for existing signals by creating a runtime field host.os.name.caseless that normalizes the host.os.name field, and also adding the host.os.name.caseless normalized multi-field to the signals index mapping so newly created signals will have it as well.

Since runtime fields are slower than regular fields we also want to avoid adding them unnecessarily. This PR builds the appropriate mappings for each index version to make them backwards compatible. The runtime fields will only be added for indices whose version is <= 45 (released in 7.14), since the next release will contain host.os.name.caseless as an indexed multifield for newly written signals.

There are 2 version fields on each .siem-signals index, which can be somewhat confusing.

version is defined when the index is created and should never change. This tells us what the original mapping was on the index so we can apply the appropriate migrations/backwards compatibility mappings. This also tells us when we need to rollover and create a new index because the "regular" field mappings have changed.

aliases_version is also defined when the index is created but can change over time. This field represents whether or not an index has the latest set of aliases and runtime fields used for backwards compatibility. When we apply aliases and runtime fields to an index, this version number is updated to reflect the latest version in the source code. Even if there are no aliases or runtime fields defined for a particular version (the static version above), we still update aliases_version on all existing indices to mark that they have been checked and brought up to date.

@marshallmain
Copy link
Contributor Author

@elasticmachine merge upstream

maxVersion: 45,
mapping: {
runtime: {
'host.os.name.caseless': {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we wanna move this out into its own json file or const just so we can add future fields without mixing all the data and logic together?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We shouldn't be adding any future fields within this object, any future migrations would be separate objects at the top level of this array. And right now the field aliases are built dynamically from another JSON file, so we'd have to rework that logic to create the aliases at build time. It could be nice, but right now it's covered with a unit test against a snapshot.

{
minVersion: 0,
// Version 45 shipped with 7.14
maxVersion: 45,
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 central point we can pull this number from so we don't have to change it piecewise every update?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This number should never change, as any future indices won't need this migration. The next migration will be a separate object and may have a different maxVersion, but we'll leave this migration the same.

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@marshallmain marshallmain added auto-backport Deprecated - use backport:version if exact versions are needed release_note:skip Skip the PR/issue when compiling release notes Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. Team:Detections and Resp Security Detection Response Team v7.16.0 v8.0.0 labels Sep 9, 2021
@marshallmain marshallmain marked this pull request as ready for review September 9, 2021 02:39
@marshallmain marshallmain requested a review from a team as a code owner September 9, 2021 02:39
@elasticmachine
Copy link
Contributor

Pinging @elastic/security-detections-response (Team:Detections and Resp)

@elasticmachine
Copy link
Contributor

Pinging @elastic/security-solution (Team: SecuritySolution)

@marshallmain marshallmain requested a review from a team September 9, 2021 02:39
Copy link
Contributor

@dplumlee dplumlee left a comment

Choose a reason for hiding this comment

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

Seems to work against master and fixes the closing logic for alerts that don't have a host.os.type field 👍

@peluja1012 peluja1012 requested a review from a team September 9, 2021 21:52
@MadameSheema
Copy link
Member

As this PR is fixing a possible blocker issue, I did a bit of exploratory testing on it. I would deeply appreciate it if you can check my results since I'm not familiar with Endpoint alerts/exceptions so I'm not sure if the results are the expected ones or not:

  • Case 1:
{
   "@timestamp":"2021-09-10T10:47:06.527Z",
   "event":{
      "kind":"alert",
      "module":"endpoint",
      "ingested": "2021-09-10T10:47:06.527Z"
   },
   "host":{
      "os":{
         "name":"MACOS"
      }
   }
}

Result:

  • The value was properly populated on the Endpoint exceptions under host.os.name.caseless in lower-case.

  • The alert was properly closed when selecting Close all alerts that match this exception and were generated by this rule

  • Also as a rule exception

  • Case 2:

   "@timestamp":"2021-09-10T13:37:06.527Z",
   "event":{
      "kind":"alert",
      "module":"endpoint",
      "ingested":"2021-09-10T13:37:06.527Z"
   },
   "host":{
      "os":{
         "type":"macos"
      }
   }
}

Result:

  • The field host.os.type is not displayed on the Endpoint exceptions modal.

  • The alert was properly closed when selecting Close all alerts that match this exception and were generated by this rule

  • Also as a rule exception

  • Case 3:

  "@timestamp": "2021-09-10T13:47:06.527Z",
  "event": {
    "kind": "alert",
    "module": "endpoint",
    "ingested": "2021-09-10T13:47:06.527Z"
  }
}

Result:

  • The alert it is not closed when closed when selecting Close all alerts that match this exception and were generated by this rule on the Endpoint exceptions modal
  • It is closed as a Rule exception

@marshallmain
Copy link
Contributor Author

Thanks for testing it @MadameSheema! Those results are what I would expect.

@marshallmain marshallmain merged commit caf5fe3 into elastic:master Sep 10, 2021
kibanamachine added a commit to kibanamachine/kibana that referenced this pull request Sep 10, 2021
…ld (elastic#111455)

* Add host.os.name.caseless field and runtime field

* Tests

* Only add backwards compatibility mappings to old indices by version

* Always update aliases_version field even if there are no compat mappings

* Add test for newest index version

* More comments

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
kibanamachine added a commit to kibanamachine/kibana that referenced this pull request Sep 10, 2021
…ld (elastic#111455)

* Add host.os.name.caseless field and runtime field

* Tests

* Only add backwards compatibility mappings to old indices by version

* Always update aliases_version field even if there are no compat mappings

* Add test for newest index version

* More comments

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
@kibanamachine
Copy link
Contributor

💚 Backport successful

Status Branch Result
7.15
7.x

The backport PRs will be merged automatically after passing CI.

jloleysens added a commit to jloleysens/kibana that referenced this pull request Sep 13, 2021
…-link-to-kibana-app

* 'master' of github.com:elastic/kibana: (120 commits)
  [TSVB] Support custom field format (elastic#101245)
  [VisEditors] Add code ownership to the functional tests (elastic#111680)
  [Lens] Make Lens saved object share-capable (elastic#111403)
  [Graph] Make Graph saved object share-capable (elastic#111404)
  [Stack Monitoring] Add breadcrumb support (elastic#111850)
  Update Jira Cloud to use OAuth2.0 (elastic#111493)
  Show warning message when attempting to create an APM alert in stack management (elastic#111781)
  Skip suite blocking ES snapshot promotion (elastic#111907)
  Respect `auth_provider_hint` if session is not authenticated. (elastic#111521)
  Added in 'Responses' field in alert telemetry & updated test (elastic#111892)
  [Usage collection] refactor cloud detector collector (elastic#110439)
  Make classnames a shared dep (elastic#111636)
  Fix link to e2e tests in APM testing.md (elastic#111869)
  [Security Solution] Add host.os.name.caseless mapping and runtime field (elastic#111455)
  [APM] Removes the beta label from APM tutorial (elastic#111499) (elastic#111828)
  [RAC] [Observability] Expand Observability alerts page functional tests (elastic#111297)
  Fix extra white space on the alert table whe page size is 50 or 100 (elastic#111568)
  [Metrics UI] Add Inventory Timeline open/close state to context and URL state (elastic#111034)
  [Graph] Switch to SavedObjectClient.resolve  (elastic#109617)
  [APM] Adding lambda icon (elastic#111834)
  ...

# Conflicts:
#	x-pack/plugins/reporting/public/management/__snapshots__/report_listing.test.tsx.snap
kibanamachine added a commit that referenced this pull request Sep 14, 2021
…ld (#111455) (#111872)

* Add host.os.name.caseless field and runtime field

* Tests

* Only add backwards compatibility mappings to old indices by version

* Always update aliases_version field even if there are no compat mappings

* Add test for newest index version

* More comments

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

Co-authored-by: Marshall Main <55718608+marshallmain@users.noreply.github.com>
marshallmain added a commit to marshallmain/kibana that referenced this pull request Sep 14, 2021
…ld (elastic#111455)

* Add host.os.name.caseless field and runtime field

* Tests

* Only add backwards compatibility mappings to old indices by version

* Always update aliases_version field even if there are no compat mappings

* Add test for newest index version

* More comments

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
marshallmain added a commit that referenced this pull request Sep 14, 2021
…ime field (#111455) (#112050)

* [Security Solution] Add host.os.name.caseless mapping and runtime field (#111455)

* Add host.os.name.caseless field and runtime field

* Tests

* Only add backwards compatibility mappings to old indices by version

* Always update aliases_version field even if there are no compat mappings

* Add test for newest index version

* More comments

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>

* Skip failing test

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Deprecated - use backport:version if exact versions are needed release_note:skip Skip the PR/issue when compiling release notes Team:Detections and Resp Security Detection Response Team Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. v7.15.0 v7.16.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Security Solution] .caseless fields are missing in .siem-signals mapping
5 participants