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] Adds Threat Intel Tab to Alert Summary Flyout #97185

Merged
merged 12 commits into from
Apr 19, 2021

Conversation

ecezalp
Copy link
Contributor

@ecezalp ecezalp commented Apr 14, 2021

Summary

Updates Threat Summary & Threat Details features to match the updated designs.

no threat - summary
Screen Shot 2021-04-14 at 4 12 07 PM

no threat - threat intel
Screen Shot 2021-04-14 at 4 12 15 PM

threat - summary
Screen Shot 2021-04-14 at 4 12 24 PM

threat - threat intel
Screen Shot 2021-04-14 at 4 18 11 PM

Notes

Relates to elastic/security-team#961 - confidence field is passing through with no additional engineering as you can see from the last attached image above.

Checklist

Delete any items that are not applicable to this PR.

For maintainers

@ecezalp ecezalp added v7.13.0 release_note:feature Makes this part of the condensed release notes 7.13 candidate Team: CTI labels Apr 14, 2021
@ecezalp ecezalp requested review from rylnd and a team April 14, 2021 20:47
@ecezalp ecezalp self-assigned this Apr 14, 2021
@ecezalp
Copy link
Contributor Author

ecezalp commented Apr 14, 2021

@elasticmachine merge upstream

@ecezalp ecezalp changed the title Security team 998 [CTI] Adds Threat Intel Tab to Alert Summary Flyout Apr 14, 2021
@rylnd
Copy link
Contributor

rylnd commented Apr 14, 2021

RE labels: I think you want auto-backport instead of backport, and release_note-wise I would qualify this as either enhancement or maybe even skip, since #95604 was already a feature

@ecezalp
Copy link
Contributor Author

ecezalp commented Apr 15, 2021

latest changes

  • updated design
  • minor cleanups

Screen Shot 2021-04-15 at 9 55 46 AM

@ecezalp ecezalp added auto-backport Deprecated - use backport:version if exact versions are needed release_note:skip Skip the PR/issue when compiling release notes and removed backport release_note:feature Makes this part of the condensed release notes labels Apr 15, 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.

This is looking fantastic! We just need to add the first_seen sorting on details and fix up a few minor UI things.

With this refactor it definitely feels like we're doing too much client-side data manipulation (independent of the JSON.parse 😅 ); it's likely not a huge performance concern as it's one alert, but the code is pretty hard to follow right now. I left some thoughts/pointers, but as always I'm happy to either a) pair on it together or b) be told I'm wrong 😄

return (
threatDetailsRows: ThreatDetailsRow[][];
}> = ({ threatDetailsRows }) =>
!threatDetailsRows[0] || threatDetailsRows[0].length === 0 ? (
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I think isEmpty would work here:

Suggested change
!threatDetailsRows[0] || threatDetailsRows[0].length === 0 ? (
isEmpty(threatDetailsRows[0]) ? (

</EuiTitle>
<StyledSpan>
{i18n.IF_CTI_NOT_ENABLED}
<a
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use EuiLink here, that'll add the "external link" indicator that you see elsewhere.

>
}) => {
const tooltipChild = linkFields.some((field) => field === fieldName) ? (
<a href={value} target="_blank" rel="noreferrer">
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto here with EuiLink

import { getDataFromSourceHits } from '../../../../common/utils/field_formatters';
import { INDICATOR_DESTINATION_PATH } from '../../../../common/constants';

const linkFields = ['threat.indicator.event.url', 'threat.indicator.event.reference'];
Copy link
Contributor

Choose a reason for hiding this comment

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

More magic strings, we'll need to consolidate those once the row renderer is merged 👍

`;

const StyledSpan = styled.span`
color: ${euiPaletteGray(5)[2]};
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this going to work with both light and dark themes? We may want to pull a semantic color from the theme itself.

}
`;

const StyledDiv = styled.div`
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
const StyledDiv = styled.div`
const FlexDiv = styled.div`

align-items: center;
`;

const StyledEuiIcon = styled(EuiIcon)`
Copy link
Contributor

Choose a reason for hiding this comment

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

I would try to give more semantic names to these styled components you're creating; a Styled prefix doesn't tell someone looking at this code why it has the given CSS.

<StyledSpan>
{i18n.IF_CTI_NOT_ENABLED}
<a
href="https://www.elastic.co/guide/en/beats/filebeat/7.12/filebeat-module-threatintel.html"
Copy link
Contributor

Choose a reason for hiding this comment

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

Check out the docLinks service for a more robust way to build this URI. I think docLinks.links.filebeat.base might be it?

'last_seen',
];

export const useThreatIntelTabs = (
Copy link
Contributor

Choose a reason for hiding this comment

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

My first impression is that this hook is doing a lot 😅 , and it's only used in one place. The only state I see that makes it hook-worthy is the cached computations, is that correct?

If nothing else, we should try to decompose this to make it more reusable/recomposable if we do see this being used in the future. If we can abstract these data-manipulation pieces out into pure functions, then the hook is just a little logic and a few simple uses of useMemo.

However this shakes out, some kind of tests around this would be nice as documentation to further support/encourage reuse, as well.

if (selectedTabId !== EventsViewType.summaryView) return rows;
return threatData
.reduce((acc, items) => {
items.forEach(({ field, originalValue }) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

This forEach within the reduce seems indicative of us doing something unnecessary; is it perhaps that we're having to undo part of what getDataFromSourceHits does above?

At a high level, this seems like what we need, data-manipulation-wise:

const summaryFields = ['threat.indicator.matched.atomic', 'etc.'];
const indicatorJSON = data.find(field === 'threat.indicator');
const indicatorFields = data.filter(isIndicatorField);
const threatSummaryRows = buildThreatSummaryRows(summaryFields, indicatorFieldsFields);
const threatDetailsRows = buildThreatDetailsRows(indicatorJSON, ALL_INDICATOR_FIELDS).sort('first_seen', 'desc');

@ecezalp ecezalp requested a review from a team as a code owner April 19, 2021 17:10
@ecezalp ecezalp requested a review from rylnd April 19, 2021 17:20
@pgayvallet
Copy link
Contributor

Got a review request, but it seems that no changes are impacting core files. Do you want review on something specific, or were the changes triggering the review reverted?

@ecezalp
Copy link
Contributor Author

ecezalp commented Apr 19, 2021

Got a review request, but it seems that no changes are impacting core files. Do you want review on something specific, or were the changes triggering the review reverted?

hey @pgayvallet, I have removed the small change I had made, so there should be nothing here for you.

I do have a question for you though! So my change used to be the addition of a link to docLinks. This failed check_published_api_changes step of the build. In the logs, there were some instructions to fix the error

warn To accept these changes run `node scripts/check_published_api_changes.js --accept` and then:
      	 1. Commit the updated documentation and API review file '/dev/shm/workspace/parallel/12/kibana/src/core/public/public.api.md' 
      	 2. Describe the change in your PR including whether it's a major, minor or patch

so I was wondering - if I were to add a new link in the future, once I run the script mentioned above, what exactly the commit message would be? Would it just be a major / minor / patch according to the release I would be targeting (for instance, minor for 7.13 in this change?) or is there a separate versioning I am not aware of? Would be happy to know.

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! Excellent work.

@@ -19,10 +19,14 @@ export const INDICATOR_MATCHED_TYPE = `${INDICATOR_DESTINATION_PATH}.${MATCHED_T
export const EVENT_DATASET = 'event.dataset';
export const EVENT_REFERENCE = 'event.reference';
export const PROVIDER = 'provider';
export const FIRSTSEEN = 'first_seen';
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
export const FIRSTSEEN = 'first_seen';
export const FIRST_SEEN = 'first_seen';

Not worth waiting for another build, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

_ seemed to indicate nesting level - leaving as is now, I can update in a later commit

`;

const EmptyThreatDetailsViewComponent: React.FC<{}> = () => {
const threatIntelDocsUrl = `${
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

eventId: string
) => {
return data
.reduce((acc, { field, originalValue }) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I think if you reoriented this as SORTED_THREAT_SUMMARY_FIELDS.map().filter() you wouldn't need the 'insert at index' logic below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
securitySolution 2217 2222 +5

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.4MB +38.5KB

History

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

cc @ecezalp

@kibanamachine
Copy link
Contributor

💚 Backport successful

Status Branch Result
7.x

This backport PR will be merged automatically after passing CI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Deprecated - use backport:version if exact versions are needed release_note:skip Skip the PR/issue when compiling release notes Team: CTI v7.13.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants