Skip to content

Commit 9ada9cb

Browse files
Merge pull request #14 from AmberJBlue/main
chore: Add Security Scan
2 parents 3fb42da + 5318088 commit 9ada9cb

File tree

1 file changed

+115
-0
lines changed

1 file changed

+115
-0
lines changed
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
name: Security Scan
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
workflow_dispatch:
9+
10+
jobs:
11+
trivy-scan:
12+
name: Trivy
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: read
16+
security-events: write
17+
actions: read
18+
19+
steps:
20+
- name: Checkout code
21+
uses: actions/checkout@v4
22+
23+
- name: Set up Python
24+
uses: actions/setup-python@v5
25+
with:
26+
python-version: '3.11'
27+
cache: "pip"
28+
29+
- name: Install dependencies
30+
run: |
31+
python -m pip install --upgrade pip
32+
if [ -f pyproject.toml ]; then
33+
pip install -e ".[dev]"
34+
fi
35+
36+
- name: Run Trivy vulnerability scan
37+
uses: aquasecurity/trivy-action@77137e9dc3ab1b329b7c8a38c2eb7475850a14e8
38+
with:
39+
scan-type: 'fs'
40+
scan-ref: '.'
41+
format: 'sarif'
42+
output: 'trivy-results.sarif'
43+
severity: 'CRITICAL,HIGH,MEDIUM,LOW'
44+
exit-code: '0'
45+
46+
- name: Check for critical and high vulnerabilities
47+
uses: aquasecurity/trivy-action@77137e9dc3ab1b329b7c8a38c2eb7475850a14e8
48+
with:
49+
scan-type: 'fs'
50+
scan-ref: '.'
51+
format: 'table'
52+
severity: 'CRITICAL,HIGH'
53+
exit-code: '1'
54+
55+
- name: Upload Trivy scan results to Security tab
56+
uses: github/codeql-action/upload-sarif@v3
57+
if: always()
58+
with:
59+
sarif_file: 'trivy-results.sarif'
60+
category: 'trivy-security-scan'
61+
62+
bandit-scan:
63+
name: Bandit
64+
runs-on: ubuntu-latest
65+
permissions:
66+
security-events: write
67+
actions: read
68+
contents: read
69+
checks: write
70+
71+
steps:
72+
- uses: actions/checkout@v4
73+
74+
- name: Set up Python
75+
uses: actions/setup-python@v5
76+
with:
77+
python-version: "3.11"
78+
cache: "pip"
79+
80+
- name: Create virtual environment
81+
run: |
82+
python -m pip install --upgrade pip
83+
python -m venv .venv
84+
85+
- name: Install dependencies
86+
run: |
87+
source .venv/bin/activate
88+
pip install -e ".[dev]"
89+
90+
- name: Install Bandit
91+
run: |
92+
source .venv/bin/activate
93+
pip install bandit[sarif]
94+
95+
- name: Run Bandit Security Scan
96+
uses: PyCQA/bandit-action@67a458d90fa11fb1463e91e7f4c8f068b5863c7f
97+
with:
98+
targets: "."
99+
exclude: "tests"
100+
101+
- name: Upload SARIF results to GitHub Security tab
102+
if: github.ref == 'refs/heads/main'
103+
uses: github/codeql-action/upload-sarif@86b04fb0e47484f7282357688f21d5d0e32175fe
104+
with:
105+
sarif_file: results.sarif
106+
category: bandit-security-scan
107+
continue-on-error: true
108+
109+
- name: Upload SARIF as artifact
110+
uses: actions/upload-artifact@v4
111+
with:
112+
name: bandit-sarif-results
113+
path: results.sarif
114+
retention-days: 30
115+
continue-on-error: true

0 commit comments

Comments
 (0)