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] Persistent rules table state #145111

Merged
merged 54 commits into from Dec 12, 2022

Conversation

maximpn
Copy link
Contributor

@maximpn maximpn commented Nov 14, 2022

Addresses: #140263

Summary

It implements rules table state persistence. Reopening or reloading of the page loads the same state as well as navigation from another page inside or outside the security plugin.

Screen.Recording.2022-11-15.at.18.13.17.mov

Details

The changes persist the rules table state in the url and the session storage to be able to recover after navigation from another page. The following parameters are persisted

  • search term, tags and elastic vs custom filters
  • sorting field and sorting direction
  • page number (only in the url) and page size

Page number is only persisted in the url. Avoiding persistence a page number in the session storage make the UX more predictable that users upon returning to the page expect the first page to be selected.

Selection state is not persisted since it can lead to URL overflow problem. According to the different resources for example this one the maximum length should not exceed 2KB though Chrome supports URLs up to 2MB.

Besides that this PR adds

  • unit tests which coved edge cases
  • basic Cypress tests

What is not done and will be addressed in the next PRs

  • persistence of the selected tab as a path segment in the url
  • comprehensive Cypress tests covering edge cases
  • getting rid of the back button < Rules on the rule details page

Edge cases

Since parameters in the URL and the session storage can be modified by users it can lead to unexpected results or security risks.
What have been tested and covered so far:

  • arbitrary modification of the serialized state which leads to deserialization error (default parameters are used in this case and the state is rewritten with the default parameters)
  • filter parameters modification (doesn't cause errors)
  • page number modification (isn't not handled in a special way, EuiBasicTable display either first of the last page if the value exceeds the limits)
  • page size (EuiBasicTable loads more records which isn't limited and can cause a performance issue, it has been addressed through validation)
  • sorting parameters modification (EuiBasicTable ignores wrong values)

The observation result is that EuiBasicTable gracefully handles the wrong values .

Checklist

@maximpn maximpn self-assigned this Nov 14, 2022
@maximpn maximpn linked an issue Nov 14, 2022 that may be closed by this pull request
5 tasks
@maximpn maximpn added Team:Detections and Resp Security Detection Response Team Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. Team:Detection Rule Management Security Detection Rule Management Team enhancement New value added to drive a business result Feature:Rule Management Security Solution Detection Rule Management v8.7.0 backport:prev-minor Backport to the previous minor version (i.e. one version back from main) release_note:enhancement labels Nov 14, 2022
@maximpn maximpn force-pushed the persistent-rules-table-state branch 5 times, most recently from 46606d8 to 3200603 Compare November 15, 2022 20:42
@maximpn maximpn marked this pull request as ready for review November 15, 2022 22:54
@maximpn maximpn requested review from a team as code owners November 15, 2022 22:54
@maximpn maximpn requested a review from jpdjere November 15, 2022 22:54
@elasticmachine
Copy link
Contributor

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

@elasticmachine
Copy link
Contributor

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

@xcrzx xcrzx self-requested a review November 16, 2022 10:17
Copy link
Contributor

@xcrzx xcrzx left a comment

Choose a reason for hiding this comment

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

I've briefly looked through the implementation and left some initial comments. I think my biggest concern currently is about the usage of local storage. Therefore, I propose discussing alternatives before proceeding with the implementation.

@maximpn maximpn force-pushed the persistent-rules-table-state branch 5 times, most recently from fd0af5c to 1c6cf42 Compare November 17, 2022 12:35
@maximpn
Copy link
Contributor Author

maximpn commented Dec 9, 2022

@elasticmachine merge upstream

@maximpn
Copy link
Contributor Author

maximpn commented Dec 12, 2022

@elasticmachine merge upstream

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
securitySolution 3381 3387 +6

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
securitySolution 10.1MB 10.1MB +4.2KB

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
securitySolution 51.0KB 51.0KB +79.0B
Unknown metric groups

ESLint disabled in files

id before after diff
osquery 1 2 +1

ESLint disabled line counts

id before after diff
enterpriseSearch 19 21 +2
fleet 60 66 +6
osquery 109 115 +6
securitySolution 445 451 +6
total +20

Total ESLint disabled count

id before after diff
enterpriseSearch 20 22 +2
fleet 69 75 +6
osquery 110 117 +7
securitySolution 521 527 +6
total +21

History

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

cc @maximpn

@maximpn maximpn merged commit 2cf74a1 into elastic:main Dec 12, 2022
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Dec 12, 2022
saarikabhasi pushed a commit to saarikabhasi/kibana that referenced this pull request Dec 14, 2022
**Addresses:** elastic#140263

## Summary

It implements rules table state persistence. Reopening or reloading of the page loads the same state as well as navigation from another page inside or outside the security plugin.

https://user-images.githubusercontent.com/3775283/201983621-e57e8c64-d5fb-4111-92df-ebe912dada38.mov

## Details

The changes persist the rules table state in the url and the session storage to be able to recover after navigation from another page. The following parameters are persisted

- search term, tags and elastic vs custom filters
- sorting field and sorting direction
- page number **(only in the url)** and page size

Page number is only persisted in the url. Avoiding persistence a page number in the session storage make the UX more predictable that users upon returning to the page expect the first page to be selected. 

Selection state is not persisted since it can lead to URL overflow problem. According to the different resources for example [this one](https://www.geeksforgeeks.org/maximum-length-of-a-url-in-different-browsers/) the maximum length should not exceed 2KB though Chrome supports URLs up to 2MB.

Besides that this PR adds

- unit tests which coved edge cases
- basic Cypress tests

What is not done and will be addressed in the next PRs

- persistence of the selected tab as a path segment in the url
- comprehensive Cypress tests covering edge cases
- getting rid of the back button `< Rules` on the rule details page

## Edge cases

Since parameters in the URL and the session storage can be modified by users it can lead to unexpected results or security risks.
What have been tested and covered so far:

- arbitrary modification of the serialized state which leads to deserialization error (default parameters are used in this case and the state is rewritten with the default parameters)
- filter parameters modification (doesn't cause errors)
- page number modification (isn't not handled in a special way, `EuiBasicTable` display either first of the last page if the value exceeds the limits)
- page size (`EuiBasicTable` loads more records which isn't limited and can cause a performance issue, it **has been addressed** through validation)
- sorting parameters modification (`EuiBasicTable` ignores wrong values)

The observation result is that `EuiBasicTable` gracefully handles the wrong values .

### Checklist

- [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
maximpn added a commit that referenced this pull request Jan 5, 2023
…147218)

Addresses: #140263

This PR was inspired by #146649 and while working on persistent rules table state #145111.

## Summary

It includes improvements for url search parameters manipulation functionality. In particular `useGetInitialUrlParamValue` and `useReplaceUrlParams` hooks.

The main idea is to isolate the encoding layer ([rison](https://github.com/Nanonid/rison)) as an implementation detail so `useGetInitialUrlParamValue` and `useReplaceUrlParams` consumers can just provide types they wish and the hooks serialize/desirealize the data into appropriate format under the hood.

On top of that after `@kbn/rison` was added in #146649 it's possible to use this package directly to encode and decode parameters whenever necessary.

The improvements include
- store unserialized url parameters state in the redux store
- encode and decode data by using functions from `@kbn/rison` directly
- let `useReplaceUrlParams` accept an updater object

### Checklist

- [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting enhancement New value added to drive a business result Feature:Rule Management Security Solution Detection Rule Management release_note:enhancement Team:Detection Rule Management Security Detection Rule Management Team Team:Detections and Resp Security Detection Response Team Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. v8.7.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

10 participants