-
Notifications
You must be signed in to change notification settings - Fork 0
188 lines (170 loc) Β· 6.72 KB
/
Copy pathpython-security.yml
File metadata and controls
188 lines (170 loc) Β· 6.72 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
name: 'π Security Scanning'
on:
workflow_call:
inputs:
python-version:
description: 'Python version to use'
type: string
default: '3.11'
uv-version:
description: 'UV version to use'
type: string
default: '0.11.3'
source-paths:
description: 'Source paths for security scanning'
type: string
default: 'src/'
run-bandit:
description: 'Run Bandit static analysis'
type: boolean
default: true
run-pip-audit:
description: 'Run pip-audit dependency check'
type: boolean
default: true
run-trufflehog:
description: 'Run TruffleHog secret scanning'
type: boolean
default: true
run-gitleaks:
description: 'Run Gitleaks secret scanning'
type: boolean
default: true
run-codeql:
description: 'Run CodeQL analysis'
type: boolean
default: false
bandit-severity:
description: 'Bandit minimum severity level (ll=low, l=medium, default=high)'
type: string
default: '-ll'
permissions:
contents: read
security-events: write
jobs:
# ==================================================================================
# π Static Security Analysis
# ==================================================================================
static-analysis:
name: π Static Analysis
runs-on: ubuntu-24.04
steps:
- name: π₯ Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: π Setup Python
uses: actions/setup-python@5fda3b95a4ea91299a34e894583c3862153e4b97 # v7.0.0
with:
python-version: ${{ inputs.python-version }}
- name: β‘ Install UV
uses: astral-sh/setup-uv@c771a70e6277c0a99b617c7a806ffedaca235ff9 # v9.0.0
with:
version: ${{ inputs.uv-version }}
enable-cache: true
- name: π¦ Install dependencies
run: |
uv sync --group dev
source .venv/bin/activate
uv pip install bandit pip-audit
- name: π Run Bandit security scan
if: inputs.run-bandit
run: |
source .venv/bin/activate
echo "## π Bandit Security Scan" >> $GITHUB_STEP_SUMMARY
bandit -r ${{ inputs.source-paths }} -f json -o bandit-report.json ${{ inputs.bandit-severity }} || true
bandit -r ${{ inputs.source-paths }} ${{ inputs.bandit-severity }} || true
- name: π Run pip-audit
if: inputs.run-pip-audit
run: |
source .venv/bin/activate
echo "## π Dependency Vulnerability Check" >> $GITHUB_STEP_SUMMARY
pip-audit --format json --output pip-audit-report.json || true
pip-audit || true
- name: π€ Upload security reports
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
if: always()
with:
name: security-reports
path: |
bandit-report.json
pip-audit-report.json
# ==================================================================================
# π Secret Scanning
# ==================================================================================
secret-scan:
name: π Secret Scan
runs-on: ubuntu-24.04
steps:
- name: π₯ Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
- name: π TruffleHog Scan (PR)
if: inputs.run-trufflehog && github.event_name == 'pull_request'
uses: trufflesecurity/trufflehog@main
continue-on-error: true
with:
path: ./
base: ${{ github.event.pull_request.base.sha }}
head: ${{ github.event.pull_request.head.sha }}
- name: π TruffleHog Scan (Push)
if: inputs.run-trufflehog && github.event_name == 'push' && github.event.before != '0000000000000000000000000000000000000000'
uses: trufflesecurity/trufflehog@main
continue-on-error: true
with:
path: ./
base: ${{ github.event.before }}
head: ${{ github.sha }}
- name: π TruffleHog Scan (Full)
if: inputs.run-trufflehog && (github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || (github.event_name == 'push' && github.event.before == '0000000000000000000000000000000000000000'))
uses: trufflesecurity/trufflehog@main
continue-on-error: true
with:
path: ./
extra_args: --only-verified
- name: π Gitleaks Scan
if: inputs.run-gitleaks
uses: gitleaks/gitleaks-action@e0c47f4f8be36e29cdc102c57e68cb5cbf0e8d1e # v3.0.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
continue-on-error: true
# ==================================================================================
# π¬ CodeQL Analysis
# ==================================================================================
codeql:
name: π¬ CodeQL Analysis
if: inputs.run-codeql
runs-on: ubuntu-24.04
permissions:
security-events: write
contents: read
steps:
- name: π₯ Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: π¬ Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: python
- name: π¬ Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
# ==================================================================================
# π Security Summary
# ==================================================================================
summary:
name: π Security Summary
needs: [static-analysis, secret-scan, codeql]
if: always()
runs-on: ubuntu-24.04
steps:
- name: π Generate Summary
run: |
echo "## π Security Scan Results" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "| Check | Status |" >> $GITHUB_STEP_SUMMARY
echo "|-------|--------|" >> $GITHUB_STEP_SUMMARY
echo "| Static Analysis | ${{ needs.static-analysis.result == 'success' && 'β
Passed' || 'β οΈ Issues' }} |" >> $GITHUB_STEP_SUMMARY
echo "| Secret Scan | ${{ needs.secret-scan.result == 'success' && 'β
Passed' || 'β οΈ Issues' }} |" >> $GITHUB_STEP_SUMMARY
if [ "${{ inputs.run-codeql }}" = "true" ]; then
echo "| CodeQL | ${{ needs.codeql.result == 'success' && 'β
Passed' || 'β οΈ Issues' }} |" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
echo "Security reports uploaded as artifacts for detailed review." >> $GITHUB_STEP_SUMMARY