This section will guide you through the process of developing Trivy plugins.
To help you get started quickly, we have published a plugin template repository.
You can use this template as a starting point for your plugin development.
Each plugin has a top-level directory, and then a plugin.yaml file.
your-plugin/
||-plugin.yaml
|-your-plugin.sh
In the example above, the plugin is contained inside a directory named your-plugin.
It has two files: plugin.yaml (required) and an executable script, your-plugin.sh (optional).
The plugin manifest is a simple YAML file named plugin.yaml.
Here is an example YAML of trivy-plugin-kubectl plugin that adds support for Kubernetes scanning.
name:"kubectl"version:"0.1.0"repository:github.com/aquasecurity/trivy-plugin-kubectlmaintainer:aquasecurityoutput:falsesummary:Scan kubectl resourcesdescription:|-A Trivy plugin that scans the images of a kubernetes resource.Usage: trivy kubectl TYPE[.VERSION][.GROUP] NAMEplatforms:-selector:# optionalos:darwinarch:amd64uri:./trivy-kubectl# where the execution file is (local file, http, git, etc.)bin:./trivy-kubectl# path to the execution file-selector:# optionalos:linuxarch:amd64uri:https://github.com/aquasecurity/trivy-plugin-kubectl/releases/download/v0.1.0/trivy-kubectl.tar.gzbin:./trivy-kubectl
We encourage you to copy and adapt plugin manifests of existing plugins.
The plugin.yaml field should contain the following information:
name: The name of the plugin. This also determines how the plugin will be made available in the Trivy CLI. For example, if the plugin is named kubectl, you can call the plugin with trivy kubectl. (required)
version: The version of the plugin. Semantic Versioning should be used. (required)
repository: The repository name where the plugin is hosted. (required)
maintainer: The name of the maintainer of the plugin. (required)
output: Whether the plugin supports the output mode. (optional)
usage: Deprecated: use summary instead. (optional)
summary: A short usage description. (required)
description: A long description of the plugin. This is where you could provide a helpful documentation of your plugin. (required)
platforms: (required)
selector: The OS/Architecture specific variations of a execution file. (optional)
os: OS information based on GOOS (linux, darwin, etc.) (optional)
arch: The architecture information based on GOARCH (amd64, arm64, etc.) (optional)
uri: Where the executable file is. Relative path from the root directory of the plugin or remote URL such as HTTP and S3. (required)
bin: Which file to call when the plugin is executed. Relative path from the root directory of the plugin. (required)
The following rules will apply in deciding which platform to select:
If both os and arch under selector match the current platform, search will stop and the platform will be used.
If selector is not present, the platform will be used.
If os matches and there is no more specific arch match, the platform will be used.
If no platform match is found, Trivy will exit with an error.
After determining platform, Trivy will download the execution file from uri and store it in the plugin cache.
When the plugin is called via Trivy CLI, bin command will be executed.
If you are hosting your plugin in a Git repository, it is strongly recommended to tag your releases with a version number.
By tagging your releases, Trivy can install specific versions of your plugin.
$trivyplugininstallreferrer@v0.3.0
When tagging versions, you must follow the Semantic Versioning and prefix the tag with v, like v1.2.3.
A plugin should be archived *.tar.gz.
After you have archived your plugin into a .tar.gz file, you can verify that your plugin installs correctly with Trivy.
The plugin.yaml file is the core of your plugin, so as long as it is published somewhere, your plugin can be installed.
If you choose to publish your plugin on GitHub, you can make it installable by placing the plugin.yaml file in the root directory of your repository.
Users can then install your plugin with the command, trivy plugin install github.com/org/repo.
While the uri specified in the plugin.yaml file doesn't necessarily need to point to the same repository, it's a good practice to host the executable file within the same repository when using GitHub.
You can utilize GitHub Releases to distribute the executable file.
For an example of how to structure your plugin repository, refer to the plugin template repository.
Trivy can install plugins directly by specifying a repository, like trivy plugin install github.com/aquasecurity/trivy-plugin-referrer,
so you don't necessarily need to register your plugin in the Trivy plugin index.
However, we would recommend distributing your plugin via the Trivy plugin index
since it makes it easier for other users to find (trivy plugin search) and install your plugin (e.g. trivy plugin install kubectl).
Submitting your plugin to the plugin index is a straightforward process.
All you need to do is create a YAML file for your plugin and place it in the plugins/ directory of the index repository.
Once you've done that, create a pull request (PR) and have it reviewed by the maintainers.
Once your PR is merged, the index will be updated, and your plugin will be available for installation.
The plugin index page will also be automatically updated to list your newly added plugin.
The content of the YAML file is very simple.
You only need to specify the name of your plugin and the repository where it is distributed.
After your PR is merged, the CI system will automatically retrieve the plugin.yaml file from your repository and update the index.yaml file.
If any required fields are missing from your plugin.yaml, the CI will fail, so make sure your plugin.yaml has all the required fields before creating a PR.
Once the index.yaml has been updated, running trivy plugin update will download the updated index to your local machine.