Links

Managing Detections and Schemas 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

Prerequisites

To get started with managing your Panther detections and schemas using GitHub Actions, you will need:
  • A Panther API Token
  • 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 PANTHER_API_TOKEN
This guide explains how to upload to your Panther Console via GitHub Actions using Panther API keys and Github secrets. This is the recommended method if you are using GitHub Actions. You can also upload to your Panther Console directly via the panther_analysis_tool.
For more information, see our CI/CD Onboarding Guide.

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: Leveraging the panther-analysis repo

Step 2: Create a new GitHub workflow

  1. 1.
    Navigate to the GitHub repository where you would like to set up automation.
  2. 2.
    Within the GitHub repository, navigate to Actions.
  3. 3.
    Click New Workflow.
  4. 4.
    Click Set up a workflow yourself →.
  5. 5.
    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

Note: This workflow assumes you have added your Panther API token as a GitHub secret under the name PANTHER_API_TOKEN. If you have not yet done this, please follow the instructions under the prerequisites.
  • Add the following code to the YAML file:
GitHub workflow YAML
  • Make sure to change the environment variable PANTHER_API_HOST on line 51 to your Panther Instance's public GraphQL URL by replacing <your-panther>.
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.

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:
GitHub workflow YAML with schemas
  • Make sure to change the environment variable PANTHER_API_HOST on line 84 to your Panther Instance's public GraphQL URL by replacing <your-panther>.
  • This workflow assumes you have added your Panther API token as a GitHub secret under the name PANTHER_API_TOKEN. Please follow the instructions under the prerequisites if you have not done that.

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 Actions workflow in Panther

Optionally, you can extend or customize this workflow to better fit your organization. The following are common workflow customizations with Panther:
  • Perform Python Linting against .py files.
  • Trigger from an approved Pull Request (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.
For more information on GitHub Actions, please see Github's documentation.