Skip to content

Commit 4ae63fa

Browse files
authored
Merge pull request #1 from AmberJBlue/security-scan
chore: add security scan
2 parents 3fb42da + a24eec0 commit 4ae63fa

File tree

1 file changed

+106
-0
lines changed

1 file changed

+106
-0
lines changed
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
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+
28+
- name: Install dependencies
29+
run: |
30+
python -m pip install --upgrade pip
31+
if [ -f pyproject.toml ]; then
32+
pip install -e ".[dev]"
33+
fi
34+
35+
- name: Run Trivy vulnerability scan
36+
uses: aquasecurity/trivy-action@0.28.0
37+
with:
38+
scan-type: 'fs'
39+
scan-ref: '.'
40+
format: 'sarif'
41+
output: 'trivy-results.sarif'
42+
severity: 'CRITICAL,HIGH,MEDIUM,LOW'
43+
exit-code: '0'
44+
45+
- name: Check for critical and high vulnerabilities
46+
uses: aquasecurity/trivy-action@0.28.0
47+
with:
48+
scan-type: 'fs'
49+
scan-ref: '.'
50+
format: 'table'
51+
severity: 'CRITICAL,HIGH'
52+
exit-code: '1'
53+
54+
- name: Upload Trivy scan results to Security tab
55+
uses: github/codeql-action/upload-sarif@v3
56+
if: always()
57+
with:
58+
sarif_file: 'trivy-results.sarif'
59+
category: 'trivy-security-scan'
60+
61+
bandit-scan:
62+
name: Bandit
63+
runs-on: ubuntu-latest
64+
permissions:
65+
security-events: write
66+
actions: read
67+
contents: read
68+
checks: write
69+
70+
steps:
71+
- uses: actions/checkout@v4
72+
73+
- name: Set up Python
74+
uses: actions/setup-python@v5
75+
with:
76+
python-version: "3.11"
77+
cache: "pip"
78+
79+
- name: Create virtual environment
80+
run: |
81+
python -m pip install --upgrade pip
82+
python -m venv .venv
83+
84+
- name: Install dependencies
85+
run: |
86+
source .venv/bin/activate
87+
pip install -e ".[dev]"
88+
89+
- name: Install Bandit
90+
run: |
91+
source .venv/bin/activate
92+
pip install bandit[sarif]
93+
94+
- name: Run Bandit Security Scan
95+
uses: PyCQA/bandit-action@v1
96+
with:
97+
targets: "."
98+
exclude: "tests"
99+
100+
- name: Upload SARIF as artifact
101+
uses: actions/upload-artifact@v4
102+
with:
103+
name: bandit-sarif-results
104+
path: results.sarif
105+
retention-days: 30
106+
continue-on-error: true

0 commit comments

Comments
 (0)