-
Notifications
You must be signed in to change notification settings - Fork 8.6k
Siem Readiness initial plugin and navigation, package, server api #233714
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
Merged
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
8efa174
init plugin and navigation creation for siem readiness
JordanSh 4d000ba
lint
JordanSh e7e5279
types
JordanSh bb593ae
Merge branch 'main' of https://github.com/elastic/kibana into siem-re…
JordanSh 896484f
Merge branch 'main' of https://github.com/elastic/kibana into siem-re…
JordanSh 1b3a6b3
wont show on serverless
JordanSh a6943a6
fix register of plugin
JordanSh ccb37bd
add exp key to link
JordanSh 2e5a04f
codeowners
JordanSh 07aa77d
adding package
JordanSh d1669cc
adding package
JordanSh 8ecfd87
adding package
JordanSh 035f439
adding server
JordanSh 716f0b7
indexing works
JordanSh daa8059
indexing works
JordanSh 36998c8
indexing works
JordanSh af47d70
indexing works
JordanSh 2f2258c
path
JordanSh ffdb088
cleaning
JordanSh d13605c
cleaning
JordanSh 06190a8
cleaning
JordanSh 06957f8
rename file
JordanSh 68f2c6e
[CI] Auto-commit changed files from 'node scripts/notice'
kibanamachine d414c87
cleaning
JordanSh 01c09d7
Merge branch 'siem-readiness-kbn-package' of https://github.com/Jorda…
JordanSh 81eb55d
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine cd8c983
[CI] Auto-commit changed files from 'node scripts/eslint_all_files --…
kibanamachine bdec17f
cleaning
JordanSh 063433a
Merge branch 'main' of https://github.com/elastic/kibana into siem-re…
JordanSh fa6bd6e
Merge branch 'main' of https://github.com/elastic/kibana into siem-re…
JordanSh 8681387
remove unneeded code
JordanSh 016adba
Merge branch 'main' of https://github.com/elastic/kibana into siem-re…
JordanSh 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
24 changes: 24 additions & 0 deletions
24
x-pack/solutions/security/packages/siem-readiness/README.md
This file contains hidden or 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,24 @@ | ||
| # @kbn/siem-readiness | ||
|
|
||
| ## Overview | ||
|
|
||
| The SIEM readiness package helps log readiness events within Kibana. | ||
|
|
||
| ## Usage | ||
|
|
||
| ```typescript | ||
| import { useLogReadinessTask } from '@kbn/siem-readiness'; | ||
|
|
||
| // Example usage | ||
| const { logReadinessTask } = useLogReadinessTask(); | ||
|
|
||
| const handleLogTask = useCallback(async () => { | ||
| logReadinessTask({ task_id: '1', status: 'complete', meta: { demo: 'demo_data' } }); | ||
| }, [logReadinessTask]); | ||
| ``` | ||
|
|
||
| ## API | ||
|
|
||
| The package is using the post_readiness_task API which can be found at: | ||
|
|
||
| `kibana/x-pack/solutions/security/plugins/security_solution/server/lib/siem_readiness/routes/post_readiness_task.ts` |
10 changes: 10 additions & 0 deletions
10
x-pack/solutions/security/packages/siem-readiness/index.ts
This file contains hidden or 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,10 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
|
|
||
| export type * from './src/types'; | ||
| export * from './src/constants'; | ||
| export * from './src/use_log_readiness_task'; |
12 changes: 12 additions & 0 deletions
12
x-pack/solutions/security/packages/siem-readiness/jest.config.js
This file contains hidden or 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,12 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
|
|
||
| module.exports = { | ||
| preset: '@kbn/test', | ||
| rootDir: '../../../../..', | ||
| roots: ['<rootDir>/x-pack/solutions/security/packages/siem-readiness'], | ||
| }; |
9 changes: 9 additions & 0 deletions
9
x-pack/solutions/security/packages/siem-readiness/kibana.jsonc
This file contains hidden or 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,9 @@ | ||
| { | ||
| "type": "shared-browser", | ||
| "id": "@kbn/siem-readiness", | ||
| "owner": [ | ||
| "@elastic/kibana-cloud-security-posture" | ||
| ], | ||
| "group": "security", | ||
| "visibility": "private" | ||
| } |
8 changes: 8 additions & 0 deletions
8
x-pack/solutions/security/packages/siem-readiness/package.json
This file contains hidden or 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,8 @@ | ||
| { | ||
| "name": "@kbn/siem-readiness", | ||
| "private": true, | ||
| "version": "1.0.0", | ||
| "license": "Elastic License 2.0", | ||
| "description": "handles SIEM Readiness tasks management for Kibana Security Solution", | ||
| "sideEffects": false | ||
| } |
9 changes: 9 additions & 0 deletions
9
x-pack/solutions/security/packages/siem-readiness/src/constants.ts
This file contains hidden or 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,9 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
|
|
||
| export const SIEM_READINESS_PACKAGE_NAME = '@kbn/siem-readiness'; | ||
| export const POST_SIEM_READINESS_TASK_API_PATH = '/api/siem_readiness/post_task'; |
12 changes: 12 additions & 0 deletions
12
x-pack/solutions/security/packages/siem-readiness/src/types.ts
This file contains hidden or 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,12 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
|
|
||
| export interface SiemReadinessTask { | ||
| task_id: string; | ||
| status: 'complete' | 'incomplete'; | ||
| meta: Record<string, unknown>; | ||
| } |
97 changes: 97 additions & 0 deletions
97
x-pack/solutions/security/packages/siem-readiness/src/use_log_readiness_task.test.tsx
This file contains hidden or 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,97 @@ | ||
| /* | ||
| * 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 React from 'react'; | ||
| import { renderHook, act } from '@testing-library/react'; | ||
| import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; | ||
| import { useLogReadinessTask } from './use_log_readiness_task'; | ||
| import { useKibana } from '@kbn/kibana-react-plugin/public'; | ||
| import { POST_SIEM_READINESS_TASK_API_PATH } from './constants'; | ||
| import type { SiemReadinessTask } from './types'; | ||
|
|
||
| jest.mock('@kbn/kibana-react-plugin/public', () => ({ | ||
| useKibana: jest.fn(), | ||
| })); | ||
|
|
||
| describe('useLogReadinessTask', () => { | ||
| const mockPost = jest.fn(); | ||
| const queryClient = new QueryClient(); | ||
|
|
||
| const wrapper = ({ children }: { children: React.ReactNode }) => ( | ||
| <QueryClientProvider client={queryClient}>{children}</QueryClientProvider> | ||
| ); | ||
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| (useKibana as jest.Mock).mockReturnValue({ | ||
| services: { | ||
| http: { | ||
| post: mockPost, | ||
| }, | ||
| }, | ||
| }); | ||
| }); | ||
|
|
||
| it('should call http.post with the correct arguments when logging a task', async () => { | ||
| const { result } = renderHook(() => useLogReadinessTask(), { wrapper }); | ||
|
|
||
| const task: SiemReadinessTask = { | ||
| task_id: 'test-task-1', | ||
| status: 'complete', | ||
| meta: { description: 'Test task', duration: 1000 }, | ||
| }; | ||
|
|
||
| await act(async () => { | ||
| result.current.logReadinessTask(task); | ||
| }); | ||
|
|
||
| expect(mockPost).toHaveBeenCalledWith(POST_SIEM_READINESS_TASK_API_PATH, { | ||
| body: JSON.stringify(task), | ||
| }); | ||
| }); | ||
|
|
||
| it('should handle an error response from http.post', async () => { | ||
| mockPost.mockRejectedValue(new Error('HTTP error')); | ||
| const { result } = renderHook(() => useLogReadinessTask({ onError: jest.fn() }), { wrapper }); | ||
|
|
||
| const task: SiemReadinessTask = { | ||
| task_id: 'test-task-2', | ||
| status: 'incomplete', | ||
| meta: { error: 'Something went wrong' }, | ||
| }; | ||
|
|
||
| await act(async () => { | ||
| try { | ||
| result.current.logReadinessTask(task); | ||
| } catch { | ||
| // expected to throw | ||
| } | ||
| }); | ||
|
|
||
| expect(mockPost).toHaveBeenCalledWith(POST_SIEM_READINESS_TASK_API_PATH, { | ||
| body: JSON.stringify(task), | ||
| }); | ||
| }); | ||
|
|
||
| it('should call onSuccess callback when mutation succeeds', async () => { | ||
| const onSuccess = jest.fn(); | ||
| mockPost.mockResolvedValue({}); | ||
| const { result } = renderHook(() => useLogReadinessTask({ onSuccess }), { wrapper }); | ||
|
|
||
| const task: SiemReadinessTask = { | ||
| task_id: 'test-task-3', | ||
| status: 'complete', | ||
| meta: {}, | ||
| }; | ||
|
|
||
| await act(async () => { | ||
| result.current.logReadinessTask(task); | ||
| }); | ||
|
|
||
| expect(onSuccess).toHaveBeenCalled(); | ||
| }); | ||
| }); |
35 changes: 35 additions & 0 deletions
35
x-pack/solutions/security/packages/siem-readiness/src/use_log_readiness_task.ts
This file contains hidden or 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,35 @@ | ||
| /* | ||
| * 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 { useMutation, type UseMutationOptions } from '@tanstack/react-query'; | ||
| import { useKibana } from '@kbn/kibana-react-plugin/public'; | ||
| import type { CoreStart } from '@kbn/core/public'; | ||
| import { POST_SIEM_READINESS_TASK_API_PATH } from './constants'; | ||
| import type { SiemReadinessTask } from './types'; | ||
|
|
||
| /** | ||
| * Hook for logging SIEM readiness tasks via API endpoint | ||
| * @param options - TanStack mutation options | ||
| * @returns Mutation hook for logging readiness tasks | ||
| */ | ||
| export const useLogReadinessTask = ( | ||
| options?: UseMutationOptions<void, unknown, SiemReadinessTask> | ||
| ) => { | ||
| const { http } = useKibana<CoreStart>().services; | ||
|
|
||
| const { mutate: logReadinessTask } = useMutation<void, unknown, SiemReadinessTask>( | ||
| (task: SiemReadinessTask) => | ||
| http.post<void>(POST_SIEM_READINESS_TASK_API_PATH, { | ||
| body: JSON.stringify(task), | ||
| }), | ||
| options | ||
| ); | ||
|
|
||
| return { | ||
| logReadinessTask, | ||
| }; | ||
| }; |
21 changes: 21 additions & 0 deletions
21
x-pack/solutions/security/packages/siem-readiness/tsconfig.json
This file contains hidden or 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,21 @@ | ||
| { | ||
| "extends": "../../../../../tsconfig.base.json", | ||
| "compilerOptions": { | ||
| "outDir": "target/types", | ||
| "types": [ | ||
| "jest", | ||
| "node", | ||
| ] | ||
| }, | ||
| "include": [ | ||
| "**/*.ts", | ||
| "**/*.tsx", | ||
| ], | ||
| "exclude": [ | ||
| "target/**/*" | ||
| ], | ||
| "kbn_references": [ | ||
| "@kbn/kibana-react-plugin", | ||
| "@kbn/core", | ||
| ] | ||
| } |
8 changes: 8 additions & 0 deletions
8
x-pack/solutions/security/plugins/security_solution/common/api/siem_readiness/constants.ts
This file contains hidden or 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,8 @@ | ||
| /* | ||
| * 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. | ||
| */ | ||
|
|
||
| export const POST_SIEM_READINESS_TASK_API_PATH = '/api/siem_readiness/post_task'; |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
should this be imported from the management package?
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.
let me know if i should move this, i've followed the pattern of other advanced settings from security solution as can be seen in this file
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.
I'm just curious why its defined in two different places. Its not a huge deal but I am trying to understand before delivering my approval.
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.
thank you for noticing its being defined twice. indeed the other const in the management package ended up not being used at the end. i will remove it and only leave this one. thank you for catching this