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

WIP: Elasticsearch Matcher #28

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ggilligan12
Copy link

WORK IN PROGRESS!

This PR is by no means ready, just wanted to have it out there so structural issues and next steps can be discussed sooner rather than later! It currently comes with no documentation and no unit tests.

What does this PR do?

  • New matcher for Elasticsearch
  • Implements functionality to query Elasticsearch .siem-signals-default index and retrieve recent, open alerts associated with a particular rule that have the detonationUuid in a specified field
  • Implements functionality to close that same alert
  • Provides appropriate types and helpers for getting an Elasticsearch client and ingesting the data types the client returns

Motivation

This implements issue #24 : Alert Matching with Elastic

Want to see E2E detection testing brought to our organisation. We use Elasticsearch instead of Datadog. No reason this project couldn't be extended to add an Elasticsearch matcher.

Checklist

  • Unit tests
  • Documentation

@christophetd
Copy link
Contributor

Hi there! Thanks a lot for the PR, this is great and I'll be happy to actively help with it.

At a high level, it would be desirable to have the following:

  • Documentation on how to use Threatest with this backend, with a code + YAML example
  • Instructions to spin up a test ES setup for people like me who aren't actively using it. Ideally Docker-based, but a commercial tool with a free trial is acceptable too

Otherwise looks good overall, let me know when you'd like me to test this / a more in-depth review!

Comment on lines +13 to +25
var containsUuid bool
for _,alert := range alerts {
containsUuid = false
for _,v := range alert.Source {
if strings.Contains(v.(string), uuid) {
containsUuid = true
break
}
}
if containsUuid {
filteredAlerts = append(filteredAlerts, alert)
}
}

Choose a reason for hiding this comment

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

Suggested change
var containsUuid bool
for _,alert := range alerts {
containsUuid = false
for _,v := range alert.Source {
if strings.Contains(v.(string), uuid) {
containsUuid = true
break
}
}
if containsUuid {
filteredAlerts = append(filteredAlerts, alert)
}
}
for _, alert := range alerts {
containsUuid := false
for _, v := range alert.Source {
if strings.Contains(v.(string), uuid) {
containsUuid = true
break
}
}
if containsUuid {
filteredAlerts = append(filteredAlerts, alert)
}
}

Spacing in the for loops and moving the variable inside the loop

// Parse the response
strippedResponse, err := StripHTTPStatusCode(res.String())
if err != nil {
log.Fatal("Error while stripping prepended HTTP status code")

Choose a reason for hiding this comment

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

Do you want to include the error here? Fatal will exit immediately and so the return won't do anything and you will lose the original error. Although maybe you don't need it because there is only one error it can be 🤔

}
var data ElasticsearchQueryResponse
if err := json.Unmarshal([]byte(strippedResponse), &data); err != nil {
log.Fatal("Error unmarshalling JSON string into ElasticsearchQueryResponse struct")

Choose a reason for hiding this comment

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

You may want to log the error here so it is easier to debug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants