-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Cloud Security] User Name Misconfiguration Table and Preview Contextual Flyout #192946
Merged
animehart
merged 8 commits into
elastic:main
from
animehart:misconfiguration-datagrid-username
Sep 18, 2024
+175
−87
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
cf9b84a
initial commit for Misconfiguration Contextual flyout for user name
animehart 4bd8a14
clean up + unit test
animehart b288e4f
Merge branch 'main' into misconfiguration-datagrid-username
animehart 92a2290
Merge branch 'main' into misconfiguration-datagrid-username
animehart 90263a5
fix attempt serverless mode, bug fix on preview mode
animehart 505229c
Merge branch 'misconfiguration-datagrid-username' of github.com:anime…
animehart 1dc2886
swap the order of accordion
animehart 3b38da4
removed misconfiguration tabs inside left flyout to prevent confusion…
animehart File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,10 +17,12 @@ import { i18n } from '@kbn/i18n'; | |
import { ExpandablePanel } from '@kbn/security-solution-common'; | ||
import { buildEntityFlyoutPreviewQuery } from '@kbn/cloud-security-posture-common'; | ||
import { useExpandableFlyoutApi } from '@kbn/expandable-flyout'; | ||
import { UserDetailsPanelKey } from '../../../flyout/entity_details/user_details_left'; | ||
import { HostDetailsPanelKey } from '../../../flyout/entity_details/host_details_left'; | ||
import { useRiskScore } from '../../../entity_analytics/api/hooks/use_risk_score'; | ||
import { RiskScoreEntity } from '../../../../common/entity_analytics/risk_engine'; | ||
import { buildHostNamesFilter } from '../../../../common/search_strategy'; | ||
import type { HostRiskScore, UserRiskScore } from '../../../../common/search_strategy'; | ||
import { buildHostNamesFilter, buildUserNamesFilter } from '../../../../common/search_strategy'; | ||
|
||
const FIRST_RECORD_PAGINATION = { | ||
cursorStart: 0, | ||
|
@@ -120,9 +122,17 @@ const MisconfigurationPreviewScore = ({ | |
); | ||
}; | ||
|
||
export const MisconfigurationsPreview = ({ hostName }: { hostName: string }) => { | ||
export const MisconfigurationsPreview = ({ | ||
name, | ||
fieldName, | ||
isPreviewMode, | ||
}: { | ||
name: string; | ||
fieldName: 'host.name' | 'user.name'; | ||
isPreviewMode?: boolean; | ||
}) => { | ||
const { data } = useMisconfigurationPreview({ | ||
query: buildEntityFlyoutPreviewQuery('host.name', hostName), | ||
query: buildEntityFlyoutPreviewQuery(fieldName, name), | ||
sort: [], | ||
enabled: true, | ||
pageSize: 1, | ||
|
@@ -133,33 +143,44 @@ export const MisconfigurationsPreview = ({ hostName }: { hostName: string }) => | |
|
||
const { euiTheme } = useEuiTheme(); | ||
const hasMisconfigurationFindings = passedFindings > 0 || failedFindings > 0; | ||
const hostNameFilterQuery = useMemo( | ||
() => (hostName ? buildHostNamesFilter([hostName]) : undefined), | ||
[hostName] | ||
|
||
const buildFilterQuery = useMemo( | ||
() => (fieldName === 'host.name' ? buildHostNamesFilter([name]) : buildUserNamesFilter([name])), | ||
[fieldName, name] | ||
); | ||
|
||
const riskScoreState = useRiskScore({ | ||
riskEntity: RiskScoreEntity.host, | ||
filterQuery: hostNameFilterQuery, | ||
riskEntity: fieldName === 'host.name' ? RiskScoreEntity.host : RiskScoreEntity.user, | ||
filterQuery: buildFilterQuery, | ||
onlyLatest: false, | ||
pagination: FIRST_RECORD_PAGINATION, | ||
}); | ||
const { data: hostRisk } = riskScoreState; | ||
const hostRiskData = hostRisk && hostRisk.length > 0 ? hostRisk[0] : undefined; | ||
const isRiskScoreExist = !!hostRiskData?.host.risk; | ||
const riskData = hostRisk && hostRisk.length > 0 ? hostRisk[0] : undefined; | ||
const isRiskScoreExist = | ||
fieldName === 'host.name' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit, but consider consolidating this check to a const (e.g. |
||
? !!(riskData as HostRiskScore)?.host.risk | ||
: !!(riskData as UserRiskScore)?.user.risk; | ||
const { openLeftPanel } = useExpandableFlyoutApi(); | ||
const isPreviewMode = false; | ||
const goToEntityInsightTab = useCallback(() => { | ||
openLeftPanel({ | ||
id: HostDetailsPanelKey, | ||
params: { | ||
name: hostName, | ||
isRiskScoreExist, | ||
hasMisconfigurationFindings, | ||
path: { tab: 'csp_insights' }, | ||
}, | ||
id: fieldName === 'host.name' ? HostDetailsPanelKey : UserDetailsPanelKey, | ||
params: | ||
fieldName === 'host.name' | ||
? { | ||
name, | ||
isRiskScoreExist, | ||
hasMisconfigurationFindings, | ||
path: { tab: 'csp_insights' }, | ||
} | ||
: { | ||
user: { name }, | ||
isRiskScoreExist, | ||
hasMisconfigurationFindings, | ||
path: { tab: 'csp_insights' }, | ||
}, | ||
}); | ||
}, [hasMisconfigurationFindings, hostName, isRiskScoreExist, openLeftPanel]); | ||
}, [fieldName, hasMisconfigurationFindings, isRiskScoreExist, name, openLeftPanel]); | ||
const link = useMemo( | ||
() => | ||
!isPreviewMode | ||
|
@@ -178,7 +199,7 @@ export const MisconfigurationsPreview = ({ hostName }: { hostName: string }) => | |
return ( | ||
<ExpandablePanel | ||
header={{ | ||
iconType: hasMisconfigurationFindings ? 'arrowStart' : '', | ||
iconType: !isPreviewMode && hasMisconfigurationFindings ? 'arrowStart' : '', | ||
title: ( | ||
<EuiText | ||
size="xs" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should do the same thing