forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[8.x] [Cloud Security]Vulnerabilities table in Contextual flyout (ela…
…stic#195143) (elastic#195597) # Backport This will backport the following commits from `main` to `8.x`: - [[Cloud Security]Vulnerabilities table in Contextual flyout (elastic#195143)](elastic#195143) <!--- Backport version: 9.4.3 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sqren/backport) <!--BACKPORT [{"author":{"name":"Rickyanto Ang","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-09T13:25:28Z","message":"[Cloud Security]Vulnerabilities table in Contextual flyout (elastic#195143)\n\n## Summary\r\n\r\nThis PR is for Vulnerabilities data table in contextual flyout\r\nIt also addresses the ticket to remove Empty State for Preview Component\r\n[ticket](https://github.com/elastic/security-team/issues/10746)\r\n<img width=\"1510\" alt=\"Screenshot 2024-10-07 at 2 14 52 AM\"\r\nsrc=\"https://github.com/user-attachments/assets/3c4cdc86-68c6-439c-96a1-92cece88e42e\">\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine <[email protected]>\r\nCo-authored-by: Maxim Kholod <[email protected]>","sha":"59f2f85b8a18cc23c7f0c168830fbc304a9346b6","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:Cloud Security","backport:prev-minor","ci:build-cloud-image","ci:project-deploy-security","v8.16.0"],"title":"[Cloud Security]Vulnerabilities table in Contextual flyout","number":195143,"url":"https://github.com/elastic/kibana/pull/195143","mergeCommit":{"message":"[Cloud Security]Vulnerabilities table in Contextual flyout (elastic#195143)\n\n## Summary\r\n\r\nThis PR is for Vulnerabilities data table in contextual flyout\r\nIt also addresses the ticket to remove Empty State for Preview Component\r\n[ticket](https://github.com/elastic/security-team/issues/10746)\r\n<img width=\"1510\" alt=\"Screenshot 2024-10-07 at 2 14 52 AM\"\r\nsrc=\"https://github.com/user-attachments/assets/3c4cdc86-68c6-439c-96a1-92cece88e42e\">\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine <[email protected]>\r\nCo-authored-by: Maxim Kholod <[email protected]>","sha":"59f2f85b8a18cc23c7f0c168830fbc304a9346b6"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/195143","number":195143,"mergeCommit":{"message":"[Cloud Security]Vulnerabilities table in Contextual flyout (elastic#195143)\n\n## Summary\r\n\r\nThis PR is for Vulnerabilities data table in contextual flyout\r\nIt also addresses the ticket to remove Empty State for Preview Component\r\n[ticket](https://github.com/elastic/security-team/issues/10746)\r\n<img width=\"1510\" alt=\"Screenshot 2024-10-07 at 2 14 52 AM\"\r\nsrc=\"https://github.com/user-attachments/assets/3c4cdc86-68c6-439c-96a1-92cece88e42e\">\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine <[email protected]>\r\nCo-authored-by: Maxim Kholod <[email protected]>","sha":"59f2f85b8a18cc23c7f0c168830fbc304a9346b6"}},{"branch":"8.x","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}] BACKPORT--> Co-authored-by: Rickyanto Ang <[email protected]>
- Loading branch information
1 parent
5798892
commit 0751a8e
Showing
36 changed files
with
1,007 additions
and
330 deletions.
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
68 changes: 68 additions & 0 deletions
68
x-pack/packages/kbn-cloud-security-posture/src/hooks/use_vulnerabilities_findings.ts
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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { useKibana } from '@kbn/kibana-react-plugin/public'; | ||
import { lastValueFrom } from 'rxjs'; | ||
import type { IKibanaSearchResponse, IKibanaSearchRequest } from '@kbn/search-types'; | ||
import { | ||
SearchRequest, | ||
SearchResponse, | ||
AggregationsMultiBucketAggregateBase, | ||
AggregationsStringRareTermsBucketKeys, | ||
} from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; | ||
import type { CspVulnerabilityFinding } from '@kbn/cloud-security-posture-common/schema/vulnerabilities/latest'; | ||
import type { CoreStart } from '@kbn/core/public'; | ||
import type { CspClientPluginStartDeps, UseCspOptions } from '../../type'; | ||
import { showErrorToast } from '../..'; | ||
import { getVulnerabilitiesAggregationCount, getVulnerabilitiesQuery } from '../utils/hooks_utils'; | ||
|
||
type LatestFindingsRequest = IKibanaSearchRequest<SearchRequest>; | ||
type LatestFindingsResponse = IKibanaSearchResponse< | ||
SearchResponse<CspVulnerabilityFinding, FindingsAggs> | ||
>; | ||
|
||
interface FindingsAggs { | ||
count: AggregationsMultiBucketAggregateBase<AggregationsStringRareTermsBucketKeys>; | ||
} | ||
|
||
export const useVulnerabilitiesFindings = (options: UseCspOptions) => { | ||
const { | ||
data, | ||
notifications: { toasts }, | ||
} = useKibana<CoreStart & CspClientPluginStartDeps>().services; | ||
/** | ||
* We're using useInfiniteQuery in this case to allow the user to fetch more data (if available and up to 10k) | ||
* useInfiniteQuery differs from useQuery because it accumulates and caches a chunk of data from the previous fetches into an array | ||
* it uses the getNextPageParam to know if there are more pages to load and retrieve the position of | ||
* the last loaded record to be used as a from parameter to fetch the next chunk of data. | ||
*/ | ||
return useQuery( | ||
['csp_vulnerabilities_findings', { params: options }], | ||
async ({ pageParam }) => { | ||
const { | ||
rawResponse: { aggregations, hits }, | ||
} = await lastValueFrom( | ||
data.search.search<LatestFindingsRequest, LatestFindingsResponse>({ | ||
params: getVulnerabilitiesQuery(options, pageParam), | ||
}) | ||
); | ||
|
||
return { | ||
count: getVulnerabilitiesAggregationCount(aggregations?.count?.buckets), | ||
rows: hits.hits.map((finding) => ({ | ||
vulnerability: finding._source?.vulnerability, | ||
resource: finding._source?.resource, | ||
})) as Array<Pick<CspVulnerabilityFinding, 'vulnerability' | 'resource'>>, | ||
}; | ||
}, | ||
{ | ||
keepPreviousData: true, | ||
enabled: options.enabled, | ||
onError: (err: Error) => showErrorToast(toasts, err), | ||
} | ||
); | ||
}; |
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
74 changes: 74 additions & 0 deletions
74
x-pack/packages/kbn-cloud-security-posture/src/utils/vulnerability_helpers.test.ts
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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { euiThemeVars } from '@kbn/ui-theme'; | ||
import { getVulnerabilityStats } from './vulnerability_helpers'; | ||
import { i18n } from '@kbn/i18n'; | ||
|
||
describe('getVulnerabilitiesAggregationCount', () => { | ||
it('should return empty array when all severity count is 0', () => { | ||
const result = getVulnerabilityStats({ critical: 0, high: 0, medium: 0, low: 0, none: 0 }); | ||
expect(result).toEqual([]); | ||
}); | ||
|
||
it('should return stats for low, medium, high, and critical vulnerabilities', () => { | ||
const result = getVulnerabilityStats({ critical: 1, high: 2, medium: 3, low: 4, none: 5 }); | ||
|
||
expect(result).toEqual([ | ||
{ | ||
key: i18n.translate( | ||
'xpack.securitySolution.flyout.right.insights.vulnerabilities.noneVulnerabilitiesText', | ||
{ | ||
defaultMessage: 'None', | ||
} | ||
), | ||
count: 5, | ||
color: '#aaa', | ||
}, | ||
{ | ||
key: i18n.translate( | ||
'xpack.securitySolution.flyout.right.insights.vulnerabilities.lowVulnerabilitiesText', | ||
{ | ||
defaultMessage: 'Low', | ||
} | ||
), | ||
count: 4, | ||
color: euiThemeVars.euiColorVis0, | ||
}, | ||
{ | ||
key: i18n.translate( | ||
'xpack.securitySolution.flyout.right.insights.vulnerabilities.mediumVulnerabilitiesText', | ||
{ | ||
defaultMessage: 'Medium', | ||
} | ||
), | ||
count: 3, | ||
color: euiThemeVars.euiColorVis5_behindText, | ||
}, | ||
{ | ||
key: i18n.translate( | ||
'xpack.securitySolution.flyout.right.insights.vulnerabilities.highVulnerabilitiesText', | ||
{ | ||
defaultMessage: 'High', | ||
} | ||
), | ||
count: 2, | ||
color: euiThemeVars.euiColorVis9_behindText, | ||
}, | ||
{ | ||
key: i18n.translate( | ||
'xpack.securitySolution.flyout.right.insights.vulnerabilities.CriticalVulnerabilitiesText', | ||
{ | ||
defaultMessage: 'Critical', | ||
} | ||
), | ||
count: 1, | ||
color: euiThemeVars.euiColorDanger, | ||
}, | ||
]); | ||
}); | ||
}); |
Oops, something went wrong.