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:

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 Panther Analysis Tool Overview.

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

  1. Navigate to the GitHub repository where you would like to set up automation.

  2. 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:

GitHub workflow YAML
name: Panther Analysis CI/CD workflow

permissions:
  id-token: write
  contents: read

on:  
  push:
    branches:
      - main
    paths:
      - 'data_models/**'
      - 'lookup_tables/**'
      - 'policies/**'
      - 'queries/**'
      - 'rules/**'
      - '.github/workflows/**'

jobs: 
  run_unit_tests:    
    runs-on: ubuntu-latest
    name: Run unit tests on detections using the panther_analysis_tool
    steps:
      - name: Check out the repo
        uses: actions/checkout@v3
      
      - name: Set python version  
        uses: actions/setup-python@v4
        with:
          python-version: '3.9'
      
      - name: Install pipenv
        run: pip install pipenv
      
      - name: Install python dependencies and panther_analysis_tool
        run: make venv
      
      - name: Run unit tests for all detections
        run: pipenv run panther_analysis_tool test
      
  panther_analysis_tool_upload:        
    runs-on: ubuntu-latest
    name: Upload detections to panther console using panther_analysis_tool
    needs: [run_unit_tests]
    env:
      PANTHER_API_TOKEN: ${{ secrets.PANTHER_API_TOKEN }}
      PANTHER_API_HOST: "https://api.<your-panther>.runpanther.net/public/graphql"
      AWS_DEFAULT_REGION: "your-aws-region"
    steps:
      - name: Checkout the repo
        uses: actions/checkout@v3
      
      - name: Set python version  
        uses: actions/setup-python@v4
        with:
          python-version: '3.9'
      
      - name: Install pipenv
        run: pip install pipenv
      
      - name: Install python dependencies and panther_analysis_tool
        run: make venv
      
      - name: Upload Enabled detections to your Panther instance
        run: pipenv run panther_analysis_tool upload --filter Enabled=true --skip-tests
  • Make sure to update the values of the following environment variables:

    • PANTHER_API_HOST on line 47: Replace <your-panther> with your Panther instance's public GraphQL URL.

    • AWS_DEFAULT_REGION on line 48: Replace with the region where your Panther Console is deployed.

  • This workflow assumes you have added your Panther API token as a GitHub secret under the name PANTHER_API_TOKEN. If you have not already done this, follow the instructions within Prerequisites.

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
name: Panther Analysis CI/CD workflow

permissions:
  id-token: write
  contents: read

on:  
  push:
    branches:
      - main
    paths:
      - 'data_models/**'
      - 'lookup_tables/**'
      - 'policies/**'
      - 'queries/**'
      - 'rules/**'
      - '.github/workflows/**'

jobs: 
  download_pantherlog_tool:
    runs-on: ubuntu-latest
    name: Download the pantherlog tool to use for schema tests
    steps: 
      - name: Download pantherlog & unzip 
        run: curl -sSO "https://panther-community-us-east-1.s3.amazonaws.com/v1.46.0/tools/linux-amd64-pantherlog.zip" && unzip linux-amd64-pantherlog.zip
      
      - name: Create a pantherlog artifact
        uses: actions/upload-artifact@v3
        with:
          name: pantherlog
          path: pantherlog
          retention-days: 1
  
  run_schema_tests:    
    runs-on: ubuntu-latest
    name: Run schema tests with pantherlog
    needs: [download_pantherlog_tool]
    steps:
      - name: Check out the repo
        uses: actions/checkout@v3

      - name: Download Pantherlog tool from artifacts
        uses: actions/download-artifact@v3
        with: 
          name: pantherlog
      - name: Make pantherlog executable
        run: sudo chmod +x pantherlog

      - name: Perform schema tests with pantherlog
        run: ./pantherlog test ./schemas
  
  run_unit_tests:    
    runs-on: ubuntu-latest
    name: Run unit tests on detections using the panther_analysis_tool
    steps:
      - name: Check out the repo
        uses: actions/checkout@v3
      
      - name: Set python version  
        uses: actions/setup-python@v4
        with:
          python-version: '3.9'
      
      - name: Install pipenv
        run: pip install pipenv
      
      - name: Install python dependencies and panther_analysis_tool
        run: make venv
      
      - name: Run unit tests for all rule detections
        run: pipenv run panther_analysis_tool test --filter AnalysisType=rule
      
      - name: Run unit tests for all scheduled rule detections
        run: pipenv run panther_analysis_tool test --filter AnalysisType=scheduled_rule
      
      - name: Run unit tests for all policy detections
        run: pipenv run panther_analysis_tool test --filter AnalysisType=policy
  
  panther_analysis_tool_upload:        
    runs-on: ubuntu-latest
    name: Upload detections to panther console using panther_analysis_tool
    needs: [download_pantherlog_tool, run_schema_tests, run_unit_tests]
    env:
      PANTHER_API_TOKEN: ${{ secrets.PANTHER_API_TOKEN }}
      PANTHER_API_HOST: "https://api.<your-panther>.runpanther.net/public/graphql"
      AWS_DEFAULT_REGION: "your-aws-region"
    steps:
      - name: Checkout the repo
        uses: actions/checkout@v3
      
      - name: Set python version  
        uses: actions/setup-python@v4
        with:
          python-version: '3.9'

      - name: Install pipenv
        run: pip install pipenv

      - name: Install python dependencies and panther_analysis_tool
        run: make venv
      
      - name: Upload detections to your Panther instance
        run: pipenv run panther_analysis_tool upload --batch --skip-tests
      
      - name: Upload custom schemas to your Panther Instance
        run: pipenv run panther_analysis_tool update-custom-schemas --path schemas/
  • Make sure to update the values of the following environment variables:

    • PANTHER_API_HOST on line 85: Replace <your-panther> with your Panther instance's public GraphQL URL.

    • AWS_DEFAULT_REGION on line 86: Replace with the region where your Panther Console is deployed.

  • This workflow assumes you have added your Panther API token as a GitHub secret under the name PANTHER_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 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 linting against .md, .py, and .yml 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.

  • If your Workflow(s) installed NPM in a prior step, replace make venv with make install.

    • make install runs npm install, which installs Prettier to handle formatting validation.

      • Without npm, make install will fail.

    • To install npm, use the setup-node Action.

For more information on GitHub Actions, please see Github's documentation.

Last updated