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

Add OpenCTI Connector Charms #3

Merged
merged 99 commits into from
Jan 24, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
07170cf
add opencti rock
weiiwang01 Dec 2, 2024
11dbfc8
Add basic charm
weiiwang01 Dec 9, 2024
4f210cf
Fix linting issues
weiiwang01 Dec 9, 2024
1dbcebf
Update config description
weiiwang01 Dec 9, 2024
a948dcb
Fix linting issues
weiiwang01 Dec 9, 2024
e990cd3
Fix linting issues
weiiwang01 Dec 9, 2024
3632067
Fix linting issues
weiiwang01 Dec 9, 2024
22077d2
Fix linting issues
weiiwang01 Dec 9, 2024
676b9a0
Fix tests
weiiwang01 Dec 10, 2024
dc9ce01
Add license headers
weiiwang01 Dec 10, 2024
d1c0c05
Update runner
weiiwang01 Dec 10, 2024
38db050
Improved start-up callback
weiiwang01 Dec 10, 2024
8a1264b
Use github hosted runners
weiiwang01 Dec 10, 2024
0caebdc
Update rockcraft.yaml
weiiwang01 Dec 10, 2024
020665a
Debug
weiiwang01 Dec 10, 2024
336b84c
Remove unnecessary files
weiiwang01 Dec 10, 2024
702add8
Remove unnecessary files
weiiwang01 Dec 10, 2024
1f2b5c5
Fix charm.py
weiiwang01 Dec 11, 2024
403aa75
Remove debug info
weiiwang01 Dec 11, 2024
4dbc03a
Stop callback in callback itself
weiiwang01 Dec 11, 2024
e494868
clean up requirements.txt
weiiwang01 Dec 11, 2024
875e116
Update documents
weiiwang01 Dec 11, 2024
9387460
Update unit tests
weiiwang01 Dec 11, 2024
61e7daa
Apply suggestions from review comments
weiiwang01 Dec 12, 2024
89e1c49
work in progress
weiiwang01 Dec 16, 2024
c13a476
work in progress
weiiwang01 Dec 16, 2024
e5c0518
work in progress
weiiwang01 Dec 18, 2024
ab0eb50
Apply suggestions from review comments
weiiwang01 Dec 18, 2024
88ae9c1
Merge platform/graphql and platform/graphql-deps in rockcraft.yaml
weiiwang01 Dec 18, 2024
a781a43
Add missing stage-snaps and stage-packages
weiiwang01 Dec 18, 2024
92d83ef
Merge branch 'init-charm' into connectors
weiiwang01 Dec 19, 2024
83203ef
Fixing merging
weiiwang01 Dec 19, 2024
8063053
Add all 18 connectors
weiiwang01 Dec 19, 2024
baa8794
Add more tests
weiiwang01 Dec 19, 2024
09ddd12
Remove connectors with name too long
weiiwang01 Dec 19, 2024
54ad996
Fix linting issues
weiiwang01 Dec 19, 2024
c5bb243
Fix linting issues
weiiwang01 Dec 19, 2024
fc961a0
Fix linting issues
weiiwang01 Dec 19, 2024
0c77534
Fix rockcraft.yaml
weiiwang01 Dec 19, 2024
a8ab93c
Fix rockcraft.yaml
weiiwang01 Dec 19, 2024
ecbc738
Fix rockcraft.yaml
weiiwang01 Dec 19, 2024
8e15609
Fix rockcraft.yaml
weiiwang01 Dec 19, 2024
e8be78f
Fix rockcraft.yaml
weiiwang01 Dec 19, 2024
5676858
Update .trivyignore
weiiwang01 Dec 19, 2024
758231a
Apply suggestions from review comments
weiiwang01 Dec 20, 2024
06bce03
Cleanup secrets
weiiwang01 Dec 20, 2024
6d95cc3
Merge branch 'init-charm' into connectors
weiiwang01 Dec 20, 2024
f99ae13
Fix linting issues
weiiwang01 Dec 20, 2024
3fd81c1
Merge branch 'init-charm' into connectors
weiiwang01 Dec 20, 2024
f5e2459
Update .trivyignore
weiiwang01 Dec 20, 2024
d0fba99
Update connector generator
weiiwang01 Jan 6, 2025
d726821
Update .woke.yaml
weiiwang01 Jan 6, 2025
5a6e508
Update linting
weiiwang01 Jan 7, 2025
3de4d69
Update .trivyignore
weiiwang01 Jan 7, 2025
5eb4d6c
Revert "Update .trivyignore"
weiiwang01 Jan 7, 2025
b4ab9cd
Update copyright years
weiiwang01 Jan 7, 2025
6a3efdb
Merge branch 'init-charm' into connectors
weiiwang01 Jan 8, 2025
fc7a38d
Update connectors
weiiwang01 Jan 8, 2025
aeb5724
Fix linting
weiiwang01 Jan 8, 2025
41153f6
Fix unit tests
weiiwang01 Jan 8, 2025
980ba73
Update copyright
weiiwang01 Jan 8, 2025
d97b412
Update connectors
weiiwang01 Jan 8, 2025
397d070
Update connectors
weiiwang01 Jan 8, 2025
02b05d7
Test license
weiiwang01 Jan 8, 2025
de0619d
Test license
weiiwang01 Jan 8, 2025
7b19242
Revert "Test license"
weiiwang01 Jan 8, 2025
635b74e
Revert "Test license"
weiiwang01 Jan 8, 2025
2011fac
Update opencti_connector.py
weiiwang01 Jan 14, 2025
2baabee
Update publish_charm.yaml
weiiwang01 Jan 15, 2025
32c6c1d
Merge branch 'main' into connectors
weiiwang01 Jan 15, 2025
63ea921
Update publish_charm.yaml
weiiwang01 Jan 15, 2025
568084a
Update publish_charm.yaml
weiiwang01 Jan 15, 2025
b9d58ab
Update publish_charm.yaml
weiiwang01 Jan 15, 2025
630894c
Update publish_charm.yaml
weiiwang01 Jan 15, 2025
4cd5b01
Update publish_charm.yaml
weiiwang01 Jan 15, 2025
31bae7c
Update publish_charm.yaml
weiiwang01 Jan 15, 2025
dc90606
Update publish_charm.yaml
weiiwang01 Jan 15, 2025
65df516
Apply suggestions from review comments
weiiwang01 Jan 16, 2025
2e5d8a1
Apply suggestions from review comments
weiiwang01 Jan 20, 2025
69f953a
Apply suggestions from review comments
weiiwang01 Jan 20, 2025
8050ec7
Apply suggestions from review comments
weiiwang01 Jan 20, 2025
52caf97
Apply suggestions from review comments
weiiwang01 Jan 20, 2025
0f11219
Apply suggestions from review comments
weiiwang01 Jan 20, 2025
d06c74f
Add python-is-python3
weiiwang01 Jan 20, 2025
f9a26aa
Wait for container ready
weiiwang01 Jan 20, 2025
8903c1e
Change publish_charm.yaml fail-fast to false
weiiwang01 Jan 21, 2025
e3eb510
Update OpenCTI graphql API client
weiiwang01 Jan 21, 2025
c110a56
Use the new client
weiiwang01 Jan 21, 2025
a65d5c1
Fix unit test and linting
weiiwang01 Jan 22, 2025
f98e9ef
Fix linting
weiiwang01 Jan 22, 2025
f9bbd2e
Apply suggestions from reviews
weiiwang01 Jan 22, 2025
3862ed9
Fix proxy environment
weiiwang01 Jan 23, 2025
2902463
Apply suggestions from review comments
weiiwang01 Jan 24, 2025
bf51888
Add a workflow to check connectors in sync
weiiwang01 Jan 24, 2025
0f2d1ad
Update
weiiwang01 Jan 24, 2025
0e41229
Update
weiiwang01 Jan 24, 2025
ccd2f3d
Update workflow
weiiwang01 Jan 24, 2025
8f49061
Update workflow
weiiwang01 Jan 24, 2025
020e8ce
Apply suggestions from review comments
weiiwang01 Jan 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 84 additions & 6 deletions .github/workflows/publish_charm.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,92 @@
name: Publish to edge

on:
workflow_dispatch:
push:
branches:
- main
pull_request:

jobs:
publish-to-edge:
uses: canonical/operator-workflows/.github/workflows/publish_charm.yaml@main
secrets: inherit
with:
channel: latest/edge
find-charms:
name: Find Charms
runs-on: ubuntu-latest
outputs:
charm-dirs: ${{ steps.charm-dirs.outputs.charm-dirs }}
steps:
- uses: actions/checkout@v4
- id: charm-dirs
run: |
echo charm-dirs=`find -name charmcraft.yaml | xargs dirname | jq --raw-input --slurp 'split("\n") | map(select(. != ""))'` >> $GITHUB_OUTPUT

publish-charm:
needs: [ find-charms ]
strategy:
fail-fast: false
matrix:
charm-dir: ${{ fromJSON(needs.find-charms.outputs.charm-dirs) }}
name: Publish Charm (${{ matrix.charm-dir }})
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: change directory
run: |
TEMP_DIR=$(mktemp -d)
cp -rp ./${{ matrix.charm-dir }}/. $TEMP_DIR
rm -rf .* * || :
cp -rp $TEMP_DIR/. .
rm -rf $TEMP_DIR
- name: setup lxd
uses: canonical/setup-lxd@v0.1.2
- name: find rock
id: rock-dir
run: |
echo rock-dir=`dirname *rock/rockcraft.yaml` >> $GITHUB_OUTPUT
- name: build rock
id: rockcraft
run: |
sudo snap install --channel latest/stable --classic rockcraft
cd ${{ steps.rock-dir.outputs.rock-dir }}
rockcraft pack --verbosity trace
echo rock=`ls *.rock` >> $GITHUB_OUTPUT
- run: |
echo rockcraft pack:
echo ${{ steps.rockcraft.outputs.rock }}
- name: upload rock
run: |
cd ${{ steps.rock-dir.outputs.rock-dir }}
rockcraft.skopeo --insecure-policy copy --dest-tls-verify=false oci-archive:${{ steps.rockcraft.outputs.rock }} docker-daemon:rock:latest
- name: build charm
id: charmcraft
run: |
sudo snap install --channel latest/stable --classic charmcraft
charmcraft pack --verbosity trace
echo charms=`ls *.charm` >> $GITHUB_OUTPUT
- run: |
echo charmcraft pack:
echo ${{ steps.charmcraft.outputs.charms }}
- id: charm-name
run: |
echo charm-name=`yq -r .name charmcraft.yaml` >> $GITHUB_OUTPUT
- run: |
sudo apt update && sudo apt install python3-yaml -y
- name: update upstream-source
shell: python
run: |
import yaml

charmcraft_yaml = yaml.safe_load(open("charmcraft.yaml"))
resources = charmcraft_yaml["resources"]
resources[list(resources)[0]]["upstream-source"] = "rock:latest"
yaml.dump(charmcraft_yaml, open("charmcraft.yaml", "w"), sort_keys=False)
- run: |
echo upload charm ${{ steps.charm-name.outputs.charm-name }}
- run: |
cat charmcraft.yaml
- if: github.event_name == 'push'
name: publish charm
uses: canonical/charming-actions/upload-charm@2.6.3
with:
credentials: ${{ secrets.CHARMHUB_TOKEN }}
github-token: ${{ secrets.GITHUB_TOKEN }}
built-charm-path: ${{ steps.charmcraft.outputs.charms }}
tag-prefix: ${{ steps.charm-name.outputs.charm-name }}
13 changes: 13 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ on:

jobs:
unit-tests:
name: Unit Tests
uses: canonical/operator-workflows/.github/workflows/test.yaml@main
secrets: inherit
with:
self-hosted-runner: false
Copy link

Choose a reason for hiding this comment

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

I think our team should be using the edge self hosted runners.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I think I will continue using the GitHub-hosted runner during rapid development to speed up iteration. I will switch to self-hosted runners once the project becomes more stable.

integration-tests:
name: Integration Tests
uses: canonical/operator-workflows/.github/workflows/integration_test.yaml@main
secrets: inherit
with:
Expand All @@ -19,3 +21,14 @@ jobs:
microk8s-addons: "dns ingress rbac storage"
pre-run-script: tests/integration/prepare.sh
self-hosted-runner: false
check-connector-sync:
name: Check Connectors
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.12'
- run: pip install tox
- run: tox -e generate-connectors
- run: git diff --exit-code
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ __pycache__/
.vscode
.mypy_cache
*.egg-info/
*/*.rock
*.rock
1 change: 1 addition & 0 deletions .licenserc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ header:
- 'trivy.yaml'
- 'zap_rules.tsv'
- 'lib/**'
- 'src/opencti.graphql'
comment: on-failure
3 changes: 3 additions & 0 deletions .woke.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
ignore_files:
- lib/charms/redis_k8s/v0/redis.py
- connectors/**
- scripts/**
- tests/unit/test_connectors.py
2 changes: 2 additions & 0 deletions charmcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ requires:
interface: ingress
optional: false
limit: 1
opencti-connector:
interface: opencti_connector
logging:
interface: loki_push_api
optional: true
Expand Down
46 changes: 46 additions & 0 deletions connector-template/charmcraft.yaml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.

name: opencti-{{ name }}-connector
title: OpenCTI {{ display_name_short }} Charm
summary: OpenCTI {{ display_name }} connector charm.
links:
documentation: https://discourse.charmhub.io
issues: https://github.com/canonical/opencti-operator/issues
source: https://github.com/canonical/opencti-operator
contact: https://launchpad.net/~canonical-is-devops

description: |
A [Juju](https://juju.is/) [charm](https://juju.is/docs/olm/charmed-operators)
for deploying and managing the [OpenCTI Connectors](https://docs.opencti.io/latest/deployment/connectors/)
for the OpenCTI charm.

This charm simplifies the configuration and maintenance of OpenCTI Connectors
across a range of environments, organize your cyber threat intelligence to
enhance and disseminate actionable insights.

{{ config | safe }}

provides:
opencti-connector:
interface: opencti_connector
limit: 1

type: charm
base: ubuntu@24.04
build-base: ubuntu@24.04
platforms:
amd64:
parts:
charm: {}

containers:
opencti-{{ name }}-connector:
resource: opencti-{{ name }}-connector-image
resources:
opencti-{{ name }}-connector-image:
type: oci-image
description: OCI image for the OpenCTI {{ display_name }} connector.

assumes:
- juju >= 3.4
1 change: 1 addition & 0 deletions connector-template/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ops == 2.17.0
41 changes: 41 additions & 0 deletions connector-template/rock/rockcraft.yaml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.

name: opencti-{{ name }}-connector
base: ubuntu@24.04
version: &version '{{ version }}'
summary: OpenCTI {{ display_name }} Connector
description: >-
OpenCTI connectors are the cornerstone of the OpenCTI platform and
allow organizations to easily ingest, enrich or export data.
platforms:
amd64:

parts:
{{ name }}-connector:
source: https://github.com/OpenCTI-Platform/connectors.git
source-type: git
source-tag: *version
source-depth: 1
plugin: nil
build-packages:
- python3-pip
stage-packages:
- python3
- libmagic1
- libffi8
- libxslt1.1
- libxml2
- python-is-python3
override-build: |
craftctl default
mkdir -p $CRAFT_PART_INSTALL/opt
cd {{ constant_to_kebab(connector_type) }}/{{ connector_name }}
cp -rp src $CRAFT_PART_INSTALL/opt/{{ install_location }}
{{ generate_entrypoint }}
cat entrypoint.sh | grep {{ install_location }}
mkdir -p $CRAFT_PART_INSTALL/usr/local/lib/python3.12/dist-packages
pip install \
--target $CRAFT_PART_INSTALL/usr/local/lib/python3.12/dist-packages \
-r $(find -name requirements.txt)
cp entrypoint.sh $CRAFT_PART_INSTALL/
25 changes: 25 additions & 0 deletions connector-template/src/charm.py.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env python3

# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.

"""OpenCTI {{ display_name }} connector charm the service."""

import pathlib

import ops

from charms.opencti.v0.opencti_connector import OpenctiConnectorCharm


class Opencti{{ kebab_to_pascal(name) }}ConnectorCharm(OpenctiConnectorCharm):
connector_type = "{{ connector_type }}"

@property
def charm_dir(self) -> pathlib.Path:
return pathlib.Path(__file__).parent.parent.absolute()

{{ charm_override | safe | indent(4) }}

if __name__ == "__main__":
ops.main(Opencti{{ kebab_to_pascal(name) }}ConnectorCharm)
78 changes: 78 additions & 0 deletions connectors/abuseipdb_ipblacklist/charmcraft.yaml
Copy link

Choose a reason for hiding this comment

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

I think our team generally add newline to end of file.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Update the Jinja2 template to retain the trailing newline, thanks!

Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Copyright 2025 Canonical Ltd.
# See LICENSE file for licensing details.

name: opencti-abuseipdb-ipblacklist-connector
title: OpenCTI abuseipdb ipblacklist Charm
summary: OpenCTI abuseipdb ipblacklist connector charm.
links:
documentation: https://discourse.charmhub.io
issues: https://github.com/canonical/opencti-operator/issues
source: https://github.com/canonical/opencti-operator
contact: https://launchpad.net/~canonical-is-devops

description: |
A [Juju](https://juju.is/) [charm](https://juju.is/docs/olm/charmed-operators)
for deploying and managing the [OpenCTI Connectors](https://docs.opencti.io/latest/deployment/connectors/)
for the OpenCTI charm.

This charm simplifies the configuration and maintenance of OpenCTI Connectors
across a range of environments, organize your cyber threat intelligence to
enhance and disseminate actionable insights.

config:
options:
abuseipdb-api-key:
description: Abuse IPDB API KEY
optional: false
type: string
abuseipdb-interval:
description: interval between 2 collect itself
optional: false
type: int
abuseipdb-limit:
description: limit number of result itself
optional: false
type: int
abuseipdb-score:
description: AbuseIPDB Score Limitation
optional: false
type: int
connector-scope:
type: string
description: connector scope
optional: false
abuseipdb-url:
description: the Abuse IPDB URL
type: string
optional: false
default: https://api.abuseipdb.com/api/v2/blacklist
connector-log-level:
type: string
description: determines the verbosity of the logs. Options are debug, info, warn, or error
default: info
optional: false


provides:
opencti-connector:
interface: opencti_connector
limit: 1

type: charm
base: ubuntu@24.04
build-base: ubuntu@24.04
platforms:
amd64:
parts:
charm: {}

containers:
opencti-abuseipdb-ipblacklist-connector:
resource: opencti-abuseipdb-ipblacklist-connector-image
resources:
opencti-abuseipdb-ipblacklist-connector-image:
type: oci-image
description: OCI image for the OpenCTI abuseipdb ipblacklist connector.

assumes:
- juju >= 3.4
Loading
Loading