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