generated from canonical/is-charms-template-repo
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Changes from all commits
Commits
Show all changes
99 commits
Select commit
Hold shift + click to select a range
07170cf
add opencti rock
weiiwang01 11dbfc8
Add basic charm
weiiwang01 4f210cf
Fix linting issues
weiiwang01 1dbcebf
Update config description
weiiwang01 a948dcb
Fix linting issues
weiiwang01 e990cd3
Fix linting issues
weiiwang01 3632067
Fix linting issues
weiiwang01 22077d2
Fix linting issues
weiiwang01 676b9a0
Fix tests
weiiwang01 dc9ce01
Add license headers
weiiwang01 d1c0c05
Update runner
weiiwang01 38db050
Improved start-up callback
weiiwang01 8a1264b
Use github hosted runners
weiiwang01 0caebdc
Update rockcraft.yaml
weiiwang01 020665a
Debug
weiiwang01 336b84c
Remove unnecessary files
weiiwang01 702add8
Remove unnecessary files
weiiwang01 1f2b5c5
Fix charm.py
weiiwang01 403aa75
Remove debug info
weiiwang01 4dbc03a
Stop callback in callback itself
weiiwang01 e494868
clean up requirements.txt
weiiwang01 875e116
Update documents
weiiwang01 9387460
Update unit tests
weiiwang01 61e7daa
Apply suggestions from review comments
weiiwang01 89e1c49
work in progress
weiiwang01 c13a476
work in progress
weiiwang01 e5c0518
work in progress
weiiwang01 ab0eb50
Apply suggestions from review comments
weiiwang01 88ae9c1
Merge platform/graphql and platform/graphql-deps in rockcraft.yaml
weiiwang01 a781a43
Add missing stage-snaps and stage-packages
weiiwang01 92d83ef
Merge branch 'init-charm' into connectors
weiiwang01 83203ef
Fixing merging
weiiwang01 8063053
Add all 18 connectors
weiiwang01 baa8794
Add more tests
weiiwang01 09ddd12
Remove connectors with name too long
weiiwang01 54ad996
Fix linting issues
weiiwang01 c5bb243
Fix linting issues
weiiwang01 fc961a0
Fix linting issues
weiiwang01 0c77534
Fix rockcraft.yaml
weiiwang01 a8ab93c
Fix rockcraft.yaml
weiiwang01 ecbc738
Fix rockcraft.yaml
weiiwang01 8e15609
Fix rockcraft.yaml
weiiwang01 e8be78f
Fix rockcraft.yaml
weiiwang01 5676858
Update .trivyignore
weiiwang01 758231a
Apply suggestions from review comments
weiiwang01 06bce03
Cleanup secrets
weiiwang01 6d95cc3
Merge branch 'init-charm' into connectors
weiiwang01 f99ae13
Fix linting issues
weiiwang01 3fd81c1
Merge branch 'init-charm' into connectors
weiiwang01 f5e2459
Update .trivyignore
weiiwang01 d0fba99
Update connector generator
weiiwang01 d726821
Update .woke.yaml
weiiwang01 5a6e508
Update linting
weiiwang01 3de4d69
Update .trivyignore
weiiwang01 5eb4d6c
Revert "Update .trivyignore"
weiiwang01 b4ab9cd
Update copyright years
weiiwang01 6a3efdb
Merge branch 'init-charm' into connectors
weiiwang01 fc7a38d
Update connectors
weiiwang01 aeb5724
Fix linting
weiiwang01 41153f6
Fix unit tests
weiiwang01 980ba73
Update copyright
weiiwang01 d97b412
Update connectors
weiiwang01 397d070
Update connectors
weiiwang01 02b05d7
Test license
weiiwang01 de0619d
Test license
weiiwang01 7b19242
Revert "Test license"
weiiwang01 635b74e
Revert "Test license"
weiiwang01 2011fac
Update opencti_connector.py
weiiwang01 2baabee
Update publish_charm.yaml
weiiwang01 32c6c1d
Merge branch 'main' into connectors
weiiwang01 63ea921
Update publish_charm.yaml
weiiwang01 568084a
Update publish_charm.yaml
weiiwang01 b9d58ab
Update publish_charm.yaml
weiiwang01 630894c
Update publish_charm.yaml
weiiwang01 4cd5b01
Update publish_charm.yaml
weiiwang01 31bae7c
Update publish_charm.yaml
weiiwang01 dc90606
Update publish_charm.yaml
weiiwang01 65df516
Apply suggestions from review comments
weiiwang01 2e5d8a1
Apply suggestions from review comments
weiiwang01 69f953a
Apply suggestions from review comments
weiiwang01 8050ec7
Apply suggestions from review comments
weiiwang01 52caf97
Apply suggestions from review comments
weiiwang01 0f11219
Apply suggestions from review comments
weiiwang01 d06c74f
Add python-is-python3
weiiwang01 f9a26aa
Wait for container ready
weiiwang01 8903c1e
Change publish_charm.yaml fail-fast to false
weiiwang01 e3eb510
Update OpenCTI graphql API client
weiiwang01 c110a56
Use the new client
weiiwang01 a65d5c1
Fix unit test and linting
weiiwang01 f98e9ef
Fix linting
weiiwang01 f9bbd2e
Apply suggestions from reviews
weiiwang01 3862ed9
Fix proxy environment
weiiwang01 2902463
Apply suggestions from review comments
weiiwang01 bf51888
Add a workflow to check connectors in sync
weiiwang01 0f2d1ad
Update
weiiwang01 0e41229
Update
weiiwang01 ccd2f3d
Update workflow
weiiwang01 8f49061
Update workflow
weiiwang01 020e8ce
Apply suggestions from review comments
weiiwang01 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,4 @@ __pycache__/ | |
.vscode | ||
.mypy_cache | ||
*.egg-info/ | ||
*/*.rock | ||
*.rock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,4 +34,5 @@ header: | |
- 'trivy.yaml' | ||
- 'zap_rules.tsv' | ||
- 'lib/**' | ||
- 'src/opencti.graphql' | ||
comment: on-failure |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ops == 2.17.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think our team generally add newline to end of file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Update the Jinja2 template to retain the trailing newline, thanks! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.