Skip to content

Commit 3746750

Browse files
committed
update security-scan.yaml
1 parent bdac6f1 commit 3746750

File tree

1 file changed

+62
-45
lines changed

1 file changed

+62
-45
lines changed
Lines changed: 62 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,89 +1,106 @@
11
name: Security Scan
22

33
on:
4-
pull_request:
5-
branches: [main]
64
push:
75
branches: [main]
6+
pull_request:
7+
branches: [main]
88
workflow_dispatch:
99

10-
concurrency:
11-
group: security-scan-${{ github.ref }}
12-
cancel-in-progress: false
13-
1410
jobs:
1511
trivy-scan:
16-
name: Trivy Scan Report
12+
name: Trivy
1713
runs-on: ubuntu-latest
1814
permissions:
1915
contents: read
2016
security-events: write
2117
actions: read
18+
2219
steps:
23-
- uses: actions/checkout@v4
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
2434
2535
- name: Run Trivy vulnerability scan
2636
uses: aquasecurity/trivy-action@0.28.0
2737
with:
28-
scan-type: fs
29-
scan-ref: .
30-
format: sarif
31-
output: trivy-results.sarif
32-
severity: CRITICAL,HIGH,MEDIUM,LOW
33-
exit-code: 0
34-
ignore-unfixed: false
35-
vuln-type: os,library
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'
3653

37-
- name: Upload SARIF
54+
- name: Upload Trivy scan results to Security tab
3855
uses: github/codeql-action/upload-sarif@v3
3956
if: always()
4057
with:
41-
sarif_file: trivy-results.sarif
42-
category: trivy-security-scan
43-
44-
trivy-gate:
45-
name: Trivy Gate
46-
needs: trivy-scan
47-
runs-on: ubuntu-latest
48-
permissions:
49-
contents: read
50-
steps:
51-
- uses: actions/checkout@v4
52-
- name: Check for critical and high vulnerabilities
53-
uses: aquasecurity/trivy-action@0.28.0
54-
with:
55-
scan-type: fs
56-
scan-ref: .
57-
format: table
58-
severity: CRITICAL,HIGH
59-
exit-code: 1
60-
ignore-unfixed: false
61-
vuln-type: os,library
58+
sarif_file: 'trivy-results.sarif'
59+
category: 'trivy-security-scan'
6260

6361
bandit-scan:
6462
name: Bandit
6563
runs-on: ubuntu-latest
6664
permissions:
67-
contents: read
6865
security-events: write
6966
actions: read
67+
contents: read
68+
checks: write
69+
7070
steps:
7171
- uses: actions/checkout@v4
7272

7373
- name: Set up Python
7474
uses: actions/setup-python@v5
7575
with:
7676
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]
7793
7894
- name: Run Bandit Security Scan
7995
uses: PyCQA/bandit-action@v1
8096
with:
8197
targets: "."
82-
exclude: "tests,docs"
98+
exclude: "tests"
8399

84-
- name: Upload Bandit SARIF to Security tab
85-
if: always()
86-
uses: github/codeql-action/upload-sarif@v3
100+
- name: Upload SARIF as artifact
101+
uses: actions/upload-artifact@v4
87102
with:
88-
sarif_file: results.sarif
89-
category: bandit-security-scan
103+
name: bandit-sarif-results
104+
path: results.sarif
105+
retention-days: 30
106+
continue-on-error: true

0 commit comments

Comments
 (0)