Managing Panther Content via GitHub Actions
Manage detections and schemas in Panther with a CI/CD workflow using GitHub Actions
Overview
You can configure GitHub Actions to automate testing, customize detections, and upload your detection pipeline from your GitHub repository to your Panther Console. This guide will walk you through the following:
Creating a custom workflow via GitHub Actions
Testing your custom schemas and detections
Uploading the schemas and detections to your Panther Console
Customizing your GitHub Actions workflow to fit your organization's needs
See CI/CD for Panther Content for information on starting your CI/CD workflow with Panther.
Prerequisites
To get started with managing your Panther detections and schemas using GitHub Actions, you will need:
A Panther API Token
See these instructions on generating an API token, and ensure it has the correct permissions for each command.
You will pass this API token as an argument to the
panther_analysis_tool
command for operations such as uploading/deleting detections, custom schemas, saved queries, and more. See this section for usage examples.
Your Panther API Host Name
Your Panther API hostname will look like this:
https://api.<your-panther-instance-name>.runpanther.net/public/graphql
Your Panther API Token added as a GitHub secret under the name
API_TOKEN
To add the token to Secrets, follow GitHub's documentation: Creating encrypted secrets for a repository. This secret is shown later in this document as
secrets.API_TOKEN
.
Configure GitHub Actions for Panther
Step 1: Make use of the Panther-managed detections in the panther-analysis GitHub repo
Follow the documentation to make use of Panther-managed detections in the panther-analysis GitHub repo: Using the Panther detections repo.
Step 2: Create a new GitHub workflow
Navigate to the GitHub repository where you would like to set up automation.
Within the GitHub repository, navigate to Actions.
Click New Workflow.
Click Set up a workflow yourself →.
On the next page, replace the default filename (
main.yml
) with a descriptive name, e.g.,panther-workflow.yml
.
Step 3: Build a workflow to test detections and upload data
Add the following code to the YAML file:
Make sure to update the values of the following environment variable:
PANTHER_API_HOST
on line39
: Replace<your-panther>
with your Panther instance's public GraphQL URL.
This workflow assumes you have added your Panther API token as a GitHub secret under the name
API_TOKEN
. If you have not already done this, follow the instructions within Prerequisites.If you'd like this workflow to only trigger on updates to content within certain folders, you can add
paths
withinon.push
. Learn more aboutpaths
in GitHub's documentation.
This will run the tests you have created on your detections and then upload all your Panther content (Lookup Tables, Data Models, and detections) if they passed.
Step 4: Push changes
Run
git push
.
After the Github Actions workflow is complete, the following will occur the next time you use git push
to make changes to the folders in the paths
section of the workflow:
Custom detections are tested with
panther_analysis_tool
.Upon success, detections are uploaded to your Panther Console.
Panther-provided GitHub workflows
The panther-analysis
workflows directory contains a number of ready-to-use GitHub workflows that you can use once you clone or fork the repository.
Workflows with names that include "(Internal)" (e.g., "Pre-Release Upload to GA (Internal)"), are not intended for customer use. Attempting to run these in your own repository may have unexpected consequences.
The workflows below are configured to trigger when a new pull request (PR) is created:
Lint: ensures your code is properly formatted and has no obvious security flaws.
Check MITRE ATT&CK Mapping Format: confirms that the format of the MITRE mappings in your detections is valid.
Test: runs all unit tests for detections and global helpers using
panther_analysis_tool test
.Validate: validates content against the Panther backend, including verifying the existence of custom log types and data lake table names (used in queries), with
panther_analysis_tool validate
.Validate only runs after a PR is approved. This is because it requires making a long-running API request to Panther, and therefore isn't well suited to being run multiple times per PR.
Build Docker Image (Deprecated): builds a new docker container for future workflows to run within.
The following workflows are triggered outside of PRs:
Sync Panther Analysis from Upstream: opens a new PR in your repository to add the most recent changes from the panther-analysis upstream repository. Use this workflow to sync your cloned or forked repository with updates to Panther-managed content.
This workflow runs at 15:00 UTC every Wednesday, and can also be triggered manually.
Upload: uploads the full content of your repository to your Panther instance using
panther_analysis_tool upload
.The Upload workflow triggers must be configured by you. It is recommended to configure this workflow to run whenever a PR is merged to
main
, but your needs may differ.
Optional: Build a workflow for custom schemas
If you are building custom schemas, use the following YAML code to include the schemas in your workflow:
Make sure to update the values of the following environment variable:
PANTHER_API_HOST
on line79
: Replace<your-panther>
with your Panther instance's public GraphQL URL.
This workflow assumes your schemas are stored in a
/schemas
directory. If they are stored elsewhere, be sure to update the location on lines11
,44
, and99
.This workflow assumes you have added your Panther API token as a GitHub secret under the name
API_TOKEN
. If you have not already done this, follow the instructions within Prerequisites.
Push changes
Run
git push
.
Now, the following will occur the next time you use git push
to make changes to the folders in the paths
section of the workflow:
Custom log schemas are tested with
pantherlog
.Custom detections are tested with
panther_analysis_tool
.Upon success, schemas and detections are uploaded to your Panther Console.
Optional: Customize your GitHub workflows in Panther
Optionally, you can extend or customize this workflow to better fit your organization. The following are common workflow customizations with Panther:
Perform linting against
.py
filesTrigger from an approved PR instead of a Push to a specific folder.
If you fork the panther-analysis repository by the latest tag, learn how syncing a fork can help keep Panther detections up-to-date. We recommend syncing weekly by tag.
Optional: Use Dependabot
Dependabot is a commonly used integration in GitHub that continually audits a repository's dependencies for security risks and available updates. Panther manages the upstream runtime environment (i.e., panther-analysis), however, you can use Dependabot for an added layer of security. To set up Dependabot for your Panther respository, follow the GitHub Dependabot quickstart guide.
Dependabot can open PRs to update your dependencies. Dependabot cannot, however, access your repository's secrets. This means that GitHub workflows that require API secrets (such as the test workflow) will fail for PRs opened by Dependabot.
To work around this, follow the GitHub instructions for storing a separate set of repository secrets specifically for Dependabot. Using this method, you must add API_HOST
and API_TOKEN
as secrets.
Last updated
Was this helpful?