Skip to content

Commit 83f30b2

Browse files
authored
chore: Update security scan (#225)
* Update Trivy scan * Add bandit scan * Exclude tests in bandit scan * Exclude tests in bandit scan * Remove redundant Bandit install * Guarantee serif format * Update Bandit scan * Update Bandit scan
1 parent 1e57d0e commit 83f30b2

File tree

2 files changed

+95
-12
lines changed

2 files changed

+95
-12
lines changed

.github/workflows/security.yaml

Lines changed: 94 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,114 @@
1-
name: Security
1+
name: Security Scan
2+
23
on:
34
push:
4-
branches:
5-
- main
5+
branches: [main]
66
pull_request:
7+
branches: [main]
8+
workflow_dispatch:
9+
710
jobs:
8-
build:
9-
name: Build
10-
runs-on: ubuntu-20.04
11+
trivy-scan:
12+
name: Trivy
13+
runs-on: ubuntu-latest
1114
permissions:
1215
contents: read
1316
security-events: write
17+
actions: read
18+
1419
steps:
1520
- name: Checkout code
1621
uses: actions/checkout@v4
1722

18-
- name: Trivy scan
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
1936
uses: aquasecurity/[email protected]
2037
with:
2138
scan-type: 'fs'
39+
scan-ref: '.'
2240
format: 'sarif'
2341
output: 'trivy-results.sarif'
24-
severity: 'MEDIUM,HIGH,CRITICAL'
42+
severity: 'CRITICAL,HIGH,MEDIUM,LOW'
2543
exit-code: '0'
26-
ignore-unfixed: false
44+
- name: Check for critical and high vulnerabilities
45+
uses: aquasecurity/[email protected]
46+
with:
47+
scan-type: 'fs'
48+
scan-ref: '.'
49+
format: 'table'
50+
severity: 'CRITICAL,HIGH'
51+
exit-code: '1'
52+
continue-on-error: true
2753

28-
- name: Update Security tab
54+
- name: Upload Trivy scan results to Security tab
2955
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 results to Security tab
101+
if: github.ref == 'refs/heads/main'
102+
uses: github/codeql-action/upload-sarif@v3
103+
with:
104+
sarif_file: results.sarif
105+
category: bandit-security-scan
106+
continue-on-error: true
107+
108+
- name: Upload SARIF as artifact
109+
uses: actions/upload-artifact@v4
30110
with:
31-
sarif_file: 'trivy-results.sarif'
111+
name: bandit-sarif-results
112+
path: results.sarif
113+
retention-days: 30
114+
continue-on-error: true

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,4 @@ markers = [
8585
[tool.setuptools.packages.find]
8686
where = ["src"]
8787

88-
[tool.setuptools_scm]
88+
[tool.setuptools_scm]

0 commit comments

Comments
 (0)