Managing Panther Content via GitHub Actions
Manage detections and schemas in Panther with a CI/CD workflow using GitHub Actions
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
To get started with managing your Panther detections and schemas using GitHub Actions, you will need:
- A Panther API Token
- Follow our documentation for Creating 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
PANTHER_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.PantherApiToken
.
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.Follow the documentation to make use of Panther-managed detections in the panther-analysis GitHub repo: Using the Panther detections repo.
- 1.Navigate to the GitHub repository where you would like to set up automation.
- 2.Within the GitHub repository, navigate to Actions.
- 3.Click New Workflow.
- 4.Click Set up a workflow yourself →.
- 5.On the next page, replace the default filename (
main.yml
) with a descriptive name, e.g.,panther-workflow.yml
.
- Add the following code to the YAML file:
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 line47
: Replace<your-panther>
with your Panther instance's public GraphQL URL.AWS_DEFAULT_REGION
on line48
: 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.
- 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.
If you are building custom schemas, use the following YAML code to include the schemas in your workflow:
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 line85
: Replace<your-panther>
with your Panther instance's public GraphQL URL.AWS_DEFAULT_REGION
on line86
: 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.
- 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.
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.