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

OpenCanary update, resolves multiple issues #13026

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

Conversation

colin-stubbs
Copy link
Contributor

  • Bug
  • Enhancement

Proposed commit message

Resolves issues #12911, #13024, #13025. Relevant to resolution of #2518.

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.
  • I have verified that any added dashboard complies with Kibana's Dashboard good practices

Author's Checklist

Resolves multiple issues:

  • Only set event.kind == alert if event is clearly not a generic application log message
  • Migrate logfile to filestream based filebeat configuration
  • Add http_endpoint for webhook based ingest
  • Add system tests for both filestream and http_endpoint as none currently exist.
  • Add pipeline test for webhook'ed events
  • Retain password fields if desired, e.g. only remove password field if redaction requested. The current behaviour always removes passwords.
  • Provide option to remove or retain ECS mapped fields, currently this option does not exist and ECS mapped fields are always removed.
  • Add dashboard and dashboard screenshot. Currently not included in integration.
  • Fix confused tftp/vnc field names. This is a typeo/bug due to lack of sufficient sample logs for pipeline or system testing.
  • Add more complete/wider variety of sample logs for testing, e.g. TFTP & VNC events, NTP events, SNMP events etc
  • Define appropriate fields based on more complete/wider variety of sample logs
  • Fix as yet unknown logtype handling, e.g. current ingest pipeline script allows the logtype integer value to be left in a field defined as keyword leading to type conflicts and incomplete search results.
  • Update known logtype map based on latest opencanary repo code. Current list is not up to date with opencanary code.

Testing:

  • elastic-package lint && check && build
  • elastic-package test system --generate
  • elastic-package test pipeline --generate
  • elastic-package test
  • Manual deploy on local elastic-package managed stack and ingest of logfile
  • Manual deploy on remote Elastic Cloud stack and ingest of webhooks from real opencanary honeypots

How to test this PR locally

Install and operate OpenCanary, ideally via docker.
Use Elastic Agent to ingest OpenCanary log file OR webhooks.
Scan OpenCanary with nmap with scripting to trigger events, e.g. nmap -sC 127.0.0.1
Review

Related issues

Screenshots

New basic summary dashboard added,

opencanary-dashboard

@colin-stubbs colin-stubbs requested a review from a team as a code owner March 8, 2025 06:35
rebuild package and retest completed OK
Comment on lines +4 to +8
"event": {
"original": "{\"message\": \"{\\\"dst_host\\\": \\\"1.128.0.10\\\", \\\"dst_port\\\": 22, \\\"local_time\\\": \\\"2024-04-04 17:03:52.569759\\\", \\\"local_time_adjusted\\\": \\\"2024-04-04 11:03:52.569785\\\", \\\"logdata\\\": {\\\"LOCALVERSION\\\": \\\"SSH-2.0-OpenSSH_5.1p1 Debian-4\\\", \\\"PASSWORD\\\": \\\"P@ssw0rd!\\\", \\\"REMOTEVERSION\\\": \\\"SSH-2.0-OpenSSH_8.9p1 Ubuntu-3ubuntu0.6\\\", \\\"USERNAME\\\": \\\"jdoe\\\"}, \\\"logtype\\\": 4002, \\\"node_id\\\": \\\"opencanary-1\\\", \\\"src_host\\\": \\\"1.128.0.10\\\", \\\"src_port\\\": 11851, \\\"utc_time\\\": \\\"2024-04-04 17:03:52.569781\\\"}\"}"
},
"json": {
"message": "{\"dst_host\": \"1.128.0.10\", \"dst_port\": 22, \"local_time\": \"2024-04-04 17:03:52.569759\", \"local_time_adjusted\": \"2024-04-04 11:03:52.569785\", \"logdata\": {\"LOCALVERSION\": \"SSH-2.0-OpenSSH_5.1p1 Debian-4\", \"PASSWORD\": \"P@ssw0rd!\", \"REMOTEVERSION\": \"SSH-2.0-OpenSSH_8.9p1 Ubuntu-3ubuntu0.6\", \"USERNAME\": \"jdoe\"}, \"logtype\": 4002, \"node_id\": \"opencanary-1\", \"src_host\": \"1.128.0.10\", \"src_port\": 11851, \"utc_time\": \"2024-04-04 17:03:52.569781\"}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we sending both event and json.message?

Copy link
Contributor Author

@colin-stubbs colin-stubbs Mar 11, 2025

Choose a reason for hiding this comment

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

Because that's what http_endpoint does for JSON payloads when preserve_original_event: true is set...

In the case of OpenCanary's native webhooks capability and minimal/default exampled config, it's JSON payload is literally {"message":"{\"another\":\"json text string that contains the real event\"}}"

I suspect it's internal code is really just reading the text file it produces and reading it line by line as message in it's internal event representation then encoding that as JSON and sending it off to the given URL... very similar to how fluentd works if you don't specifically instruct it to parse the line as JSON or send the actual message content only.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, thanks.

- add_host_metadata: ~
{{#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.

Add final new line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So we've been here before @efd6 ...

  1. This does not affect functionality in any way shape or form.
  2. This does not affect viewing/editing functionality for anyone.
  3. This does not violate yaml or the handlebars template standard/definition.
  4. elastic-package does not identify this as an issue.

If this kind of thing is actually a problem elastic-package should identify it, and ideally fix it automatically via elastic-package format.

What's the actual problem here?
How are you even identifying these?

Copy link
Contributor

@efd6 efd6 Mar 11, 2025

Choose a reason for hiding this comment

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

The problem is noise in the git log. For your points, I agree with 3 and 4. 1 and 2 depend on the definition of "functionality" and I don't agree when I use my definition of that (which includes maintenance, not just whether the code works).

You can see the absence marked in git logs and in the GH rendering of diffs (e.g. here for this particular case — showing up as a red circle with a red dash in the middle). It can also be seen in an editor by virtue of the absence of a new line in the rendered text (when I'm reviewing code I'll often pull the branch and experiment with changes, so I see them then).

I agree, this kind of thing should be handled by either ep or (as is the case with beats) by using an .editorconfig file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure... but even elastic-package generates files like this... you can see it with sample event.json files and even the Kibana assets...

Screenshot 2025-03-11 at 10 51 38 Screenshot 2025-03-11 at 10 51 27

The entire integrations repo will be literally littered with files like this...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeap... in terms of just the yaml handlebars templates...

Quick and dirty...

user@box ~ % cat newline_test.sh 
#!/bin/bash

printf '\n' > newline_only

tail -c 1 $1 | cmp -s newline_only - || echo "$1 does not contain a final newline"

# EOF
user@box ~ % find ~/Documents/SRC/GitHub/elastic/integrations -type f -name \*.yml.hbs -exec ./newline_test.sh {} \; | wc -l
     388
user@box ~ % find ~/Documents/SRC/GitHub/elastic/integrations -type f -name \*.yml.hbs | wc -l                              
    1316
user@box ~ % find ~/Documents/SRC/GitHub/elastic/integrations -type f -name \*.yml.hbs -exec ./newline_test.sh {} \; | head -n 5
/Users/user/Documents/SRC/GitHub/elastic/integrations/packages/unifiedlogs/agent/input/unifiedlogs.yml.hbs does not contain a final newline
/Users/user/Documents/SRC/GitHub/elastic/integrations/packages/first_epss/data_stream/vulnerability/agent/stream/cel.yml.hbs does not contain a final newline
/Users/user/Documents/SRC/GitHub/elastic/integrations/packages/activemq/data_stream/broker/agent/stream/stream.yml.hbs does not contain a final newline
/Users/user/Documents/SRC/GitHub/elastic/integrations/packages/activemq/data_stream/audit/agent/stream/log.yml.hbs does not contain a final newline
/Users/user/Documents/SRC/GitHub/elastic/integrations/packages/activemq/data_stream/log/agent/stream/log.yml.hbs does not contain a final newline
user@box ~ % find ~/Documents/SRC/GitHub/elastic/integrations -type f -name \*.yml.hbs -exec ./newline_test.sh {} \; | tail -n 5
/Users/user/Documents/SRC/GitHub/elastic/integrations/packages/rubrik/data_stream/physical_hosts/agent/stream/cel.yml.hbs does not contain a final newline
/Users/user/Documents/SRC/GitHub/elastic/integrations/packages/cisco_ios/data_stream/log/agent/stream/tcp.yml.hbs does not contain a final newline
/Users/user/Documents/SRC/GitHub/elastic/integrations/packages/cisco_ios/data_stream/log/agent/stream/udp.yml.hbs does not contain a final newline
/Users/user/Documents/SRC/GitHub/elastic/integrations/packages/cisco_ios/data_stream/log/agent/stream/stream.yml.hbs does not contain a final newline
/Users/user/Documents/SRC/GitHub/elastic/integrations/build/packages/email_report/0.0.1/data_stream/tlsrpt/agent/stream/http_endpoint.yml.hbs does not contain a final newline
user@box ~ % 

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure... but even elastic-package generates files like this... you can see it with sample event.json files and even the Kibana assets...

Yes, the kibana assets are still like this, sample and expectation files are no longer rendered without a trailing new line.

{{#if processors}}
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.

Add final new line.

Comment on lines +619 to 623
description: Remove opencanary.logdata.MAC if MAC addresses were parsed out and mapped field preservation is not requested
tag: remove_opencanary_logdata_MAC
if: ctx.source?.mac != null && ctx.destination?.mac != null
if: (ctx?.tags == null || !(ctx.tags.contains('preserve_duplicate_custom_fields'))) && ctx.source?.mac != null && ctx.destination?.mac != null
field: opencanary.logdata.MAC
ignore_missing: true
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 put these in separate processors rather than rolling them together.

colin-stubbs and others added 2 commits March 11, 2025 10:48
Co-authored-by: Dan Kortschak <dan.kortschak@elastic.co>
Co-authored-by: Dan Kortschak <dan.kortschak@elastic.co>
@efd6
Copy link
Contributor

efd6 commented Mar 11, 2025

/test

@elasticmachine
Copy link

elasticmachine commented Mar 11, 2025

💔 Build Failed

Failed CI Steps

History

}
],
"type": "dashboard",
"typeMigrationVersion": "10.2.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

Error: can't install the package: could not zip-install package; API status code = 422; response body = {"statusCode":422,"error":"Unprocessable Entity","message":"Document "opencanary-96cfb6c4-bc46-4fd4-9476-e8e9550442d9" belongs to a more recent version of Kibana [10.2.0] when the last known version is [8.9.0]."}

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