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

[ti_opencti] OpenCTI integration #7385

Merged
merged 100 commits into from
Oct 16, 2023
Merged

Conversation

chrisberkhout
Copy link
Contributor

@chrisberkhout chrisberkhout commented Aug 14, 2023

Proposed commit message

[ti_opencti] OpenCTI integration

A new integration for the OpenCTI threat intelligence platform:
https://www.filigran.io/en/solutions/products/opencti/

It queries a GraphQL API for indicator data using the CEL input,
populates ECS threat fields where possible and preserves additional
indicator-related data under an `opencti` prefix.

Background

OpenCTI integration development notes has some some background information about OpenCTI and the approach taken with this integration.

OpenCTI Mappings is a spreadsheet with field-level notes.

Status

What's working

This version is ready for final review and then release.

Since the demo timestamp mapping has been changed. The current mappings of the various timestamps are described in the README. The motivations for the change were to show incoming data at recent @timestamp values for a more intuitive user experience, and to build visualizations on logs-* rather than ad-hoc data views to avoid issues with persistent visualization errors and controls not working.

Potential future enhancements

  • Set up a transform to provide a view that shows the most recent non-expired data, as done elsewhere.
  • Support limiting the time range of the initial fetch.
  • Parse STIX rules for atomic indicators, so alert rules can work when no related observable is present, if requested.
    Infosec have said that, in general, observables will be present. For the demo.opencti.io data, only about 0.17% of indicators have a STIX pattern but no observables.

How to test this PR locally

Build and install the integration as usual:

cd packages/ti_opencti
elastic-package stack up -d
elastic-package build -v
elastic-package install -v
elastic-package test pipeline -v
elastic-package test system -v

With a free account on the OpenCTI public demo instance you can get an API key (in the UI under Profile > API access) that will work as a bearer token as long as you're logged in. The OpenCTI demo instance has about 1.2 million indicators. The API token and base URL are the only setting required when adding a policy.

Making dashboard changes

If dashboards need to be updated, it may be necessary to downgrade to version 8.7.1 of the stack and export them from there, to avoid failing with the error "packages with dashboards exported since Kibana 8.8.0 may not be installed till 8.10.0, please export the dashboard/s from a different version". To make the integration work on 8.7.1, some further changes are necessary:

Changes necessary to run on 8.7.1
diff --git a/packages/ti_opencti/data_stream/indicator/agent/stream/cel.yml.hbs b/packages/ti_opencti/data_stream/indicator/agent/stream/cel.yml.hbs
index f4d975ed9..20067bf9a 100644
--- a/packages/ti_opencti/data_stream/indicator/agent/stream/cel.yml.hbs
+++ b/packages/ti_opencti/data_stream/indicator/agent/stream/cel.yml.hbs
@@ -43,15 +43,15 @@ program: |
         {}
     )
   }).with({
-    "Body": {
-      "query": state.query,
+    "Body": '''{
+      "query": ''' + state.query.encode_json() + ''',
       "variables": {
-        "after": has(state.cursor) && has(state.cursor.value) ? state.cursor.value : null,
-        "first": state.page_size,
+        "after": ''' + (has(state.cursor) && has(state.cursor.value) ? state.cursor.value.encode_json() : 'null') + ''',
+        "first": ''' + string(state.page_size) + ''',
         "orderBy": "modified",
-        "orderMode": "asc",
+        "orderMode": "asc"
       }
-    }.encode_json()
+    }'''
   }).do_request().as(resp,
     bytes(resp.Body).decode_json().as(body, state.with({
       "events": body.data.indicators.edges.map(e, e.node.with(
diff --git a/packages/ti_opencti/manifest.yml b/packages/ti_opencti/manifest.yml
index 02d8ca449..881eb2eff 100644
--- a/packages/ti_opencti/manifest.yml
+++ b/packages/ti_opencti/manifest.yml
@@ -11,7 +11,7 @@ categories:
   - threat_intel
 conditions:
   kibana:
-    version: "^8.9.0"
+    version: "^8.7.1"
 screenshots:
   - src: /img/screenshot1.png
     title: "Dashboard: OpenCTI Overview"

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.

Related issues

Screenshots

Please see the screenshots in the integration.

@chrisberkhout chrisberkhout added the enhancement New feature or request label Aug 14, 2023
@elasticmachine
Copy link

elasticmachine commented Aug 14, 2023

💔 Build Failed

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2023-10-12T14:52:14.782+0000

  • Duration: 115 min 43 sec

Test stats 🧪

Test Results
Failed 0
Passed 5027
Skipped 6
Total 5033

Steps errors 2

Expand to view the steps failures

Test integration: aws
  • Took 3 min 33 sec . View more details here
  • Description: eval "$(../../build/elastic-package stack shellinit)" ../../build/elastic-package test -v --report-format xUnit --report-output file --test-coverage
Google Storage Download
  • Took 0 min 0 sec . View more details here

🤖 GitHub comments

Expand to view the GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

@elasticmachine
Copy link

elasticmachine commented Aug 23, 2023

🌐 Coverage report

Name Metrics % (covered/total) Diff
Packages 100.0% (464/464) 💚
Files 96.126% (794/826) 👎 -3.874
Classes 96.126% (794/826) 👎 -3.874
Methods 92.455% (7695/8323) 👎 -7.545
Lines 88.365% (175204/198274) 👎 -7.158
Conditionals 100.0% (0/0) 💚

Copy link
Member

@ebeahan ebeahan left a comment

Choose a reason for hiding this comment

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

Great work! I added some nits as a scanned your progress so far.

For the list of remaining items under To Do, let's talk to @jamiehynds if there are items/features we can descope in this initial version. For example, maybe we don't need to support additional auth methods, likemTLS certificate and OAuth2, up front.

packages/ti_opencti/LICENSE.txt Outdated Show resolved Hide resolved
packages/ti_opencti/img/sample-screenshot.png Outdated Show resolved Hide resolved
packages/ti_opencti/img/sample-logo.svg Outdated Show resolved Hide resolved
@chrisberkhout
Copy link
Contributor Author

/test

@chrisberkhout
Copy link
Contributor Author

/test

@chrisberkhout chrisberkhout force-pushed the ti_opencti branch 2 times, most recently from f2f4feb to f02899b Compare October 2, 2023 09:05
@chrisberkhout chrisberkhout marked this pull request as ready for review October 2, 2023 09:15
@chrisberkhout chrisberkhout requested a review from a team as a code owner October 2, 2023 09:15
@elasticmachine
Copy link

Pinging @elastic/security-external-integrations (Team:Security-External Integrations)

@efd6
Copy link
Contributor

efd6 commented Oct 3, 2023

@jsoriano I suspect the "run all the things" testing here is because of the change to links_table.yml. This is a similar situation to what I saw when I changed the pr template. Should we be doing a full test of all packages when this file changes? (I can see that we should do a check to make sure the change has not broken any generated docs).

@jsoriano
Copy link
Member

jsoriano commented Oct 3, 2023

Should we be doing a full test of all packages when this file changes? (I can see that we should do a check to make sure the change has not broken any generated docs).

Yes, it looks like a check would be enough, or we could try to make the pipeline smarter and detect what packages are using each link. Could you please open an issue to improve the situation? Though this file doesn't change frequently.

Copy link
Member

@jsoriano jsoriano left a comment

Choose a reason for hiding this comment

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

Change in CODEOWNERS and links table looks good to me.

Copy link
Contributor

@taylor-swanson taylor-swanson left a comment

Choose a reason for hiding this comment

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

Just a couple of typos to fix, but otherwise LGTM

packages/ti_opencti/_dev/build/docs/README.md Outdated Show resolved Hide resolved
packages/ti_opencti/_dev/build/docs/README.md Outdated Show resolved Hide resolved
@ebeahan
Copy link
Member

ebeahan commented Oct 16, 2023

@chrisberkhout anything else you need here or is this ready to merge and release?

@chrisberkhout
Copy link
Contributor Author

@ebeahan All feedback addressed and tests for this integration are passing. I think this is good to go.

It looks like I can't override and merge without tests passing, but if someone else can that would be good.

@ebeahan ebeahan merged commit 96d2416 into elastic:main Oct 16, 2023
3 of 4 checks passed
@elasticmachine
Copy link

Package ti_opencti - 0.1.0 containing this change is available at https://epr.elastic.co/search?package=ti_opencti

@chrisberkhout chrisberkhout deleted the ti_opencti branch October 17, 2023 09:11
@colin-stubbs
Copy link
Contributor

a pleasant surprise to see this pop up, nice work @chrisberkhout !

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

Successfully merging this pull request may close these issues.

OpenCTI
10 participants