-
Notifications
You must be signed in to change notification settings - Fork 8
229 lines (188 loc) · 6.46 KB
/
security-scan.yml
File metadata and controls
229 lines (188 loc) · 6.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
name: Security Scanning
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch: # Manual trigger
jobs:
dependency-scan:
name: Dependency Vulnerability Scan
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install project dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[all]"
# Freeze before pip-audit is installed so its own transitive deps
# (rich → pygments etc.) are not included in the audit scope.
pip freeze --exclude-editable > project-requirements.txt
- name: Install security scanning tools
run: |
pip install pip-audit
- name: pip-audit (Fail on vulnerabilities)
run: |
echo "🔍 Running pip-audit dependency scan..."
pip-audit --desc --format json -r project-requirements.txt > pip-audit-report.json || true
if pip-audit --desc -r project-requirements.txt; then
echo "✅ No vulnerabilities found"
else
echo "❌ Vulnerabilities found!"
exit 1
fi
- name: Upload dependency scan reports
uses: actions/upload-artifact@v4
if: always()
with:
name: dependency-scan-reports
path: pip-audit-report.json
retention-days: 30
sast-scan:
name: Static Application Security Testing
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install Bandit
run: pip install bandit[toml]
- name: Run Bandit SAST (Fail on HIGH/MEDIUM issues)
run: |
echo "🔍 Running Bandit SAST scan..."
# -ll = only report HIGH and MEDIUM severity
# Exit code 1 if issues found
bandit -r cleancloud/ -ll -f json -o bandit-report.json
# Also print human-readable output
bandit -r cleancloud/ -ll
- name: Upload Bandit report
uses: actions/upload-artifact@v4
if: always()
with:
name: bandit-report
path: bandit-report.json
retention-days: 30
secrets-scan:
name: Secrets Scanning
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Full history for comprehensive scan
- name: TruffleHog Secrets Scan - PR
if: github.event_name == 'pull_request'
uses: trufflesecurity/trufflehog@v3.94.3
with:
path: ./
base: ${{ github.event.pull_request.base.sha }}
head: ${{ github.event.pull_request.head.sha }}
extra_args: --only-verified
- name: TruffleHog Secrets Scan - Push to Main
if: github.event_name == 'push'
uses: trufflesecurity/trufflehog@v3.94.3
with:
path: ./
base: ${{ github.event.before }}
head: ${{ github.event.after }}
extra_args: --only-verified
license-compliance:
name: License Compliance Check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e ".[all]"
pip install pip-licenses
- name: Generate license report
run: |
echo "📋 Generating license compliance report..."
pip-licenses --format=json --with-urls --with-description > licenses.json
pip-licenses --format=markdown > licenses.md
echo "## License Summary"
pip-licenses --summary
- name: Check for non-permissive licenses (FAIL on GPL/AGPL)
run: |
echo "🔍 Checking for restrictive licenses..."
# Fail if GPL, AGPL, or unknown licenses found
if pip-licenses | grep -iE "GPL|AGPL|Unknown"; then
echo "❌ Found restrictive or unknown licenses!"
pip-licenses
exit 1
else
echo "✅ All licenses are permissive"
fi
- name: Upload license reports
uses: actions/upload-artifact@v4
if: always()
with:
name: license-reports
path: |
licenses.json
licenses.md
retention-days: 30
codeql:
name: CodeQL Security Analysis
runs-on: ubuntu-latest
permissions:
security-events: write
actions: read
contents: read
steps:
- uses: actions/checkout@v4
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: python
queries: security-extended
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
security-summary:
name: Security Scan Summary
runs-on: ubuntu-latest
needs: [dependency-scan, sast-scan, secrets-scan, license-compliance, codeql]
if: always()
steps:
- name: Check if all scans passed
run: |
echo "🔒 Security Scan Summary"
echo "========================"
if [ "${{ needs.dependency-scan.result }}" != "success" ]; then
echo "❌ Dependency scan FAILED"
exit 1
fi
if [ "${{ needs.sast-scan.result }}" != "success" ]; then
echo "❌ SAST scan FAILED"
exit 1
fi
if [ "${{ needs.secrets-scan.result }}" != "success" ]; then
echo "❌ Secrets scan FAILED"
exit 1
fi
if [ "${{ needs.license-compliance.result }}" != "success" ]; then
echo "❌ License compliance FAILED"
exit 1
fi
if [ "${{ needs.codeql.result }}" != "success" ]; then
echo "❌ CodeQL analysis FAILED"
exit 1
fi
echo "✅ All security scans passed!"
echo ""
echo "Scans completed:"
echo " ✅ Dependency vulnerabilities (pip-audit)"
echo " ✅ Code security (Bandit SAST)"
echo " ✅ Secrets detection (TruffleHog)"
echo " ✅ License compliance (pip-licenses)"
echo " ✅ Advanced security analysis (CodeQL)"