-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Automatic Import] Reject CEF logs in Auto Import until it is support…
…ed (#201792) ## Release Note Restrict and Reject CEF logs in Automatic Import and redirect to CEF integration instead. ## Summary Currently Automatic Import does not handle CEF logs properly and gives wierd errors. This PR identifies the CEF logs and sends an error popup to alternatively go for CEF integration instead. <img width="1229" alt="image" src="https://github.com/user-attachments/assets/59037dd4-323a-476a-9747-950fbc6e384d"> ## Testing Tested this with different types of CEF logs ``` <14>Nov 22 16:19:13 ABQ-ZTA-VRNS-3 CEF:0|Varonis Inc.|DatAdvantage|8.6.51|6000|Folder permissions added|3|rt=Nov 22 2024 16:19:09 cat=Alert cs2=Permissions granted to Global Access Groups cs2Label=RuleName cn1=132 cn1Label=RuleID end=Nov 22 2024 16:19:05 duser=zta.local\\Dani Lulli (ADMIN) dhost=10.100.20.12 filePath=E:\\Share\\Share\\Finance fname=Finance act=Folder permissions added dvchost= outcome=Success msg=Read & Execute permissions for This folder, subfolders and files (not inherited) was added to Everyone on E:\\Share\\Share\\Finance cs3= cs3Label=AttachmentName cs4= cs4Label=ClientAccessType deviceCustomDate1= fileType= cs1= cs1Label=MailRecipient suser= cs5= cs5Label=MailboxAccessType cnt= cs6=Read & Execute cs6Label=ChangedPermissions oldFilePermission=None filePermission=Read & Execute dpriv=Everyone start= <14>Nov 22 16:44:31 ABQ-ZTA-VRNS-3 CEF:0|Varonis Inc.|DatAdvantage|8.6.51|1|File opened|2|rt=Nov 22 2024 16:44:31 cat=Alert cs2=Dani Test - access of credentials cs2Label=RuleName cn1=184 cn1Label=RuleID end=Nov 22 2024 16:34:33 duser=zta.local\\Dani Lulli (ADMIN) dhost=10.100.20.12 filePath=E:\\Share\\Share\\B4\\Project mgmt\\U3 projects11.txt:Zone.Identifier fname=U3 projects11.txt:Zone.Identifier act=File opened dvchost= outcome=Success msg= cs3= cs3Label=AttachmentName cs4= cs4Label=ClientAccessType deviceCustomDate1= fileType= cs1= cs1Label=MailRecipient suser= cs5= cs5Label=MailboxAccessType cnt= cs6=None cs6Label=ChangedPermissions oldFilePermission=None filePermission=None dpriv= start= ``` ``` CEF:0|Elastic|Vaporware|1.0.0-alpha|18|Web request|low|eventId=3457 requestMethod=POST slat=38.915 slong=-77.511 proto=TCP sourceServiceName=httpd requestContext=https://www.google.com src=89.160.20.156 spt=33876 dst=192.168.10.1 dpt=443 request=https://www.example.com/cart CEF:0|Elastic|Vaporware|1.0.0-alpha|18|Authentication|low|eventId=123 src=89.160.20.156 spt=33876 dst=89.160.20.156 dpt=443 duser=alice suser=bob destinationTranslatedAddress=10.10.10.10 fileHash=bc8bbe52f041fd17318f08a0f73762ce oldFileHash=a9796280592f86b74b27e370662d41eb CEF:0|Elastic|Vaporware|1.0.0-alpha|18|Authentication|low|spriv=user dpriv=root CEF:0|Elastic|Vaporware|1.0.0-alpha|18|Authentication|low|message=This event is padded with whitespace dst=192.168.1.2 src=192.168.3.4 ``` ``` <163>Apr 1 05:14:15 192.0.2.1 CEF:0|Elastic|Vaporware|1.0.0-alpha|18|Web request|low|msg=rfc3164 Apr 1 05:14:15 192.0.2.1 CEF:0|Elastic|Vaporware|1.0.0-alpha|18|Web request|low|msg=rfc3164 <164>1 2021-04-01T05:14:15.000003-05:00 192.0.2.1 rfc5424App 8710 - - CEF:0|Elastic|Vaporware|1.0.0-alpha|18|Web request|low|msg=rfc5424 2021-04-01T05:14:15.000003-05:00 192.0.2.1 rfc5424App 8710 - - CEF:0|Elastic|Vaporware|1.0.0-alpha|18|Web request|low|msg=rfc5424 <165>1 2021-04-01T05:14:15.000003Z 192.0.2.1 rfc5424App 8710 - - CEF:0|Elastic|Vaporware|1.0.0-alpha|18|Web request|low|msg=rfc5424 2021-04-01T05:14:15.000003Z 192.0.2.1 rfc5424App 8710 - - CEF:0|Elastic|Vaporware|1.0.0-alpha|18|Web request|low|msg=rfc5424 ``` ### Checklist Check the PR satisfies following conditions. Reviewers should verify this PR satisfies this list as well. - [x] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md) - [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [x] The PR description includes the appropriate Release Notes section, and the correct `release_note:*` label is applied per the [guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) --------- Co-authored-by: Elastic Machine <[email protected]>
- Loading branch information
1 parent
76c2f31
commit f6fa94f
Showing
13 changed files
with
258 additions
and
6 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
x-pack/plugins/integration_assistant/common/api/generation_error.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,63 @@ | ||
/* | ||
* 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 { GenerationErrorCode } from '../constants'; | ||
import { isGenerationErrorBody } from './generation_error'; | ||
import type { GenerationErrorBody } from './generation_error'; | ||
|
||
describe('isGenerationErrorBody', () => { | ||
it('should return true for a valid GenerationErrorBody object', () => { | ||
const validErrorBody: GenerationErrorBody = { | ||
message: 'An error occurred', | ||
attributes: { | ||
errorCode: GenerationErrorCode.CEF_ERROR, | ||
underlyingMessages: ['Error message 1', 'Error message 2'], | ||
}, | ||
}; | ||
|
||
expect(isGenerationErrorBody(validErrorBody)).toBe(true); | ||
}); | ||
|
||
it('should return false for an object without a message', () => { | ||
const invalidErrorBody = { | ||
attributes: { | ||
errorCode: 'ERROR_CODE', | ||
underlyingMessages: ['Error message 1', 'Error message 2'], | ||
}, | ||
}; | ||
|
||
expect(isGenerationErrorBody(invalidErrorBody)).toBe(false); | ||
}); | ||
|
||
it('should return false for an object without attributes', () => { | ||
const invalidErrorBody = { | ||
message: 'An error occurred', | ||
}; | ||
|
||
expect(isGenerationErrorBody(invalidErrorBody)).toBe(false); | ||
}); | ||
|
||
it('should return false for an object with invalid attributes', () => { | ||
const invalidErrorBody = { | ||
message: 'An error occurred', | ||
attributes: { | ||
errorCode: 123, // errorCode should be a string | ||
underlyingMessages: 'Error message', // underlyingMessages should be an array | ||
}, | ||
}; | ||
|
||
expect(isGenerationErrorBody(invalidErrorBody)).toBe(false); | ||
}); | ||
|
||
it('should return false for a non-object value', () => { | ||
expect(isGenerationErrorBody(null)).toBe(false); | ||
expect(isGenerationErrorBody(undefined)).toBe(false); | ||
expect(isGenerationErrorBody('string')).toBe(false); | ||
expect(isGenerationErrorBody(123)).toBe(false); | ||
expect(isGenerationErrorBody(true)).toBe(false); | ||
}); | ||
}); |
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 |
---|---|---|
|
@@ -64,6 +64,7 @@ components: | |
- structured | ||
- unstructured | ||
- unsupported | ||
- cef | ||
|
||
SamplesFormat: | ||
type: object | ||
|
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
43 changes: 43 additions & 0 deletions
43
..._integration/create_integration_assistant/steps/data_stream_step/error_with_link.test.tsx
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,43 @@ | ||
/* | ||
* 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 { render } from '@testing-library/react'; | ||
import { ErrorMessage, isErrorMessageWithLink, MessageLink } from './error_with_link'; | ||
|
||
describe('isErrorMessageWithLink', () => { | ||
it('should return true when error is an ErrorMessageWithLink', () => { | ||
const error = { | ||
link: 'http://example.com', | ||
errorMessage: 'An error occurred', | ||
linkText: 'decode_cef', | ||
}; | ||
expect(isErrorMessageWithLink(error)).toBe(true); | ||
}); | ||
|
||
it('should return false when error is a string', () => { | ||
const error = 'An error occurred'; | ||
expect(isErrorMessageWithLink(error)).toBe(false); | ||
}); | ||
|
||
describe('MessageLink', () => { | ||
it('should render link with correct href and text', () => { | ||
const { getByText } = render(<MessageLink link="http://example.com" linkText="decode_cef" />); | ||
const linkElement = getByText('decode_cef'); | ||
expect(linkElement).toBeInTheDocument(); | ||
expect(linkElement).toHaveAttribute('href', 'http://example.com'); | ||
}); | ||
}); | ||
|
||
describe('ErrorMessage', () => { | ||
it('should render error message when error is a string', () => { | ||
const error = 'An error occurred'; | ||
const { getByText } = render(<ErrorMessage error={error} />); | ||
expect(getByText('An error occurred')).toBeInTheDocument(); | ||
}); | ||
}); | ||
}); |
59 changes: 59 additions & 0 deletions
59
...reate_integration/create_integration_assistant/steps/data_stream_step/error_with_link.tsx
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,59 @@ | ||
/* | ||
* 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 { FormattedMessage } from '@kbn/i18n-react'; | ||
import { EuiLink } from '@elastic/eui'; | ||
import type { ErrorMessageWithLink } from '../../../../../../common/api/generation_error'; | ||
|
||
interface ErrorMessageProps { | ||
error: string | null | ErrorMessageWithLink; | ||
} | ||
|
||
interface MessageLinkProps { | ||
link: string; | ||
linkText: string; | ||
} | ||
|
||
export const isErrorMessageWithLink = ( | ||
error: string | ErrorMessageWithLink | null | ||
): error is ErrorMessageWithLink => { | ||
return ( | ||
(error as ErrorMessageWithLink).link !== undefined && | ||
(error as ErrorMessageWithLink).linkText !== undefined && | ||
(error as ErrorMessageWithLink).errorMessage !== undefined | ||
); | ||
}; | ||
|
||
export const MessageLink = React.memo<MessageLinkProps>(({ link, linkText }) => { | ||
return ( | ||
<EuiLink href={link} target="_blank"> | ||
{linkText} | ||
</EuiLink> | ||
); | ||
}); | ||
MessageLink.displayName = 'MessageLink'; | ||
|
||
export const ErrorMessage = React.memo<ErrorMessageProps>(({ error }) => { | ||
return ( | ||
<> | ||
{isErrorMessageWithLink(error) ? ( | ||
<FormattedMessage | ||
id="xpack.integrationAssistant.createIntegration.generateErrorWithLink" | ||
defaultMessage="{errorMessage} {link}" | ||
values={{ | ||
errorMessage: error.errorMessage, | ||
link: <MessageLink link={error.link} linkText={error.linkText} />, | ||
}} | ||
/> | ||
) : typeof error === 'string' ? ( | ||
<>{error}</> | ||
) : null} | ||
</> | ||
); | ||
}); | ||
ErrorMessage.displayName = 'ErrorMessage'; |
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
42 changes: 42 additions & 0 deletions
42
x-pack/plugins/integration_assistant/server/lib/errors/cef_error.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,42 @@ | ||
/* | ||
* 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 { KibanaResponseFactory } from '@kbn/core/server'; | ||
import { | ||
GenerationErrorAttributes, | ||
GenerationErrorBody, | ||
} from '../../../common/api/generation_error'; | ||
import { ErrorThatHandlesItsOwnResponse } from './types'; | ||
import { GenerationErrorCode } from '../../../common/constants'; | ||
|
||
export class CefError extends Error implements ErrorThatHandlesItsOwnResponse { | ||
private readonly errorCode: GenerationErrorCode = GenerationErrorCode.CEF_ERROR; | ||
attributes: GenerationErrorAttributes; | ||
|
||
constructor(message: string) { | ||
super(message); | ||
this.attributes = { | ||
errorCode: this.errorCode, | ||
errorMessageWithLink: { | ||
linkText: 'cef-integration', | ||
link: 'https://www.elastic.co/docs/current/integrations/cef', | ||
errorMessage: '', // Will be set using translation in the UI. | ||
}, | ||
}; | ||
} | ||
|
||
public sendResponse(res: KibanaResponseFactory) { | ||
const body: GenerationErrorBody = { | ||
message: this.errorCode, | ||
attributes: this.attributes, | ||
}; | ||
return res.customError({ | ||
statusCode: 501, | ||
body, | ||
}); | ||
} | ||
} |
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