-
Notifications
You must be signed in to change notification settings - Fork 0
206 lines (176 loc) · 6.17 KB
/
security-dependencies.yml
File metadata and controls
206 lines (176 loc) · 6.17 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
name: Security - Dependency Scanning
on:
push:
branches: [main, develop]
paths:
- 'requirements.txt'
- 'pyproject.toml'
- 'setup.cfg'
- '.github/workflows/security-dependencies.yml'
pull_request:
branches: [main, develop]
paths:
- 'requirements.txt'
- 'pyproject.toml'
- 'setup.cfg'
schedule:
# Run daily at 2 AM UTC to catch newly disclosed vulnerabilities
- cron: '0 2 * * *'
workflow_dispatch:
permissions:
contents: read
security-events: write
pull-requests: write
jobs:
dependency-check:
name: Check for vulnerable dependencies
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.13'
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install safety pip-audit
- name: Run Safety check
id: safety
continue-on-error: true
run: |
echo "## Security Check Results" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Safety Check" >> $GITHUB_STEP_SUMMARY
safety check --json 2>/dev/null || echo "No known vulnerabilities"
echo "" >> $GITHUB_STEP_SUMMARY
- name: Run pip-audit
id: pip-audit
continue-on-error: true
run: |
echo "### pip-audit Check" >> $GITHUB_STEP_SUMMARY
pip-audit --desc --format json 2>/dev/null > /tmp/pip-audit.json || true
pip-audit --desc 2>/dev/null || echo "No vulnerabilities found"
echo "" >> $GITHUB_STEP_SUMMARY
- name: Comment on PR with findings
if: github.event_name == 'pull_request' && (steps.safety.outcome == 'failure' || steps.pip-audit.outcome == 'failure')
uses: actions/github-script@v7
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: >
⚠️ **Dependency Security Warning**
Vulnerable dependencies detected. Review the workflow logs
and update packages.
})
- name: Report vulnerability summary
if: steps.safety.outcome == 'failure' || steps.pip-audit.outcome == 'failure'
run: |
echo "❌ Vulnerable dependencies found!"
echo "Please update your dependencies:"
echo " pip install --upgrade -r requirements.txt"
exit 1
outdated-packages:
name: Check for outdated packages
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.13'
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pip-audit
- name: Check for outdated packages
id: outdated
continue-on-error: true
run: |
echo "## Outdated Packages Report" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
pip list --outdated || echo "All packages are up to date"
echo "" >> $GITHUB_STEP_SUMMARY
- name: Suggest updates
if: steps.outdated.outcome == 'failure'
run: |
echo "⚠️ Some packages are outdated. Consider updating:"
echo " pip install --upgrade -r requirements.txt"
licenses:
name: Check dependency licenses
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.13'
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pip-licenses
- name: Generate license report
run: |
echo "## License Compliance Report" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Installed Package Licenses" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
pip-licenses --format=plain --sort-by-license || true
echo '```' >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
- name: Check for incompatible licenses
id: license-check
continue-on-error: true
run: |
# Check for problematic licenses (GPL, AGPL, etc. if not compatible with Apache 2.0)
pip-licenses --fail-on AGPL --fail-on GPL || echo "⚠️ License check completed (warnings may exist)"
sbom-generation:
name: Generate Software Bill of Materials
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.13'
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install cyclonedx-bom
- name: Generate SBOM (CycloneDX format)
run: |
cyclonedx-py environment -o sbom.json --of JSON
cyclonedx-py environment -o sbom.xml --of XML
- name: Upload SBOM artifacts
uses: actions/upload-artifact@v4
with:
name: sbom-reports
path: |
sbom.json
sbom.xml
retention-days: 90
- name: Print SBOM summary
run: |
echo "## SBOM Generation Complete" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Generated SBOM files:" >> $GITHUB_STEP_SUMMARY
echo "- sbom.json (CycloneDX JSON)" >> $GITHUB_STEP_SUMMARY
echo "- sbom.xml (CycloneDX XML)" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Available as workflow artifacts" >> $GITHUB_STEP_SUMMARY