Links

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. 1.
    Navigate to the GitHub repository where you would like to set up automation.
  2. 2.
    Within the GitHub repository, navigate to Actions.
    The image shows the panther-analysis repo on Github. There is a red circle around the "Actions" tab.
  3. 3.
    Click New Workflow.
    The image shows the Panther-analysis repo in Github. There is a red circle around the "New Workflow" button on the left.
  4. 4.
    Click Set up a workflow yourself →.
    The image shows the panther-analysis repo on Github. The "Actions" tab is open. Under "Choose a workflow," there is a red circle around "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

  • Add the following code to the YAML file:
GitHub workflow YAML
1
name: Panther Analysis CI/CD workflow
2
3
permissions:
4
id-token: write
5
contents: read
6
7
on:
8
push:
9
branches:
10
- master
11
paths:
12
- 'data_models/**'
13
- 'lookup_tables/**'
14
- 'policies/**'
15
- 'queries/**'
16
- 'rules/**'
17
- '.github/workflows/**'
18
19
jobs:
20
run_unit_tests:
21
runs-on: ubuntu-latest
22
name: Run unit tests on detections using the panther_analysis_tool
23
steps:
24
- name: Check out the repo
25
uses: actions/checkout@v3
26
27
- name: Set python version
28
uses: actions/setup-python@v4
29
with:
30
python-version: '3.9'
31
32
- name: Install pipenv
33
run: pip install pipenv
34
35
- name: Install python dependencies and panther_analysis_tool
36
run: make install
37
38
- name: Run unit tests for all detections
39
run: pipenv run panther_analysis_tool test
40
41
panther_analysis_tool_upload:
42
runs-on: ubuntu-latest
43
name: Upload detections to panther console using panther_analysis_tool
44
needs: [run_unit_tests]
45
env:
46
PANTHER_API_TOKEN: ${{ secrets.PANTHER_API_TOKEN }}
47
PANTHER_API_HOST: "https://api.<your-panther>.runpanther.net/public/graphql"
48
AWS_DEFAULT_REGION: "your-aws-region"
49
steps:
50
- name: Checkout the repo
51
uses: actions/checkout@v3
52
53
- name: Set python version
54
uses: actions/setup-python@v4
55
with:
56
python-version: '3.9'
57
58
- name: Install pipenv
59
run: pip install pipenv
60
61
- name: Install python dependencies and panther_analysis_tool
62
run: make install
63
64
- name: Upload Enabled detections to your Panther instance
65
run: pipenv run panther_analysis_tool upload --filter Enabled=true --skip-tests
66
  • 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
1
name: Panther Analysis CI/CD workflow
2
3
permissions:
4
id-token: write
5
contents: read
6
7
on:
8
push:
9
branches:
10
- main
11
paths:
12
- 'data_models/**'
13
- 'lookup_tables/**'
14
- 'policies/**'
15
- 'queries/**'
16
- 'rules/**'
17
- '.github/workflows/**'
18
19
jobs:
20
download_pantherlog_tool:
21
runs-on: ubuntu-latest
22
name: Download the pantherlog tool to use for schema tests
23
steps:
24
- name: Download pantherlog & unzip
25
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
26
27
- name: Create a pantherlog artifact
28
uses: actions/upload-artifact@v3
29
with:
30
name: pantherlog
31
path: pantherlog
32
retention-days: 1
33
34
run_schema_tests:
35
runs-on: ubuntu-latest
36
name: Run schema tests with pantherlog
37
needs: [download_pantherlog_tool]
38
steps:
39
- name: Check out the repo
40
uses: actions/checkout@v3
41
42
- name: Download Pantherlog tool from artifacts
43
uses: actions/download-artifact@v3
44
with:
45
name: pantherlog
46
- name: Make pantherlog executable
47
run: sudo chmod +x pantherlog
48
49
- name: Perform schema tests with pantherlog
50
run: ./pantherlog test ./schemas
51
52
run_unit_tests:
53
runs-on: ubuntu-latest
54
name: Run unit tests on detections using the panther_analysis_tool
55
steps:
56
- name: Check out the repo
57
uses: actions/checkout@v3
58
59
- name: Set python version
60
uses: actions/setup-python@v4
61
with:
62
python-version: '3.9'
63
64
- name: Install pipenv
65
run: pip install pipenv
66
67
- name: Install python dependencies and panther_analysis_tool
68
run: make install
69
70
- name: Run unit tests for all rule detections
71
run: pipenv run panther_analysis_tool test --filter AnalysisType=rule
72
73
- name: Run unit tests for all scheduled rule detections
74
run: pipenv run panther_analysis_tool test --filter AnalysisType=scheduled_rule
75
76
- name: Run unit tests for all policy detections
77
run: pipenv run panther_analysis_tool test --filter AnalysisType=policy
78
79
panther_analysis_tool_upload:
80
runs-on: ubuntu-latest
81
name: Upload detections to panther console using panther_analysis_tool
82
needs: [download_pantherlog_tool, run_schema_tests, run_unit_tests]
83
env:
84
PANTHER_API_TOKEN: ${{ secrets.PANTHER_API_TOKEN }}
85
PANTHER_API_HOST: "https://api.<your-panther>.runpanther.net/public/graphql"
86
AWS_DEFAULT_REGION: "your-aws-region"
87
steps:
88
- name: Checkout the repo
89
uses: actions/checkout@v3
90
91
- name: Set python version
92
uses: actions/setup-python@v4
93
with:
94
python-version: '3.9'
95
96
- name: Install pipenv
97
run: pip install pipenv
98
99
- name: Install python dependencies and panther_analysis_tool
100
run: make install
101
102
- name: Upload detections to your Panther instance
103
run: pipenv run panther_analysis_tool upload --batch --skip-tests
104
105
- name: Upload custom schemas to your Panther Instance
106
run: pipenv run panther_analysis_tool update-custom-schemas --path schemas/
107
  • 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 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.