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

[CTI] Filters alerts table by presence of threat (elastic/security-team#907) #96096

Merged
merged 12 commits into from
Apr 12, 2021

Conversation

ecezalp
Copy link
Contributor

@ecezalp ecezalp commented Apr 1, 2021

Closes elastic/security-team#907.

Summary

This change enables alert table filtering by the presence of signal.rule.threat_mapping. Previously we have discussed the usage of threat.indicator.matched to detect whether an alert is a "threat" or not, but I was unable to get hits on threat and any fields that would be under it, even though I was able to see the fields when I queried my siem-signals index with a match all query. So, this implementation detail (using signal.rule.threat_mapping instead of threat.indicator.matched is up for discussion.

Another interesting finding was around the default filters, it appeared that the filters were reversed, in the sense that I had to use a must_not query to obtain the results containing the threats, as opposed to a must. I found this peculiar, so please let me know if there are any improvements to be made in this area.

Lastly, a few unit tests were added, but so far there are no integration tests, I wasn't able to find if the Alerts Table is currently covered with integration tests, so I would appreciate a nudge towards that direction.

Images

not applied (Detections Home)
Screen Shot 2021-04-01 at 4 32 14 PM

applied (Detections Home)
Screen Shot 2021-04-01 at 4 32 24 PM

also available on the Rules page
Screen Shot 2021-04-01 at 4 34 20 PM

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@ecezalp ecezalp requested review from rylnd and a team April 1, 2021 20:27
@ecezalp ecezalp added release_note:feature Makes this part of the condensed release notes v7.13.0 labels Apr 1, 2021
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.

So, this implementation detail (using signal.rule.threat_mapping instead of threat.indicator.matched is up for discussion.

My initial thinking was that we need a canonical definition for a threat match alert, and that "has threat match fields" was the simplest answer. To that end, I'd be happy to pair to see if we can't figure out a query that works; I'm guessing it's either the nested fields thing, or a consequence of the fields being requested.

I was also going to claim that this logic would also catch old, pre-enriched indicator alerts (which I don't think we want), however, we didn't have mappings for these fields until 7.12, so (I think) both enrichment and the ability to query threat_mapping happened in the same release, so this should work? Regardless, I think we should try to make the former work before settling on this solution.

You've got some type failures which look related to one of my questions, so let's discuss this again on Monday :)

@ecezalp ecezalp requested a review from a team as a code owner April 6, 2021 14:45
filter instead to achieve the same result. An old TODO has been
addressed by adding an optional boolean exists to Filter type
@ecezalp
Copy link
Contributor Author

ecezalp commented Apr 6, 2021

@kibana-app-services you have been summoned because I temporarily removed a TODO that was left in the codebase, which suppressed a ts-error regarding the Filter not having an "exists" field. I briefly added an optional field to the Filter object in the data plugin, but that seemed to result in a lot of type errors in this build, so I decided to bring back the TODO -- nothing to see here. Creating a new ticket for the removal of the TODO for the future, will attach to this comment shortly.

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.

The filter functionality works great! The only things to address are the label copy and the space between the two labels.

@@ -159,6 +167,20 @@ const AlertsUtilityBarComponent: React.FC<AlertsUtilityBarProps> = ({
label={i18n.ADDITIONAL_FILTERS_ACTIONS_SHOW_BUILDING_BLOCK}
/>
</BuildingBlockContainer>
<ThreatMatchContainer>
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

Suggested change
<ThreatMatchContainer>
<ThreatMatchFilterContainer>

export const ADDITIONAL_FILTERS_ACTIONS_SHOW_THREAT_MATCHES_ONLY = i18n.translate(
'xpack.securitySolution.detectionEngine.alerts.utilityBar.additionalFiltersActions.showThreatMatchesOnly',
{
defaultMessage: 'Show threat indicator matches only',
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
defaultMessage: 'Show threat indicator matches only',
defaultMessage: 'Show only threat match alerts',

Thoughts: I would emphasize the entities that this filter is acting on (alerts), and move "only" to the beginning of the label since it's logically different than the existing building block query.

RE qualifying alert, I like "threat indicator alert" more than "threat indicator match alert" as that seems redundant, but we should probably rope product in for the final say here. /cc @MikePaquette @devonakerr

Choose a reason for hiding this comment

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

I think "threat indicator match alert" is awkward, and "threat indicator alert" is more concise without losing meaning.

Copy link
Contributor Author

@ecezalp ecezalp Apr 7, 2021

Choose a reason for hiding this comment

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

updating as Show only threat indicator alerts

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.

I think this PR unintentionally inverted the logic of the building block filter; please do fix that before merging. Other than that, this looks great!

@@ -286,10 +288,11 @@ const RuleDetailsPageComponent = () => {

const alertDefaultFilters = useMemo(
() => [
...(ruleId != null ? buildAlertsRuleIdFilter(ruleId) : []),
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we safely remove this ternary that was here before? What was its purpose?

Copy link
Contributor

Choose a reason for hiding this comment

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

Update: never mind, I see that you moved this logic into the function itself 👍

Copy link
Contributor

Choose a reason for hiding this comment

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

Would be great to add a quick unit test for that 😉

onShowBuildingBlockAlertsChanged: (showBuildingBlockAlerts: boolean) => void;
onShowThreatMatchesOnlyChanged: (showBuildingBlockAlerts: boolean) => void;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit:

Suggested change
onShowThreatMatchesOnlyChanged: (showBuildingBlockAlerts: boolean) => void;
onShowThreatMatchesOnlyChanged: (showThreatMatchesOnly: boolean) => void;


export const buildShowBuildingBlockFilter = (showBuildingBlockAlerts: boolean): Filter[] => [
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 the logic was inverted here; we were previously returning an empty array if showBuildingBlockAlerts was truthy.

@kibanamachine
Copy link
Contributor

💛 Build succeeded, but was flaky


Test Failures

Kibana Pipeline / general / "before all" hook for "should open a modal".Open timeline Open timeline modal "before all" hook for "should open a modal"

Link to Jenkins

Stack Trace

Failed Tests Reporter:
  - Test has not failed recently on tracked branches

AssertionError: Timed out retrying after 60000ms: Expected to find element: `[data-test-subj="title-924470b0-9bca-11eb-bf7d-539c5070ec2a"]`, but never found it.

Because this error occurred during a `before all` hook we are skipping the remaining tests in the current suite: `Open timeline`

Although you have test retries enabled, we do not retry tests when `before all` or `after all` hooks fail
    at Object.openTimelineById (http://localhost:6121/__cypress/tests?p=cypress/integration/timelines/open_timeline.spec.ts:16092:15)
    at Context.eval (http://localhost:6121/__cypress/tests?p=cypress/integration/timelines/open_timeline.spec.ts:15046:28)

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 7.3MB 7.3MB +2.9KB

History

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

@ecezalp ecezalp merged commit e7ecad7 into elastic:master Apr 12, 2021
ecezalp added a commit to ecezalp/kibana that referenced this pull request Apr 12, 2021
…am#907) (elastic#96096)

[CTI] Filters alerts table by presence of threat (elastic/security-team#907)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport release_note:feature Makes this part of the condensed release notes Team: CTI v7.13.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants