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]Fix incorrect number of invalid connectors is shown on the toast message #152313

Merged
merged 10 commits into from
Mar 6, 2023

Conversation

WafaaNasr
Copy link
Contributor

@WafaaNasr WafaaNasr commented Feb 28, 2023

Summary

Before the fix, the number of missing connectors was always 1, even if the message says the invalid connectors are more
image

After,

image

Checklist

@WafaaNasr WafaaNasr added release_note:skip Skip the PR/issue when compiling release notes Team:Security Solution Platform Security Solution Platform Team backport:prev-minor Backport to (9.0) the previous minor version (i.e. one version back from main) v8.7.0 labels Feb 28, 2023
@WafaaNasr WafaaNasr self-assigned this Feb 28, 2023
@WafaaNasr WafaaNasr requested review from a team as code owners February 28, 2023 08:38
@WafaaNasr WafaaNasr requested a review from maximpn February 28, 2023 08:38
@WafaaNasr WafaaNasr added the ci:cloud-deploy Create or update a Cloud deployment label Feb 28, 2023
Copy link
Contributor

@maximpn maximpn left a comment

Choose a reason for hiding this comment

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

@WafaaNasr thank you for fixing this bug 🙏 Let's just explore edge cases to make sure there are no bugs here.

const { error } = connectorError;
let concatenatedActionIds: string = '';
const mappedErrors = actionConnectorsErrors.map((connectorError) => {
const { id, error } = connectorError as ImportResponseError;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why isn't it possible to just calculate the number of errors? Can we get more than one error per connector?

Generally speaking ImportRulesResponseError | ImportResponseError only differs by id and rule_id which come from BulkError (just the fact BulkError allows to omit both id and rule_id which is not supposed to happen I expect but it's another story). If we still support rule_id (most probably for backwards compatibility) can we have a situation when it's in use and this code is gonna fail? If it's not a case so then we should remove rule_id so as ImportResponseError type casting won't be necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why isn't it possible to just calculate the number of errors? Can we get more than one error per connector?

-Yes true.
Forex. if the user has rule to import in one file, and this rule has 3 connectors.

For instance, if 2 of them have missing connectors, what will happen as per the Old workflow=> One error message will be generated with the count of the failing connectors, and one error object will be pushed in the array.
2 connectors are missing. Connector ids missing are: X, Y

And just to clarify the id here is the action-connectors id not the rule_id

Copy link
Contributor

Choose a reason for hiding this comment

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

Hey @maximpn ! rule_id was initially created to act as a signature id so that a rule could be recognized, say, across platforms. This allows sigma, snort, suricata etc to identify a rule with a singular "signature id" that is never regenerated over time. So the concept of rule_id should hopefully stick around the solution unless platform has come up with a way for it to be supported more globally within a saved object. This comes in very handy on import when a user could be importing a rule they've ported over from elsewhere and want to maintain it's reference to the signature id. I don't think it would be in our interest to remove it's use. Like @WafaaNasr pointed out, the id she references is to the connector, the rule_id points back to the rule that had an action pointing to said connector so the user knows which rule was the source of the error.

If there's a worry that id would not exist in connectorError because it ends up being ImportRulesResponseError vs ImportResponseError maybe we can add a check for id != null.

If there's larger refactoring you think is necessary (this route is now a bit dated and could benefit from refactoring as it's complexity has grown a lot), feel free to create a ticket and we can keep discussing what the response should look like and how rule_id fits into the import use case.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hey @yctercero, thank you for the explanation! My concern is misleading types as BulkError at backend and ImportRulesResponseError at frontend don't look related to the connectors. ImportResponseError looks too generic (by name). According to what I see in the code it's pretty easy to use some tailored for connectors error type which action_connectors_errors will use.

Absence of such a type leads to reusing id and rule_id fields to store serialized arrays in a case of missing connectors. I'm afraid it doesn't match with SO importer errors so that importer seems to returning an error per connector. Merging it now and creating a ticket looks like adding a technical debt while we already have it a lot.

Copy link
Contributor

Choose a reason for hiding this comment

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

There's definitely refactoring needed overall on import. It used to just be rules and now is exceptions, actions and connectors. With the added comments, we can certainly look to simplify and refactor this flow.

Copy link
Contributor

Choose a reason for hiding this comment

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

I understand the concern with creating technical debt. As we are far into the BCs, adding scope in this bug fix can also open us up to further bugs. Our team is working on documenting this route, the technical debt and suggested updates. I can be sure to make reference back to your concerns to ensure they're addressed in any upcoming refactors.

Copy link
Contributor

Choose a reason for hiding this comment

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

Here we go #152648

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you @maximpn !

@@ -178,6 +178,7 @@ describe('checkRuleExceptionReferences', () => {
'1 connector is missing. Connector id missing is: cabc78e0-9031-11ed-b076-53cc4d57aaf1',
status_code: 404,
},
id: 'cabc78e0-9031-11ed-b076-53cc4d57aaf1',
Copy link
Contributor

Choose a reason for hiding this comment

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

Interesting, you provide both id and rule_id in tests while it should be one of them according to the operated types. See my question regarding them above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They are different id is the actionConnectors ids and the rule_id is the rule to be imported.

And we need it, in case the user has multiple rules in one file and not all of them are failing

Copy link
Contributor

Choose a reason for hiding this comment

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

I see. For some reason actionsImporter returns a comma separated list of connector identifiers in id field and we don't have any breakdown on this. So this list corresponds to a rule.

@@ -40,6 +40,7 @@ export const handleActionsHaveNoConnectors = (
: 'connector is missing. Connector id missing is:';
errors.push(
createBulkErrorObject({
id: actionsIds.join(),
Copy link
Contributor

Choose a reason for hiding this comment

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

As id field stores a serialized array it worth to have a comment in BulkError and ImportResponseError to highlight that fact it can contain more than one identifier in a case of missing connectors.

Copy link
Contributor

Choose a reason for hiding this comment

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

We'll go ahead and add a comment there. Looks like rule_id has been used this way for a bit. Will be sure to document.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please review bc5547c

@@ -40,6 +40,7 @@ export const handleActionsHaveNoConnectors = (
: 'connector is missing. Connector id missing is:';
errors.push(
createBulkErrorObject({
id: actionsIds.join(),
statusCode: 404,
message: `${actionsIds.length} ${errorMessage} ${actionsIds.join(', ')}`,
ruleId: ruleIds,
Copy link
Contributor

@maximpn maximpn Mar 2, 2023

Choose a reason for hiding this comment

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

As rule_id field stores a serialized array it worth to have a comment in BulkError and ImportRuleResponseError to highlight that fact it can contain more than one identifier in a case of missing connectors.

Copy link
Contributor

Choose a reason for hiding this comment

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

We'll go ahead and add a comment there. Looks like rule_id has been used this way for a bit. Will be sure to document.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please review here bc5547c

@WafaaNasr
Copy link
Contributor Author

@elasticmachine merge upstream

Copy link
Contributor

@yctercero yctercero 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 and adding comments to clarify some of our existing types.

@kibana-ci
Copy link
Collaborator

kibana-ci commented Mar 2, 2023

💚 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 +644.0B
Unknown metric groups

ESLint disabled line counts

id before after diff
securitySolution 428 430 +2

Total ESLint disabled count

id before after diff
securitySolution 506 508 +2

History

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

cc @WafaaNasr

Copy link
Contributor

@maximpn maximpn left a comment

Choose a reason for hiding this comment

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

@WafaaNasr Thank you for addressing my comments 👍 I've created a refactoring ticket so the rest of my concerns should be addressed there.

@WafaaNasr WafaaNasr merged commit c0d2b0f into elastic:main Mar 6, 2023
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Mar 6, 2023
…n on the toast message (elastic#152313)

## Summary

- Addresses elastic#151988

Before the fix, the number of missing connectors was always 1, even if
the message says the invalid connectors are more

![image](https://user-images.githubusercontent.com/12671903/221798261-8fb7ba28-3a1a-4269-9e00-a540f7febb1b.png)

After,

![image](https://user-images.githubusercontent.com/12671903/221798298-1f3728b2-d7a9-41c9-a0f4-d80892a7c0f1.png)

### 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

---------

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit c0d2b0f)
@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 6, 2023
…s shown on the toast message (#152313) (#152661)

# Backport

This will backport the following commits from `main` to `8.7`:
- [[Security Solution]Fix incorrect number of invalid connectors is
shown on the toast message
(#152313)](#152313)

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

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

<!--BACKPORT [{"author":{"name":"Wafaa
Nasr","email":"wafaa.nasr@elastic.co"},"sourceCommit":{"committedDate":"2023-03-06T08:24:00Z","message":"[Security
Solution]Fix incorrect number of invalid connectors is shown on the
toast message (#152313)\n\n## Summary\r\n\r\n- Addresses
https://github.com/elastic/kibana/issues/151988\r\n\r\nBefore the fix,
the number of missing connectors was always 1, even if\r\nthe message
says the invalid connectors are
more\r\n\r\n![image](https://user-images.githubusercontent.com/12671903/221798261-8fb7ba28-3a1a-4269-9e00-a540f7febb1b.png)\r\n\r\nAfter,\r\n\r\n\r\n![image](https://user-images.githubusercontent.com/12671903/221798298-1f3728b2-d7a9-41c9-a0f4-d80892a7c0f1.png)\r\n\r\n\r\n###
Checklist\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: Kibana Machine
<42973632+kibanamachine@users.noreply.github.com>","sha":"c0d2b0f5cc7d5915f9f3894cdccfc7513a61cdc6","branchLabelMapping":{"^v8.8.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:Security
Solution
Platform","backport:prev-minor","ci:cloud-deploy","v8.7.0","v8.8.0"],"number":152313,"url":"https://github.com/elastic/kibana/pull/152313","mergeCommit":{"message":"[Security
Solution]Fix incorrect number of invalid connectors is shown on the
toast message (#152313)\n\n## Summary\r\n\r\n- Addresses
https://github.com/elastic/kibana/issues/151988\r\n\r\nBefore the fix,
the number of missing connectors was always 1, even if\r\nthe message
says the invalid connectors are
more\r\n\r\n![image](https://user-images.githubusercontent.com/12671903/221798261-8fb7ba28-3a1a-4269-9e00-a540f7febb1b.png)\r\n\r\nAfter,\r\n\r\n\r\n![image](https://user-images.githubusercontent.com/12671903/221798298-1f3728b2-d7a9-41c9-a0f4-d80892a7c0f1.png)\r\n\r\n\r\n###
Checklist\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: Kibana Machine
<42973632+kibanamachine@users.noreply.github.com>","sha":"c0d2b0f5cc7d5915f9f3894cdccfc7513a61cdc6"}},"sourceBranch":"main","suggestedTargetBranches":["8.7"],"targetPullRequestStates":[{"branch":"8.7","label":"v8.7.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.8.0","labelRegex":"^v8.8.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/152313","number":152313,"mergeCommit":{"message":"[Security
Solution]Fix incorrect number of invalid connectors is shown on the
toast message (#152313)\n\n## Summary\r\n\r\n- Addresses
https://github.com/elastic/kibana/issues/151988\r\n\r\nBefore the fix,
the number of missing connectors was always 1, even if\r\nthe message
says the invalid connectors are
more\r\n\r\n![image](https://user-images.githubusercontent.com/12671903/221798261-8fb7ba28-3a1a-4269-9e00-a540f7febb1b.png)\r\n\r\nAfter,\r\n\r\n\r\n![image](https://user-images.githubusercontent.com/12671903/221798298-1f3728b2-d7a9-41c9-a0f4-d80892a7c0f1.png)\r\n\r\n\r\n###
Checklist\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common
scenarios\r\n\r\n---------\r\n\r\nCo-authored-by: Kibana Machine
<42973632+kibanamachine@users.noreply.github.com>","sha":"c0d2b0f5cc7d5915f9f3894cdccfc7513a61cdc6"}}]}]
BACKPORT-->

Co-authored-by: Wafaa Nasr <wafaa.nasr@elastic.co>
bmorelli25 pushed a commit to bmorelli25/kibana that referenced this pull request Mar 10, 2023
…n on the toast message (elastic#152313)

## Summary

- Addresses elastic#151988

Before the fix, the number of missing connectors was always 1, even if
the message says the invalid connectors are more

![image](https://user-images.githubusercontent.com/12671903/221798261-8fb7ba28-3a1a-4269-9e00-a540f7febb1b.png)

After,


![image](https://user-images.githubusercontent.com/12671903/221798298-1f3728b2-d7a9-41c9-a0f4-d80892a7c0f1.png)


### 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

---------

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
@WafaaNasr WafaaNasr deleted the fix-incorrect-invalid-connectors branch February 6, 2024 10:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:prev-minor Backport to (9.0) the previous minor version (i.e. one version back from main) ci:cloud-deploy Create or update a Cloud deployment release_note:skip Skip the PR/issue when compiling release notes Team:Security Solution Platform Security Solution Platform Team v8.7.0 v8.8.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants