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

[Detection Engine][Exceptions] - Fix exception item update route #159223

Merged
merged 13 commits into from Jun 9, 2023

Conversation

yctercero
Copy link
Contributor

@yctercero yctercero commented Jun 7, 2023

Summary

Addresses #159230. Fixes a bug in exception item update route. When updating an exception item and not passing in id, id here is undefined and because it does not see an SO to overwrite, it creates it.

Wrote test to confirm that this behavior is occurring:
Screenshot 2023-06-07 at 8 13 09 AM

Checklist

@yctercero yctercero requested review from a team as code owners June 7, 2023 15:16
@yctercero yctercero added v8.9.0 v8.8.2 bug Fixes for quality problems that affect the customer experience release_note:fix Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. Feature:Rule Exceptions Security Solution Rule Exceptions feature Team:Detection Engine Security Solution Detection Engine Area labels Jun 7, 2023
@elasticmachine
Copy link
Contributor

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

@yctercero yctercero self-assigned this Jun 7, 2023
@@ -72,7 +72,7 @@ export const updateOverwriteExceptionListItem = async ({
version: exceptionListItem._version ? parseInt(exceptionListItem._version, 10) : undefined,
},
{
id,
id: exceptionListItem.id,
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we be respecting the id argument at all here?

Suggested change
id: exceptionListItem.id,
id: id ?? exceptionListItem.id,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call! Yes, I think we should.

Comment on lines 34 to 36
// SDH came up where this route was creating a new item when updating
// by item_id, ensuring that's no longer the case
it('should not create a new item on update', async () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we could do away with the comment and put this context into the test description. I deleted the mention of an SDH because IMO the fact that it's a regression test isn't particularly important; deleting a test is an exception for which one had better have a good reason!

Suggested change
// SDH came up where this route was creating a new item when updating
// by item_id, ensuring that's no longer the case
it('should not create a new item on update', async () => {
it('should not create a new item when updating by item_id', async () => {

Copy link
Contributor

@rylnd rylnd 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 id arg is respected and we're 🟢 .

rylnd and others added 5 commits June 7, 2023 16:15
Similar to how specifying item_id when updating causes a new id to be
generated, specifying an id causes the item_id to be deleted if
unspecified.

This commit adds a test to cover this case, along with updating the
existing regression to have more assertions and have more accurate
variable names.
This test attempts to see exactly what's going on with this endpoint,
currently:

1. Create a fully custom, fully specified exception item
    * WIP; see TODOs in code
2. Update it with only the required fields
3. See what changed after the update
yctercero and others added 3 commits June 8, 2023 08:37
* More descriptive test/comments
* Remove server-generated noise from our assertions
* Add comments to the item

This test is currently failing due to the fact that we drop tags if they
aren't specified. Will see if this behavior is consistent with the old
implementation.
If we specify custom tags here, the test will fail because tags are
overwritten if not specified on update.

However, this has always been the behavior of this endpoint (it at least
preceded the changes causing the id-related bugs), so we're leaving it
for now.
@yctercero
Copy link
Contributor Author

@elasticmachine merge upstream

@rylnd
Copy link
Contributor

rylnd commented Jun 8, 2023

@elasticmachine merge upstream

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Unknown metric groups

ESLint disabled line counts

id before after diff
enterpriseSearch 19 21 +2
securitySolution 414 418 +4
total +6

Total ESLint disabled count

id before after diff
enterpriseSearch 20 22 +2
securitySolution 498 502 +4
total +6

History

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

cc @yctercero

@yctercero yctercero merged commit f895c5c into elastic:main Jun 9, 2023
18 checks passed
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Jun 9, 2023
…stic#159223)

## Summary

Addresses issue 159230

(cherry picked from commit f895c5c)
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Jun 9, 2023
…stic#159223)

## Summary

Addresses issue 159230

(cherry picked from commit f895c5c)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.7
8.8

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

Questions ?

Please refer to the Backport tool documentation

saarikabhasi pushed a commit to saarikabhasi/kibana that referenced this pull request Jun 14, 2023
@yctercero yctercero deleted the exceptions_update_route branch June 21, 2023 05:33
mistic pushed a commit that referenced this pull request Jun 21, 2023
#159223) (#159420)

# Backport

This will backport the following commits from `main` to `8.8`:
- [[Detection Engine][Exceptions] - Fix exception item update route
(#159223)](#159223)

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

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

<!--BACKPORT [{"author":{"name":"Yara
Tercero","email":"yctercero@users.noreply.github.com"},"sourceCommit":{"committedDate":"2023-06-09T19:31:03Z","message":"[Detection
Engine][Exceptions] - Fix exception item update route (#159223)\n\n##
Summary\r\n\r\nAddresses issue
159230","sha":"f895c5c2058f3f36c828fe9d8f1dbc0c19a2b381","branchLabelMapping":{"^v8.9.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:fix","Team:
SecuritySolution","Feature:Rule
Exceptions","v8.7.2","v8.9.0","Team:Detection
Engine","v8.8.2"],"number":159223,"url":"#159223
Engine][Exceptions] - Fix exception item update route (#159223)\n\n##
Summary\r\n\r\nAddresses issue
159230","sha":"f895c5c2058f3f36c828fe9d8f1dbc0c19a2b381"}},"sourceBranch":"main","suggestedTargetBranches":["8.7","8.8"],"targetPullRequestStates":[{"branch":"8.7","label":"v8.7.2","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.9.0","labelRegex":"^v8.9.0$","isSourceBranch":true,"state":"MERGED","url":"#159223
Engine][Exceptions] - Fix exception item update route (#159223)\n\n##
Summary\r\n\r\nAddresses issue
159230","sha":"f895c5c2058f3f36c828fe9d8f1dbc0c19a2b381"}},{"branch":"8.8","label":"v8.8.2","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Yara Tercero <yctercero@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Fixes for quality problems that affect the customer experience Feature:Rule Exceptions Security Solution Rule Exceptions feature release_note:fix Team:Detection Engine Security Solution Detection Engine Area Team: SecuritySolution Security Solutions Team working on SIEM, Endpoint, Timeline, Resolver, etc. v8.7.2 v8.8.2 v8.9.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants