Regenerating Plugins
Regeneration occurs when you want to update the plugin schema to add, remove, or modify any actions, triggers, improved title and descriptions, etc. without loss of code and manual updates to the JSON schema.
Instructions for Insight Plugin
The primary instructions are for the new Insight Plugin. For legacy instructions, see sections labeled Legacy Content. Please read carefully to make sure the instructions are relevant to the version you have installed.
Compatability
The latest plugin architecture is V2
, which refers to SDK and insight-plugin
tool improvements. The improvements split plugin components such as action and triggers into their own directories. For each directory, a code (e.g. action.py) and schema (e.g. schema.py) file exists. The schema files are generated directly off plugin.spec.yaml
(source of truth) and should not be modified by the user. In this design, developers only need to modify the code files.
An example of a Python plugin that is V2
compliant:
1base642├── Dockerfile3├── Makefile4├── bin5│ └── icon_base646├── icon_base647│ ├── __init__.py8│ ├── actions9│ │ ├── __init__.py10│ │ ├── decode11│ │ │ ├── __init__.py12│ │ │ ├── action.py13│ │ │ └── schema.py14│ │ └── encode15│ │ ├── __init__.py16│ │ ├── action.py17│ │ └── schema.py18│ ├── connection19│ │ ├── __init__.py20│ │ ├── connection.py21│ │ └── schema.py22│ ├── triggers23│ │ ├── __init__.py24│ │ ├── trigger.py25│ │ └── schema.py26│ └── util27│ ├── __init__.py28│ └── api.py29├── plugin.spec.yaml30├── requirements.txt31├── setup.py32└── tests33| ├── decode.json34| └── encode.json35└── unit_tests36├── __init__.py37├── test_encode.json38└── test_decode.json
- Plugins developed after October 1, 2016 have the ability to be regenerated using the older git method.
- V1 method of Regenerating Plugins
- Plugins developed after January 1, 2018 or plugins that have been ported to
V2
have the ability to be regenerated using the newer method.- The plugin
V2
architecture provides regeneration natively withinsight-plugin refresh
. - All our plugins have been ported to
V2
but your custom plugins may have not, if they haven't, it's best to port them first to make development easier for the long term.
- The plugin
Generation Command
As described in the SDK Spec document, plugin skeletons are generated by running:
insight-plugin create plugin.spec.yaml
Legacy Content
icon-plugin generate python plugin.spec.yaml
Regeneration Command
If you decide to modify your plugin’s scheme, by editing plugin.spec.yaml
, you’ll need to regenerate the plugin skeleton using insight-plugin refresh
inside the plugin’s directory to apply the changes to all the files throughout the plugin.
Legacy Content
If you decide to modify your plugin’s scheme, by editing plugin.spec.yaml
, you’ll need to regenerate the plugin skeleton using make regenerate
inside the plugin’s directory. The make regenerate
target is a shortcut that calls the full regenerate command which is icon-plugin generate python --regenerate
.
Process
The following process will automatically put the new schema changes from plugin.spec.yaml
into effect:
- Update the
plugin.spec.yaml
file - Run
insight-plugin refresh
- Update any code files needed (e.g. action.py)
Example
Here's an example of plugin regeneration by updating the schema (plugin.spec.yaml
) to support:
- A new action
- A new plugin description
- A schema for an existing action
1❯ insight-plugin refresh2Refresh process complete!
Here's a list of the changes with git status
. You can see that a few files were modified as well as the new addition of the malware_lookup action directory.
1$ git status2On branch master3Your branch is up to date with 'origin/master'.45Changes not staged for commit:6(use "git add <file>..." to update what will be committed)7(use "git checkout -- <file>..." to discard changes in working directory)89modified: .CHECKSUM10modified: bin/komand_cymon11modified: komand_cymon/actions/__init__.py12modified: plugin.spec.yaml13modified: setup.py1415Untracked files:16(use "git add <file>..." to include in what will be committed)1718komand_cymon/actions/malware_lookup/
We can see the exact changes using git diff
. Notice that the description and version were updated in multiple files, specifically: cymon/bin/komand_cymon and setup.py. The new action resulted in the creation of new directory komand_cymon/actions/malware_lookup/ which contains an action.py and schema.py file. The rest of the output are the references to the new action.
1diff --git a/cymon/bin/komand_cymon b/cymon/bin/komand_cymon2index ccd4c109d..7aed3ab00 1007553--- a/cymon/bin/komand_cymon4+++ b/cymon/bin/komand_cymon5@@ -6,8 +6,8 @@ from komand_cymon import connection, actions, triggers67Name = 'Cymon'8Vendor = 'rapid7'9-Version = '0.1.4'10-Description = 'Cymon Open Threat Intelligence'11+Version = '1.0.0'12+Description = 'Cymon is the largest tracker of open-source security reports about phishing, malware, botnets and other malicious activities'131415class KomandCymon(insightconnect_plugin_runtime.Plugin):16@@ -31,6 +31,8 @@ class KomandCymon(insightconnect_plugin_runtime.Plugin):1718self.add_action(actions.DomainLookup())1920+ self.add_action(actions.MalwareLookup())21+22self.add_action(actions.UrlLookup())232425diff --git a/cymon/komand_cymon/actions/__init__.py b/cymon/komand_cymon/actions/__init__.py26index 41ac95ec7..44a025ccb 10075527--- a/cymon/komand_cymon/actions/__init__.py28+++ b/cymon/komand_cymon/actions/__init__.py29@@ -3,4 +3,5 @@ from .address_blacklist.action import AddressBlacklist30from .address_lookup.action import AddressLookup31from .domain_blacklist.action import DomainBlacklist32from .domain_lookup.action import DomainLookup33+from .malware_lookup.action import MalwareLookup34from .url_lookup.action import UrlLookup35diff --git a/cymon/plugin.spec.yaml b/cymon/plugin.spec.yaml36index a435d9eaf..23dda41a8 10064437--- a/cymon/plugin.spec.yaml38+++ b/cymon/plugin.spec.yaml39@@ -1,8 +1,8 @@40plugin_spec_version: v241name: cymon42title: Cymon43-description: "Cymon Open Threat Intelligence"44-version: 0.1.445+description: "Cymon is the largest tracker of open-source security reports about phishing, malware, botnets and other malicious activities"46+version: 1.0.047vendor: rapid748@@ -529,3 +529,14 @@ actions:49url:50type: "[]string"51title: Cymon URL References52+ malware_lookup:53+ description: Lookup malware hash54+ input:55+ hash:56+ type: string57+ description: MD5 or SHA1 hash58+ required: true59+ output:60+ found:61+ type: boolean62+ title: Malware Found63diff --git a/cymon/setup.py b/cymon/setup.py64index e72761182..6e8117680 10075565--- a/cymon/setup.py66+++ b/cymon/setup.py67@@ -3,8 +3,8 @@ from setuptools import setup, find_packages686970setup(name='cymon-komand-plugin',71- version='0.1.4',72- description='Cymon Open Threat Intelligence',73+ version='1.0.0',74+ description='Cymon is the largest tracker of open-source security reports about phishing, malware, botnets and other malicious activities',75author='komand',76author_email='',77url='',
In addition, you will see changes to the plugin.spec.yaml
file itself, since it’s the source of truth and we created those changes manually.
Now, add your code to the new komand_cymon/actions/malware_lookup/action.py file, test, and finalize your changes with:
1$ git add .2$ git commit -m "Regenerate Cymon with new description and new malware lookup action"