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

[SIEM][Exceptions] - Exception builder component #67013

Merged
merged 59 commits into from
Jul 2, 2020

Conversation

yctercero
Copy link
Contributor

@yctercero yctercero commented May 19, 2020

Summary

This PR creates the bulk functionality of the exception builder. The exception builder is the component that will be used to create exception list items. It does not deal with the actual API creation/deletion/update of exceptions, it does contain an onChange handler that can be used to access the exceptions. The builder is able to:

  • accept ExceptionListItem and render them correctly
  • allow user to add exception list item and exception list item entries
  • accept an indexPattern and use it to fetch relevant field and autocomplete field values
  • disable Or button if user is only allowed to edit/add to exception list item (not add additional exception list items)
  • displays Add new exception button if no exception items exist
    • An exception item can be created without entries, the add new exception button will show in the case that an exception list contains exception list item(s) with an empty entries array (as long as there is one exception list item with an item in entries, button does not show)
  • debounces field value autocomplete searches
  • bubble up exceptions to parent component, stripping out any empty entries

Logic checks:

  • if selected field is type boolean, operators are limited to is, is not, exists, does not exist and available values are true, false
  • if selected field is type date, number, or ip, values combo box shows error state if values do not match field type
  • if selected operator is is in list or is not in list, only lists that match the selected field type will be displayed in the autocomplete
  • no error state shown if value box is empty, invalid fields get stripped out when exceptions are passed back to parent

Aside
Created reusable components for field, operator and field value inputs as it's already needed for other functionality. I added a README.md (x-pack/plugins/security_solution/public/common/components/autocomplete/readme.md) to try to make use of the components a bit easier.

To Do

  • Additional value validation checks
  • Nested types logic (will do follow up PR)
  • React warning on initial first field selection (wip)
  • Match any was acting funny (was passing selected field as query to autocomplete, causing funkiness, fixed!)

Examples

Builder

builder

List operator

list

Match operator

match

Match any operator

match_any

Boolean field type

boolean

Exists operator

exists

Sample validation (field of type ip)

validation

Checklist

yctercero and others added 30 commits May 17, 2020 21:58
This also adds a generic hook, useAsyncTask, that wraps an async
function to provide basic utilities:
  * loading state
  * error state
  * abort/cancel function
These were not caught locally as I was accidentally running typescript
without the full project.
… tuple

This allows callers to further leverage fp-ts functions as needed.
* leverages new validateEither fn which returns an Either
* constructs a pipeline that:
  * validates the payload
  * performs the API call
  * validates the response
and short-circuits if any of those produce a Left value.

It then converts the Either into a promise that either rejects with the
Left or resolves with the Right.
This cleans up our validation pipeline considerably.
* refactors private API functions to accept the encoded request schema
(i.e. snake cased)
* refactors validateEither to use `schema.validate` instead of
`schema.decode` since we don't actually want the decoded value, we just
want to verify that it'll be able to be decoded on the backend.
* Continue to export decoded types without a qualifier
* pull types used by hooks from their new location
* Fix errors with usage of act()
By pulling from the module directly instead of an index, we can
hopefully narrow down our dependencies until tree-shaking does this for
us.
@yctercero yctercero changed the title [SIEM][Exceptions] - Exception builder component (wip) [SIEM][Exceptions] - Exception builder component Jul 1, 2020
@yctercero yctercero self-assigned this Jul 1, 2020
@yctercero yctercero marked this pull request as ready for review July 1, 2020 11:44
@yctercero yctercero requested review from a team as code owners July 1, 2020 11:44
@elasticmachine
Copy link
Contributor

Pinging @elastic/siem (Team:SIEM)

/>
);
if (index === 0 && exceptionItemIndex === 0) {
return <MyFirstRowContainer grow={false}>{button}</MyFirstRowContainer>;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Similar to the above comment - the first row includes the field labels, so the delete icon was centering based on that extra space. Added padding fixes that.

};
};

export const filterExceptionItems = (
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 is to ensure that we only bubble up valid exception item and entries. A user could add 10 blank rows or entries, this strips those out.

@@ -49,3 +50,46 @@ export interface ExceptionsPagination {
totalItemCount: number;
pageSizeOptions: number[];
}

export interface FormattedBuilderEntryBase {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These new types are to deal with the empty states of the entries in the builder, since the exception item entries can be in what the ExceptionListItemSchema would pick up as invalid. But when bubbling up the exceptions to the parent, we do check to strip out any empties.

@@ -0,0 +1,122 @@
# Autocomplete Fields
Copy link
Contributor

Choose a reason for hiding this comment

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

Great readme!

Copy link
Contributor

@peluja1012 peluja1012 left a comment

Choose a reason for hiding this comment

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

Tested by integrating the component with the Exception Modal (upcoming PR). Looks great! My only suggestion would be to look into using useMemo and useCallback where it makes sense throughout these components.

@yctercero yctercero merged commit 6581450 into elastic:master Jul 2, 2020
yctercero added a commit to yctercero/kibana that referenced this pull request Jul 2, 2020
### Summary

This PR creates the bulk functionality of the exception builder. The exception builder is the component that will be used to create exception list items. It does not deal with the actual API creation/deletion/update of exceptions, it does contain an `onChange` handler that can be used to access the exceptions. The builder is able to:

- accept `ExceptionListItem` and render them correctly
- allow user to add exception list item and exception list item entries
- accept an `indexPattern` and use it to fetch relevant field and autocomplete field values
- disable `Or` button if user is only allowed to edit/add to exception list item (not add additional exception list items)
- displays `Add new exception` button if no exception items exist
    - An exception item can be created without entries, the `add new exception` button will show in the case that an exception list contains exception list item(s) with an empty `entries` array (as long as there is one exception list item with an item in `entries`, button does not show)
- debounces field value autocomplete searches
- bubble up exceptions to parent component, stripping out any empty entries
@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Build metrics

✅ unchanged

History

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

yctercero added a commit that referenced this pull request Jul 2, 2020
### Summary

This PR creates the bulk functionality of the exception builder. The exception builder is the component that will be used to create exception list items. It does not deal with the actual API creation/deletion/update of exceptions, it does contain an `onChange` handler that can be used to access the exceptions. The builder is able to:

- accept `ExceptionListItem` and render them correctly
- allow user to add exception list item and exception list item entries
- accept an `indexPattern` and use it to fetch relevant field and autocomplete field values
- disable `Or` button if user is only allowed to edit/add to exception list item (not add additional exception list items)
- displays `Add new exception` button if no exception items exist
    - An exception item can be created without entries, the `add new exception` button will show in the case that an exception list contains exception list item(s) with an empty `entries` array (as long as there is one exception list item with an item in `entries`, button does not show)
- debounces field value autocomplete searches
- bubble up exceptions to parent component, stripping out any empty entries
gmmorris added a commit to gmmorris/kibana that referenced this pull request Jul 2, 2020
* master: (46 commits)
  [Visualize] Add missing advanced settings and custom label for pipeline aggs (elastic#69688)
  Use dynamic: false for config saved object mappings (elastic#70436)
  [Ingest Pipelines] Error messages (elastic#70167)
  [APM] Show transaction rate per minute on Observability Overview page (elastic#70336)
  Filter out error when calculating a label (elastic#69934)
  [Visualizations] Each visType returns its supported triggers (elastic#70177)
  [Telemetry] Report data shippers (elastic#64935)
  Reduce SavedObjects mappings for Application Usage (elastic#70475)
  [Lens] fix dimension label performance issues (elastic#69978)
  Skip failing endgame tests (elastic#70548)
  [SIEM] Reenabling Cypress tests (elastic#70397)
  [SIEM][Security Solution][Endpoint] Endpoint Artifact Manifest Management + Artifact Download and Distribution (elastic#67707)
  [Security] Adds field mapping support to rule creation (elastic#70288)
  SECURITY-ENDPOINT: add fields for events to metadata document (elastic#70491)
  Fixed assertion in hybrid index pattern test to iterate through indices (elastic#70130)
  [SIEM][Exceptions] - Exception builder component (elastic#67013)
  [Ingest Manager] Rename data sources to package configs (elastic#70259)
  skip suites blocking es snapshot promomotion (elastic#70532)
  [Metrics UI] Fix asynchronicity and error handling in Snapshot API (elastic#70503)
  fix export response (elastic#70473)
  ...
@yctercero yctercero deleted the exception-builder branch October 14, 2020 12:00
@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
release_note:enhancement Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. Team:SIEM v7.9.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants