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

[CrowdStrike] Add Support of Crowdstrike Event Stream #11773

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

mohitjha-elastic
Copy link
Contributor

@mohitjha-elastic mohitjha-elastic commented Nov 19, 2024

Type of change

  • Enhancement

Proposed Commit Message

Add support of new input type to collect logs for the falcon dataset- CrowdStrike Event Stream via streaming input.
Update the minimum kibana version to 8.16.0
Add the entry of the crowdstrike event stream in readme

Checklist

  • I have reviewed tips for building integrations and this pull request is aligned with them.
  • I have verified that all data streams collect metrics or logs.
  • I have added an entry to my package's changelog.yml file.
  • I have verified that Kibana version constraints are current according to guidelines.

Screenshots

image
image

@mohitjha-elastic mohitjha-elastic requested a review from a team as a code owner November 19, 2024 12:27
@andrewkroh andrewkroh added Crest enhancement New feature or request Integration:crowdstrike CrowdStrike Team:Security-Service Integrations Security Service Integrations Team [elastic/security-service-integrations] labels Nov 19, 2024
@elasticmachine
Copy link

Pinging @elastic/security-service-integrations (Team:Security-Service Integrations)

Copy link
Contributor

@efd6 efd6 left a comment

Choose a reason for hiding this comment

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

There are not tests here. Can you remove the comment in the PR that says how to test locally since that obviously has no effect on this addition.

Have you tested? What do you need in order to add CI testing?

processors:
{{#if processors}}
{{processors}}
{{/if}}
Copy link
Contributor

Choose a reason for hiding this comment

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

Final new line.

redact:
fields: ~
program: |
bytes(state.response).decode_json().as(body,{
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
bytes(state.response).decode_json().as(body,{
state.response.decode_json().as(body,{

We should not need the conversion since we are now on 8.16 which has mito v1.15.0 and the newer type checker.

Add new line at last in input file.
Remove the byte conversion.
@mohitjha-elastic
Copy link
Contributor Author

There are not tests here. Can you remove the comment in the PR that says how to test locally since that obviously has no effect on this addition.

Have you tested? What do you need in order to add CI testing?

Thank you for pointing that out! I've removed the comment from the PR description.

It has been tested on the CrowdStrike Live Instance using the Event Stream API.
I am under the impression that system testing for streaming is not yet supported.

@efd6
Copy link
Contributor

efd6 commented Nov 20, 2024

I am under the impression that system testing for streaming is not yet supported.

As far as the input is concerned, chunked and non-chunked connections are the same. It should be possible to simulate the behaviour of the API with stream as it currently exists.

@efd6
Copy link
Contributor

efd6 commented Nov 20, 2024

/test

Copy link
Contributor

@efd6 efd6 left a comment

Choose a reason for hiding this comment

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

Looks good, but I'd like to see whether we can have system tests.

@elastic-vault-github-plugin-prod

🚀 Benchmarks report

To see the full report comment with /test benchmark fullreport

Copy link
Contributor

Choose a reason for hiding this comment

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

Have you tried just using stream?

If we do need to use this, please put callers before callees. Other comments below.

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 was encountering issues with using the stream , as it wasn't matching the requests and ended up in a loop. To resolve this, I implemented a different approach.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this because stream is not adequately stateful?

Comment on lines 13 to 20
// Mock OAuth2 client credentials
var mockClientID = "xxxx"
var mockClientSecret = "xxxx"
var datafeedCalled bool = false

// Mock OAuth2 token
var mockAccessToken = "abcd"
var mockSessionToken = "xyz"
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's use flag for these so that they can be controlled in the docker-compos.yml file.

@@ -0,0 +1,3 @@
module streaming-mock-service

go 1.21.3
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's use a more recent version.

Comment on lines 134 to 138
data := []string{
`{"metadata":{"customerIDString":"abcabcabc22221","offset":8695284,"eventType":"RemoteResponseSessionStartEvent","eventCreationTime":1698932494000,"version":"1.0"},"event":{"SessionId":"1111-fffff-4bb4-99c1-74c13cfc3e5a","HostnameField":"UKCHUDL00206","UserName":"[email protected]","StartTimestamp":1698932494,"AgentIdString":"fffffffff33333"}}`,
`{"metadata":{"customerIDString":"abcabcabc22222","offset":8695285,"eventType":"RemoteResponseSessionStartEvent","eventCreationTime":1698932494000,"version":"1.0"},"event":{"SessionId":"1111-fffff-4bb4-99c1-74c13cfc3e5a","HostnameField":"UKCHUDL00206","UserName":"[email protected]","StartTimestamp":1698932494,"AgentIdString":"fffffffff33333"}}`,
`{"metadata":{"customerIDString":"abcabcabc22223","offset":8695286,"eventType":"RemoteResponseSessionStartEvent","eventCreationTime":1698932494000,"version":"1.0"},"event":{"SessionId":"1111-fffff-4bb4-99c1-74c13cfc3e5a","HostnameField":"UKCHUDL00206","UserName":"[email protected]","StartTimestamp":1698932494,"AgentIdString":"fffffffff33333"}}`,
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Either read this from a file with flag-provided path, or use embed to get the text from a text file so that changes in the future are simpler.

1. Update golang version.
2. Use caller before calee.
3. Replace logs with log files.
Comment on lines 7 to 9
- description: Update the minimum kibana version to 8.16.0.
type: enhancement
link: https://github.com/elastic/integrations/pull/11773
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need to include this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please run go fmt.

func main() {
flag.Parse()
// Setup routes
http.HandleFunc("/oauth2/token", mockTokenHandler) // Token endpoint
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
http.HandleFunc("/oauth2/token", mockTokenHandler) // Token endpoint
http.HandleFunc("POST /oauth2/token", mockTokenHandler)
  • make use of the METHOD pattern feature of the mux
  • the code is adequately self-commenting

Comment on lines 45 to 49
// Only allow POST method
if r.Method != http.MethodPost {
http.Error(w, "Invalid request method", http.StatusMethodNotAllowed)
return
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can be dropped when using the METHOD pattern feature of the mux.

Comment on lines 183 to 185
chunk := s.data[s.index]
s.index++
copy(p, chunk)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not safe if len(p) < len(chunk).

1. Remove kibana version from changelog.
2. Utilize pattern feature of the MUX.
3. Add len check of chunk safety check.
Comment on lines 180 to 182
if len(chunk) > len(p) {
p = append(p, make([]byte, len(chunk)-len(p))...)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

You cannot do this.

@efd6
Copy link
Contributor

efd6 commented Nov 27, 2024

It's still not clear to me why you can't use stream. Can you show me how you had it configure where it did not work?

@mohitjha-elastic
Copy link
Contributor Author

It's still not clear to me why you can't use stream. Can you show me how you had it configure where it did not work?

I have sent you the full configuration file in DM that I tried earlier to use the stream.

Copy link
Contributor

@efd6 efd6 left a comment

Choose a reason for hiding this comment

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

Full patch for mock changes sent offline.

func resourceHandler(w http.ResponseWriter, r *http.Request) {
log.Printf("Received request: Method=%s, URL=%s", r.Method, r.URL.String())
log.Printf("Headers: %+v", r.Header)
if *datafeedCalled {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is racy in the context of L82.

Comment on lines 12 to 14
"events": {
"message": body.encode_json(),
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"events": {
"message": body.encode_json(),
}
?"cursor": body.?metadata.optMap(m, {"offset": m.offset}),
"events": [{
"message": body.encode_json(),
}],

Apply the patch file sent by Dan.
1. Update the system test, use stream instead of custom mock.
2. Add offset in curson in data collection.
@efd6
Copy link
Contributor

efd6 commented Nov 29, 2024

/test

@elasticmachine
Copy link

💚 Build Succeeded

History

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Crest enhancement New feature or request Integration:crowdstrike CrowdStrike Team:Security-Service Integrations Security Service Integrations Team [elastic/security-service-integrations]
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants