Skip to content

[Security Solution] Fix exporting all rules#152900

Merged
maximpn merged 8 commits intoelastic:mainfrom
maximpn:fix-export-all-rules
Mar 10, 2023
Merged

[Security Solution] Fix exporting all rules#152900
maximpn merged 8 commits intoelastic:mainfrom
maximpn:fix-export-all-rules

Conversation

@maximpn
Copy link
Contributor

@maximpn maximpn commented Mar 8, 2023

Relates to: https://github.com/elastic/security-team/issues/5339, #150097, #150553

Summary

This PR fixes all rules exporting functionality which started exporting unintentionally runtime fields like execution_summary. This way it lead to inability to import just exported rules if as minimum one of them executed just once.

On top of this the PR contains functional and Cypress tests to cover the fix.

TODO

Checklist

@maximpn maximpn added 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. Team:Detection Rule Management Security Detection Rule Management Team backport:prev-minor Feature:Rule Import/Export Security Solution Detection Rule Import & Export workflow labels Mar 8, 2023
@maximpn maximpn self-assigned this Mar 8, 2023
@maximpn maximpn changed the title [Security Solution] Fix export all rules [Security Solution] Fix exporting all rules Mar 8, 2023
@maximpn maximpn marked this pull request as ready for review March 8, 2023 12:24
@maximpn maximpn requested review from a team as code owners March 8, 2023 12:24
@maximpn maximpn requested a review from spong March 8, 2023 12:24
@elasticmachine
Copy link
Contributor

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

@elasticmachine
Copy link
Contributor

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

@maximpn maximpn requested a review from xcrzx March 8, 2023 13:42
Comment on lines 67 to 71
Copy link
Contributor

Choose a reason for hiding this comment

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

To clarify, the event log and the .kibana index are separate. Just because the event log contains an "execution complete" event doesn't necessarily mean that the .kibana index has been updated and that the execution_summary has been added to the rule. It's possible for this update to happen before or after the execution event. We shouldn't rely on this assumption.

The best option for us is to poll for the execution_summary update in the rule. But if for some reason, it is complicated, a better solution would be adding a "sleep" function for one second to ensure the .kibana index has been refreshed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Another thought is to try to await for POST /.kibana/_refresh.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've replaced await waitForEventLogExecuteComplete with 1 second delay.

@maximpn maximpn force-pushed the fix-export-all-rules branch from 7e70284 to a405b28 Compare March 10, 2023 13:58
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.

LGTM, thanks for the fix 👍

Copy link
Contributor

@e40pud e40pud left a comment

Choose a reason for hiding this comment

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

LGTM

@kibana-ci
Copy link

💚 Build Succeeded

Metrics [docs]

Async chunks

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

id before after diff
securitySolution 15.7MB 15.7MB +134.0B
Unknown metric groups

ESLint disabled line counts

id before after diff
securitySolution 434 437 +3

Total ESLint disabled count

id before after diff
securitySolution 514 517 +3

History

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

cc @maximpn

@maximpn maximpn merged commit 6b62ae2 into elastic:main Mar 10, 2023
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Mar 10, 2023
**Relates to:** elastic/security-team#5339, elastic#150097, elastic#150553

## Summary

This PR fixes all rules exporting functionality which started exporting unintentionally runtime fields like `execution_summary`. This way it lead to inability to import just exported rules if as minimum one of them executed just once.

On top of this the PR contains functional and Cypress tests to cover the fix.

## TODO

- [ ] get rid of `await waitForEventLogExecuteComplete()` in functional tests
- [ ] allow `getNewRule()` to rewrite its defaults

### Checklist

- [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials
- [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

(cherry picked from commit 6b62ae2)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.7

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Mar 10, 2023
# Backport

This will backport the following commits from `main` to `8.7`:
- [[Security Solution] Fix exporting all rules
(#152900)](#152900)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Maxim
Palenov","email":"maxim.palenov@elastic.co"},"sourceCommit":{"committedDate":"2023-03-10T17:23:48Z","message":"[Security
Solution] Fix exporting all rules (#152900)\n\n**Relates to:**
elastic/security-team#5339,
#150097,
https://github.com/elastic/kibana/pull/150553\r\n\r\n##
Summary\r\n\r\nThis PR fixes all rules exporting functionality which
started exporting unintentionally runtime fields like
`execution_summary`. This way it lead to inability to import just
exported rules if as minimum one of them executed just once.\r\n\r\nOn
top of this the PR contains functional and Cypress tests to cover the
fix.\r\n\r\n## TODO\r\n\r\n- [ ] get rid of `await
waitForEventLogExecuteComplete()` in functional tests\r\n- [ ] allow
`getNewRule()` to rewrite its defaults\r\n\r\n### Checklist\r\n\r\n- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials\r\n- [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","sha":"6b62ae2adfead5ece8b47c0909ab58c67f3f1adb","branchLabelMapping":{"^v8.8.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:Detections
and Resp","Team: SecuritySolution","Team:Detection
Rules","backport:prev-minor","Feature:Rule
Import/Export","v8.8.0"],"number":152900,"url":"https://github.com/elastic/kibana/pull/152900","mergeCommit":{"message":"[Security
Solution] Fix exporting all rules (#152900)\n\n**Relates to:**
elastic/security-team#5339,
#150097,
https://github.com/elastic/kibana/pull/150553\r\n\r\n##
Summary\r\n\r\nThis PR fixes all rules exporting functionality which
started exporting unintentionally runtime fields like
`execution_summary`. This way it lead to inability to import just
exported rules if as minimum one of them executed just once.\r\n\r\nOn
top of this the PR contains functional and Cypress tests to cover the
fix.\r\n\r\n## TODO\r\n\r\n- [ ] get rid of `await
waitForEventLogExecuteComplete()` in functional tests\r\n- [ ] allow
`getNewRule()` to rewrite its defaults\r\n\r\n### Checklist\r\n\r\n- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials\r\n- [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","sha":"6b62ae2adfead5ece8b47c0909ab58c67f3f1adb"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.8.0","labelRegex":"^v8.8.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/152900","number":152900,"mergeCommit":{"message":"[Security
Solution] Fix exporting all rules (#152900)\n\n**Relates to:**
elastic/security-team#5339,
#150097,
https://github.com/elastic/kibana/pull/150553\r\n\r\n##
Summary\r\n\r\nThis PR fixes all rules exporting functionality which
started exporting unintentionally runtime fields like
`execution_summary`. This way it lead to inability to import just
exported rules if as minimum one of them executed just once.\r\n\r\nOn
top of this the PR contains functional and Cypress tests to cover the
fix.\r\n\r\n## TODO\r\n\r\n- [ ] get rid of `await
waitForEventLogExecuteComplete()` in functional tests\r\n- [ ] allow
`getNewRule()` to rewrite its defaults\r\n\r\n### Checklist\r\n\r\n- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials\r\n- [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","sha":"6b62ae2adfead5ece8b47c0909ab58c67f3f1adb"}}]}]
BACKPORT-->

Co-authored-by: Maxim Palenov <maxim.palenov@elastic.co>
bmorelli25 pushed a commit to bmorelli25/kibana that referenced this pull request Mar 10, 2023
**Relates to:** elastic/security-team#5339, elastic#150097, elastic#150553

## Summary

This PR fixes all rules exporting functionality which started exporting unintentionally runtime fields like `execution_summary`. This way it lead to inability to import just exported rules if as minimum one of them executed just once.

On top of this the PR contains functional and Cypress tests to cover the fix.

## TODO

- [ ] get rid of `await waitForEventLogExecuteComplete()` in functional tests
- [ ] allow `getNewRule()` to rewrite its defaults

### Checklist

- [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials
- [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 maximpn deleted the fix-export-all-rules branch March 21, 2023 13:09
maximpn added a commit that referenced this pull request Mar 27, 2023
…153410)

**Relates to:** #152900

## Summary

This PR adds an ability to wait for rule status by its rule id in functional tests. It is a result of splitting of #150553 into isolated parts.

## Details

Based on what kind of id is used (SO id or rule id) it leads to different behaviour under the hood. SO id related functionality consumes ES Get API while rule id related functionality consumes ES Search API. This way it may require to add some delay to let ES to refresh the data if the testing logic consumes ES Search API while rule status was awaited via SO id so that handled by ES Get API. This PR removes such a delay at rule exporting functional tests.
maximpn added a commit to maximpn/kibana that referenced this pull request Apr 4, 2023
…lastic#153410)

**Relates to:** elastic#152900

## Summary

This PR adds an ability to wait for rule status by its rule id in functional tests. It is a result of splitting of elastic#150553 into isolated parts.

## Details

Based on what kind of id is used (SO id or rule id) it leads to different behaviour under the hood. SO id related functionality consumes ES Get API while rule id related functionality consumes ES Search API. This way it may require to add some delay to let ES to refresh the data if the testing logic consumes ES Search API while rule status was awaited via SO id so that handled by ES Get API. This PR removes such a delay at rule exporting functional tests.

(cherry picked from commit 519185f)

# Conflicts:
#	x-pack/test/cases_api_integration/common/lib/alerts.ts
maximpn referenced this pull request Apr 4, 2023
…per (#153410) (#154328)

# Backport

This will backport the following commits from `main` to `8.7`:
- [[Security Solution] Support rule id in wait for rule status helper
(#153410)](#153410)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Maxim
Palenov","email":"maxim.palenov@elastic.co"},"sourceCommit":{"committedDate":"2023-03-27T09:03:15Z","message":"[Security
Solution] Support rule id in wait for rule status helper
(#153410)\n\n**Relates to:**
https://github.com/elastic/kibana/pull/152900\r\n\r\n##
Summary\r\n\r\nThis PR adds an ability to wait for rule status by its
rule id in functional tests. It is a result of splitting of
#150553 into isolated
parts.\r\n\r\n## Details\r\n\r\nBased on what kind of id is used (SO id
or rule id) it leads to different behaviour under the hood. SO id
related functionality consumes ES Get API while rule id related
functionality consumes ES Search API. This way it may require to add
some delay to let ES to refresh the data if the testing logic consumes
ES Search API while rule status was awaited via SO id so that handled by
ES Get API. This PR removes such a delay at rule exporting functional
tests.","sha":"519185ffa88aeea05626f71b303a7daf1ce9d14b","branchLabelMapping":{"^v8.8.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["refactoring","technical
debt","release_note:skip","test-api-integration","Team:Detections and
Resp","Team: SecuritySolution","Team:Detection
Rules","backport:prev-minor","v8.8.0"],"number":153410,"url":"https://github.com/elastic/kibana/pull/153410","mergeCommit":{"message":"[Security
Solution] Support rule id in wait for rule status helper
(#153410)\n\n**Relates to:**
https://github.com/elastic/kibana/pull/152900\r\n\r\n##
Summary\r\n\r\nThis PR adds an ability to wait for rule status by its
rule id in functional tests. It is a result of splitting of
#150553 into isolated
parts.\r\n\r\n## Details\r\n\r\nBased on what kind of id is used (SO id
or rule id) it leads to different behaviour under the hood. SO id
related functionality consumes ES Get API while rule id related
functionality consumes ES Search API. This way it may require to add
some delay to let ES to refresh the data if the testing logic consumes
ES Search API while rule status was awaited via SO id so that handled by
ES Get API. This PR removes such a delay at rule exporting functional
tests.","sha":"519185ffa88aeea05626f71b303a7daf1ce9d14b"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v8.8.0","labelRegex":"^v8.8.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/153410","number":153410,"mergeCommit":{"message":"[Security
Solution] Support rule id in wait for rule status helper
(#153410)\n\n**Relates to:**
https://github.com/elastic/kibana/pull/152900\r\n\r\n##
Summary\r\n\r\nThis PR adds an ability to wait for rule status by its
rule id in functional tests. It is a result of splitting of
#150553 into isolated
parts.\r\n\r\n## Details\r\n\r\nBased on what kind of id is used (SO id
or rule id) it leads to different behaviour under the hood. SO id
related functionality consumes ES Get API while rule id related
functionality consumes ES Search API. This way it may require to add
some delay to let ES to refresh the data if the testing logic consumes
ES Search API while rule status was awaited via SO id so that handled by
ES Get API. This PR removes such a delay at rule exporting functional
tests.","sha":"519185ffa88aeea05626f71b303a7daf1ce9d14b"}}]}]
BACKPORT-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Feature:Rule Import/Export Security Solution Detection Rule Import & Export workflow release_note:skip Skip the PR/issue when compiling release notes 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 v8.8.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants