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][Exceptions] Add lowercase normalizer for case-insensitivity + deprecate _tags field (new OS field) #77379

Merged
merged 36 commits into from
Oct 2, 2020

Conversation

madirey
Copy link
Contributor

@madirey madirey commented Sep 14, 2020

Summary

This PR ensures that *.caseless fields appearing in exceptions are translated correctly so that the endpoint can use them for case-insensitive comparisons.

A migration is added to convert *.text fields appearing in exceptions to *.caseless so that the detection engine will perform case-insensitive comparisons in the same way that the endpoint does (without tokenization).

Requires updating to a new endpoint package which contains the below fix:

Related:

Additionally, this PR deprecates usage of _tags in the lists plugin, in favor of os_types, which is more explicit. We were only using it for OS designation, so the relevant tags will be migrated. The field will remain in ES for now, but it has been removed from all schemas. This will prevent the confusion between _tags and tags and will prevent the user from inadvertently updating _tags to a value that breaks internal functionality.

Finally, this PR fixes the button text when adding an endpoint exception:
image

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@madirey madirey requested review from a team as code owners September 14, 2020 17:24
@elasticmachine
Copy link
Contributor

Pinging @elastic/endpoint-response (Team:Endpoint Response)

@elasticmachine
Copy link
Contributor

Pinging @elastic/siem (Team:SIEM)

@madirey madirey added the Feature:Endpoint Elastic Endpoint feature label Sep 14, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/endpoint-app-team (Feature:Endpoint)

@jen-huang jen-huang added v7.10.0 and removed v7.10 labels Sep 14, 2020
@botelastic botelastic bot added the Team:Fleet Team label for Observability Data Collection Fleet team label Sep 23, 2020
@elasticmachine
Copy link
Contributor

Pinging @elastic/ingest-management (Team:Ingest Management)

@madirey madirey requested a review from a team September 23, 2020 14:42
migration((doc as unknown) as SavedObjectUnsanitizedDoc<OldExceptionListSoSchema>)
).toEqual({
attributes: {
_tags: ['1234', 'os:windows'],
Copy link
Contributor

Choose a reason for hiding this comment

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

With _tags deleted from the exceptionListItemSchema won't migrated exception list items fail to validate against it in update_exception_list_item_route and others if the items still contain _tags?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@marshallmain No, the validation is performed against an object that will already have _tags removed from the SO response.

const { entries, description, created_by, created_at, name, _tags, id } = exceptionListItem;
const os = osFromTagsList(_tags);
const { entries, description, created_by, created_at, name, os_types, id } = exceptionListItem;
const os = os_types.length ? os_types[0] : 'unknown';
Copy link
Contributor

Choose a reason for hiding this comment

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

😮

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah? 😂

Copy link
Contributor

Choose a reason for hiding this comment

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

Trusted apps supports only 1 OS per entry, thus why we return a string rather than string[]. unknown should never happen (🤞 )

Comment on lines +23 to +31
const migrateEntry = (entryToMigrate: EntryType): EntryType => {
const newEntry = entryToMigrate;
if (entriesNested.is(entryToMigrate) && entriesNested.is(newEntry)) {
newEntry.entries = entryToMigrate.entries.map((nestedEntry) =>
migrateEntry(nestedEntry)
) as NonEmptyNestedEntriesArray;
}
newEntry.field = entryToMigrate.field.replace('.text', '.caseless');
return newEntry;
Copy link
Contributor

Choose a reason for hiding this comment

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

does making newEntry do anything here? it looks like a reference to the same object as entryToMigrate. The if conditions appear to be redundant as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@marshallmain Thanks, will fix!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@marshallmain Oh, this was actually to get around the no-param-reassign eslint rule. Leaving it as-is.

Copy link
Contributor

@marshallmain marshallmain left a comment

Choose a reason for hiding this comment

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

LGTM once the unit test failures are fixed

@marshallmain
Copy link
Contributor

One other note is that the exception migration from .text to .caseless is a breaking change for exceptions until the endpoint package is upgraded - we may need users to manually upgrade the endpoint package in ingest manager since the ingest manager does not (I think?) automatically install package upgrades as they become available.

@madirey
Copy link
Contributor Author

madirey commented Sep 26, 2020

@marshallmain I believe @jonathan-buttner is working on that...

@jonathan-buttner
Copy link
Contributor

@marshallmain I believe @jonathan-buttner is working on that...

Oops sorry I had missed this previously. Yeah we implemented a check when the user is interacting with the security solution app and in the ingest manager app that checks for a new endpoint package and installs it:

#78081
#77498

@madirey
Copy link
Contributor Author

madirey commented Oct 1, 2020

@elasticmachine merge upstream

@madirey
Copy link
Contributor Author

madirey commented Oct 1, 2020

@elasticmachine merge upstream

@madirey madirey changed the title [Security Solution][Exceptions] Add lowercase normalizer for more accurate case-insensitive exceptions [Security Solution][Exceptions] Add lowercase normalizer for case-insensitivity + deprecate _tags field (new OS field) Oct 2, 2020
Copy link
Contributor

@paul-tavares paul-tavares left a comment

Choose a reason for hiding this comment

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

Looks good from a Trusted Apps standpoint. I assume you are still working on getting the changes in for the .caseless change for trusted apps, right?

const { entries, description, created_by, created_at, name, _tags, id } = exceptionListItem;
const os = osFromTagsList(_tags);
const { entries, description, created_by, created_at, name, os_types, id } = exceptionListItem;
const os = os_types.length ? os_types[0] : 'unknown';
Copy link
Contributor

Choose a reason for hiding this comment

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

Trusted apps supports only 1 OS per entry, thus why we return a string rather than string[]. unknown should never happen (🤞 )

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

@kbn/optimizer bundle module count

id before after diff
securitySolution 1989 1990 +1

async chunks size

id before after diff
securitySolution 10.3MB 10.3MB -1.3KB

distributable file count

id before after diff
default 45824 45826 +2

page load bundle size

id before after diff
lists 164.1KB 164.7KB +658.0B
securitySolution 585.9KB 586.9KB +996.0B
total +1.6KB

Saved Objects .kibana field count

id before after diff
exception-list 38 39 +1
exception-list-agnostic 38 39 +1
total +2

History

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

Copy link
Contributor

@paul-tavares paul-tavares left a comment

Choose a reason for hiding this comment

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

Changes to Trusted Apps code for the .caseless field looks good 👍

@madirey madirey merged commit c456f64 into elastic:master Oct 2, 2020
@madirey madirey deleted the lowercase-normalizer branch October 2, 2020 19:54
madirey added a commit that referenced this pull request Oct 3, 2020
…ensitivity + deprecate _tags field (new OS field) (#77379) (#79376)

* Finish adding .lower to exceptionable fields

* Add back migrations

* .lower -> .caseless

* Add separate field for os type

* updates

* Type updates

* Switch over to osTypes

* get rid of _tags

* Add tests for schema validation

* Remove remaining references to _tags

* Another round of test fixes

* DefaultArray tests

* More test fixes

* Fix remaining test failures

* types / tests

* more test updates

* lowercase os values

* Address feedback + fix test failure

* tests

* Fix integration test

* process.executable.path -> process.executable.caseless

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
@MindyRS MindyRS added the Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. label Sep 23, 2021
@elasticmachine
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Endpoint Elastic Endpoint feature needs_docs release_note:enhancement Team:Endpoint Response Endpoint Response Team Team:Fleet Team label for Observability Data Collection Fleet team Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. Team:SIEM v7.10.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants