1
- name : Security
1
+ name : Security Scan
2
+
2
3
on :
3
4
push :
4
- branches :
5
- - main
5
+ branches : [main]
6
6
pull_request :
7
+ branches : [main]
8
+ workflow_dispatch :
9
+
7
10
jobs :
8
- build :
9
- name : Build
10
- runs-on : ubuntu-20.04
11
+ trivy-scan :
12
+ name : Trivy
13
+ runs-on : ubuntu-latest
11
14
permissions :
12
15
contents : read
13
16
security-events : write
17
+ actions : read
18
+
14
19
steps :
15
20
- name : Checkout code
16
21
uses : actions/checkout@v4
17
22
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
19
36
uses :
aquasecurity/[email protected]
20
37
with :
21
38
scan-type : ' fs'
39
+ scan-ref : ' .'
22
40
format : ' sarif'
23
41
output : ' trivy-results.sarif'
24
- severity : ' MEDIUM ,HIGH,CRITICAL '
42
+ severity : ' CRITICAL ,HIGH,MEDIUM,LOW '
25
43
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
27
53
28
- - name : Update Security tab
54
+ - name : Upload Trivy scan results to Security tab
29
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 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
30
110
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
0 commit comments