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

Asset Criticality UI #173011

Closed
wants to merge 12 commits into from
Closed

Asset Criticality UI #173011

wants to merge 12 commits into from

Conversation

tiansivive
Copy link
Contributor

@tiansivive tiansivive commented Dec 10, 2023

Summary

This PR adds the UI to assign asset criticality in the old host flyout. #8086

asset-criticality.demo.mov

Checklist

Delete any items that are not applicable to this PR.

@tiansivive tiansivive added the Team:Entity Analytics Security Entity Analytics Team label Dec 10, 2023
@tiansivive tiansivive self-assigned this Dec 10, 2023
Comment on lines 86 to 87
<EuiSpacer size="m" />
<AssetCriticalitySelector entity={{ type: 'host', name: hostName }} />
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Still not sure if this is the correct placement? @SourinPaul

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After discussing with Pablo, we were wondering if it also needs to show up in the user flyout in the timeline?

Choose a reason for hiding this comment

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

Still not sure if this is the correct placement? @SourinPaul

Can we move the assignment component before displaying host metadata? The accordion can stay collapsed.

After discussing with Pablo, we were wondering if it also needs to show up in the user flyout in the timeline?

In short, yes. The users should be able to assign from every instance of the user flyout, including the timeline. Afaik, this user flyout component is reused everywhere in our app for consistency. I may be incorrect, so worth double checking that.

cc: @tiansivive @machadoum

Copy link
Contributor

@jaredburgettelastic jaredburgettelastic Dec 16, 2023

Choose a reason for hiding this comment

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

Afaik, this user flyout component is reused everywhere in our app for consistency. I may be incorrect, so worth double checking that.

Not a direct answer, but regarding consistency, today the timeline view does not support the new expanded flyouts. This means that, today, even when we have the new users flyout enabled, the timeline view still shows the old flyout.

I'm working to find an answer for when the timeline view will support expanded flyouts, so that this discrepancy will be fixed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jaredburgettelastic The key here is that the timeline does not use flyouts, hence the discrepancy. Perhaps it should?

Copy link
Contributor

@jaredburgettelastic jaredburgettelastic Dec 18, 2023

Choose a reason for hiding this comment

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

The key here is that the timeline does not use flyouts

Apologies for the lack of clarity, to make this more clear:

This means that, today, even when we have the new users flyout enabled, the timeline view still shows the old flyout a panel containing many of the same components used by the old host/user flyout, but embedded directly into the timeline view.

);
};

const useAssetCriticality = (entity: Entity): State => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure if this is the correct place for this hook?
This is under the components folder, maybe we want the hook logic somewhere else?

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe security_solution/public/entity_analytics/hooks/use_asset_criticality.ts?

Copy link
Member

Choose a reason for hiding this comment

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

use_asset_criticality looks like a single usage hook. You could create a folder for the component for asset_criticality inside components and encapsulate everything related to the component inside the folder.

Copy link
Contributor Author

@tiansivive tiansivive Dec 11, 2023

Choose a reason for hiding this comment

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

done.
As discussed I separated the hook into one dealing with data fetching and another for the modal and placed them in a file under the new asset criticality directory

const QC = useQueryClient();

const privileges = useQuery({
queryKey: ['ASSET_CRITICALITY', 'PRIVILEGES', entity.name],
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do we have common place for react-query keys?

Copy link
Contributor Author

@tiansivive tiansivive Dec 11, 2023

Choose a reason for hiding this comment

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

Moved this to a new file in the new asset criticality folder

type: 'host' | 'user';
}

const criticalityDisplayText: Record<AssetCriticalityRecord['criticality_level'], string> = {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should this also be moved to a different file? It seems like this mapping might apply anywhere we deal with asset criticality levels?

Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like a translation map, shouldn't we use i18n for the texts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

export const ASSET_CRITICALITY_INDEX_PATTERN = '.asset-criticality.asset-criticality-*';

type AssetCriticalityIndexPrivilege = 'read' | 'write';
export const ASSET_CRITICALITY_REQUIRED_ES_INDEX_PRIVILEGES = {
[ASSET_CRITICALITY_INDEX_PATTERN]: ['read', 'write'] as AssetCriticalityIndexPrivilege[],
};

export const PICK_ASSET_CRITICALITY = i18n.translate(
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 wonder if this is also the correct place to place this common stuff?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not the best place, as a general rule of thumb:

  • security_solution/common/* -> shared between public and server directories (URLs, indexPatterns, privileges..)
  • security_solution/public/common/* -> shared between public "sub-plugin" directories (reusable components, reusable hooks, paths, constants...)

These translations, however, do not seem to be common stuff, they are only used in the security_solution/public/entity_analytics/components/asset_criticality_selector.tsx component.

So, it would be better to put them in a new translations file inside the same directory, like: security_solution/public/entity_analytics/components/translations.ts.

However, how things are organized inside the security_solution/public/entity_analytics directory is up to your team.

Copy link
Member

Choose a reason for hiding this comment

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

security_solution/public/entity_analytics/components/translations.ts is a good option. The docs recommend inlining the copy into the react component using <FormattedMessage>.

You can read more here: https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/GUIDELINE.md

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I think @hop-dev just had a PR that moved stuff around quite a bit within EA?

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 moved stuff around, most of this stuff now lives along side the component in a new asset criticality folder within EA

@tiansivive tiansivive force-pushed the siem-ea-8086 branch 2 times, most recently from c448f27 to 65e5d20 Compare December 11, 2023 10:53
@tiansivive tiansivive marked this pull request as ready for review December 11, 2023 11:20
@tiansivive tiansivive requested review from a team as code owners December 11, 2023 11:20
@tiansivive tiansivive added release_note:feature Makes this part of the condensed release notes v8.13.0 labels Dec 11, 2023
@machadoum machadoum self-requested a review December 11, 2023 12:21
fill
data-test-subj="asset-criticality-modal-save-btn"
>
{'Save'}
Copy link
Member

Choose a reason for hiding this comment

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

Please use i18n to allow translation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

export const ASSET_CRITICALITY_INDEX_PATTERN = '.asset-criticality.asset-criticality-*';

type AssetCriticalityIndexPrivilege = 'read' | 'write';
export const ASSET_CRITICALITY_REQUIRED_ES_INDEX_PRIVILEGES = {
[ASSET_CRITICALITY_INDEX_PATTERN]: ['read', 'write'] as AssetCriticalityIndexPrivilege[],
};

export const PICK_ASSET_CRITICALITY = i18n.translate(
Copy link
Member

Choose a reason for hiding this comment

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

security_solution/public/entity_analytics/components/translations.ts is a good option. The docs recommend inlining the copy into the react component using <FormattedMessage>.

You can read more here: https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/GUIDELINE.md

<>
<EuiAccordion
id="asset-criticality-selector"
buttonContent="Asset Criticality"
Copy link
Member

Choose a reason for hiding this comment

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

i18n

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


const useAssetCriticality = (entity: Entity): State => {
const [visible, toggleModal] = useToggle(false);
const modal = { visible, toggle: (next: boolean) => () => toggleModal(next) };
Copy link
Member

Choose a reason for hiding this comment

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

This object will update on every hook execution.
I would rather move the toggle state to the component itself so we don't have to create this object.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to a different hook

);
};

const useAssetCriticality = (entity: Entity): State => {
Copy link
Member

Choose a reason for hiding this comment

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

use_asset_criticality looks like a single usage hook. You could create a folder for the component for asset_criticality inside components and encapsulate everything related to the component inside the folder.

import type { CriticalityLevel } from './common';

export const PICK_ASSET_CRITICALITY = i18n.translate(
'xpack.securitySolution.timeline.sidePanel.hostDetails.assetCriticality.pick',
Copy link
Member

Choose a reason for hiding this comment

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

nit: The id xpack.securitySolution.timeline.sidePanel.hostDetails.assetCriticality.pick looks outdated

/**
* Find the first alert row in the alerts table then click on the host name to open the flyout
*/
export const expandFirstAlertHostExpandableFlyout = () => {
Copy link
Member

Choose a reason for hiding this comment

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

I noticed that you created files and functions inside the cypress folder containing HostExpandableFlyout, but there isn't a host expandable flyout yet. We are going to create it soon, but for now, we only have a HostFlyout.

ex: expandable_flyout/host_details_right_panel.ts

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that whole thing is weird.
I was pairing with @jaredburgettelastic and we figured that was the best place to add the test. Do you have a better option?

Copy link
Member

@machadoum machadoum Dec 12, 2023

Choose a reason for hiding this comment

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

A recently merged PR created this folder x-pack/test/security_solution_cypress/cypress/e2e/entity_analytics. I believe that we should put all entity_analytics tests there.

Please don't name it "expandable" if it is testing the old flyout.

@machadoum
Copy link
Member

machadoum commented Dec 12, 2023

I noticed some small UI issues:

  • If we keep the asset criticality as the last item, the content might be hidden after the item is expanded
Dec-12-2023.18-08-36.mov
  • Duplicated CancelCancel text

@tiansivive tiansivive requested a review from machadoum December 18, 2023 11:10
@tiansivive tiansivive marked this pull request as draft December 18, 2023 11:15
@kibana-ci
Copy link
Collaborator

kibana-ci commented Dec 18, 2023

💔 Build Failed

Failed CI Steps

Test Failures

  • [job] [logs] Jest Tests #11 / Details Panel Component DetailsPanel:HostDetails: rendering it should render the Host Details view in the Details Panel when the panelView is hostDetail and the hostName is set
  • [job] [logs] Jest Tests #11 / Expandable Host Component ExpandableHostDetails: rendering it should set date range to anomaly date range
  • [job] [logs] Jest Tests #11 / Expandable Host Component ExpandableUserDetails: rendering it should set date range to anomaly date range
  • [job] [logs] Defend Workflows Cypress Tests #11 / Response console From Alerts "after all" hook for "should open responder from alert details flyout" "after all" hook for "should open responder from alert details flyout"
  • [job] [logs] Defend Workflows Cypress Tests #11 / Response console From Alerts "before all" hook for "should open responder from alert details flyout" "before all" hook for "should open responder from alert details flyout"
  • [job] [logs] Defend Workflows Cypress Tests #9 / Unenroll agent from fleet changing when agent tamper protection is enabled but then is switched to a policy with it disabled "after all" hook for "should unenroll from fleet without issues" "after all" hook for "should unenroll from fleet without issues"
  • [job] [logs] Defend Workflows Cypress Tests #9 / Unenroll agent from fleet changing when agent tamper protection is enabled but then is switched to a policy with it disabled "before each" hook for "should unenroll from fleet without issues" "before each" hook for "should unenroll from fleet without issues"
  • [job] [logs] Defend Workflows Cypress Tests #8 / Unenroll agent from fleet when agent tamper protection is disabled but then is switched to a policy with it enabled "after all" hook for "should unenroll from fleet without issues" "after all" hook for "should unenroll from fleet without issues"
  • [job] [logs] Defend Workflows Cypress Tests #8 / Unenroll agent from fleet when agent tamper protection is disabled but then is switched to a policy with it enabled "before each" hook for "should unenroll from fleet without issues" "before each" hook for "should unenroll from fleet without issues"
  • [job] [logs] Defend Workflows Cypress Tests #10 / Uninstall agent from host changing agent policy when agent tamper protection is disabled but then is switched to a policy with it enabled "after all" hook for "should uninstall from host without issues" "after all" hook for "should uninstall from host without issues"
  • [job] [logs] Defend Workflows Cypress Tests #10 / Uninstall agent from host changing agent policy when agent tamper protection is disabled but then is switched to a policy with it enabled "before each" hook for "should uninstall from host without issues" "before each" hook for "should uninstall from host without issues"

History

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

cc @tiansivive

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release_note:feature Makes this part of the condensed release notes Team:Entity Analytics Security Entity Analytics Team v8.13.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants