-
-
Notifications
You must be signed in to change notification settings - Fork 1
289 lines (239 loc) · 9.3 KB
/
Copy pathdependency-security.yml
File metadata and controls
289 lines (239 loc) · 9.3 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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
---
name: Advanced Dependency and Security Management
on:
schedule:
# Run weekly on Sundays at 3 AM UTC
- cron: '0 3 * * 0'
pull_request:
paths:
- '.github/workflows/requirements.txt'
- 'meson.build'
- 'android/app/build.gradle'
workflow_dispatch:
inputs:
scan_type:
description: 'Type of scan to perform'
required: true
default: 'all'
type: choice
options:
- all
- dependencies
- security
- licenses
jobs:
dependency-audit:
runs-on: ubuntu-latest
outputs:
vulnerabilities-found: ${{ steps.audit.outputs.vulnerabilities }}
updates-available: ${{ steps.audit.outputs.updates }}
steps:
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Install Security Tools
run: |
pip install safety bandit semgrep pip-audit
- name: Python Dependency Audit
id: audit
run: |
echo "## 🔍 Python Dependency Audit" >> $GITHUB_STEP_SUMMARY
# Check for known vulnerabilities
if pip-audit --format=json --output=python-vulnerabilities.json; then
echo "✅ No Python vulnerabilities found" >> $GITHUB_STEP_SUMMARY
echo "vulnerabilities=false" >> $GITHUB_OUTPUT
else
echo "❌ Python vulnerabilities detected" >> $GITHUB_STEP_SUMMARY
echo "vulnerabilities=true" >> $GITHUB_OUTPUT
fi
# Check for outdated packages
pip list --outdated --format=json > outdated-packages.json
OUTDATED_COUNT=$(jq length outdated-packages.json)
if [ "$OUTDATED_COUNT" -gt 0 ]; then
echo "📦 $OUTDATED_COUNT outdated packages found" >> $GITHUB_STEP_SUMMARY
echo "updates=true" >> $GITHUB_OUTPUT
else
echo "✅ All packages up to date" >> $GITHUB_STEP_SUMMARY
echo "updates=false" >> $GITHUB_OUTPUT
fi
- name: Upload Audit Results
uses: actions/upload-artifact@v4
with:
name: dependency-audit-results
path: |
python-vulnerabilities.json
outdated-packages.json
license-compliance:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: License Scan
uses: fossa-contrib/fossa-action@v2
with:
api-key: ${{ secrets.FOSSA_API_KEY }}
- name: Generate License Report
run: |
echo "## 📄 License Compliance Report" >> $GITHUB_STEP_SUMMARY
# Check for license files
if find . -name "LICENSE*" -o -name "COPYING*" | grep -q .; then
echo "✅ License files found" >> $GITHUB_STEP_SUMMARY
else
echo "❌ No license files found" >> $GITHUB_STEP_SUMMARY
fi
# List all license types
echo "### License Files:" >> $GITHUB_STEP_SUMMARY
find . -name "LICENSE*" -o -name "COPYING*" | while read file; do
echo "- $file" >> $GITHUB_STEP_SUMMARY
done
codeql-security:
runs-on: ubuntu-latest
permissions:
security-events: write
strategy:
matrix:
language: ['cpp', 'python']
steps:
- uses: actions/checkout@v4
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}
- name: Install Dependencies
if: matrix.language == 'cpp'
run: |
sudo apt update
sudo apt install -y gperf pkg-config ninja-build meson \
libblkid-dev libudev-dev libmount-dev libkmod-dev libcap-dev
- name: Build for Analysis
if: matrix.language == 'cpp'
run: |
pip install -r .github/workflows/requirements.txt
meson setup build -Dmode=developer
meson compile -C build
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
create-security-report:
runs-on: ubuntu-latest
needs: [dependency-audit, license-compliance, codeql-security]
if: always()
steps:
- uses: actions/checkout@v4
- name: Download Audit Results
uses: actions/download-artifact@v4
with:
name: dependency-audit-results
- name: Generate Security Summary
run: |
echo "# 🛡️ Security and Compliance Report" > security-report.md
echo "Generated: $(date -u +%Y-%m-%dT%H:%M:%SZ)" >> security-report.md
echo "" >> security-report.md
echo "## 📊 Summary" >> security-report.md
echo "| Category | Status |" >> security-report.md
echo "|----------|--------|" >> security-report.md
echo "| Dependency Audit | ${{ needs.dependency-audit.result }} |" >> security-report.md
echo "| License Compliance | ${{ needs.license-compliance.result }} |" >> security-report.md
echo "| CodeQL Security | ${{ needs.codeql-security.result }} |" >> security-report.md
echo "" >> security-report.md
if [ "${{ needs.dependency-audit.outputs.vulnerabilities-found }}" = "true" ]; then
echo "## ⚠️ Vulnerabilities Found" >> security-report.md
echo "Python dependency vulnerabilities detected. See audit results for details." >> security-report.md
echo "" >> security-report.md
fi
if [ "${{ needs.dependency-audit.outputs.updates-available }}" = "true" ]; then
echo "## 📦 Package Updates Available" >> security-report.md
echo "Some packages have newer versions available." >> security-report.md
echo "" >> security-report.md
fi
echo "## 🔗 Resources" >> security-report.md
echo "- [Security Policy](https://github.com/${{ github.repository }}/security/policy)" >> security-report.md
echo "- [Vulnerability Reporting](https://github.com/${{ github.repository }}/security/advisories)" >> security-report.md
- name: Upload Security Report
uses: actions/upload-artifact@v4
with:
name: security-report
path: security-report.md
- name: Create Issue on Vulnerabilities
if: needs.dependency-audit.outputs.vulnerabilities-found == 'true'
uses: actions/github-script@v7
with:
script: |
const title = '🚨 Security Vulnerabilities Detected';
const body = `## Security Alert
Automated security scan detected vulnerabilities in dependencies.
**Details:**
- Scan Date: ${new Date().toISOString()}
- Commit: ${{ github.sha }}
- Workflow: ${{ github.workflow }}
**Action Required:**
1. Review the security report artifact
2. Update vulnerable dependencies
3. Re-run security scan to verify fixes
**Files to Check:**
- \`.github/workflows/requirements.txt\`
- \`meson.build\`
- \`android/app/build.gradle\`
This issue was created automatically. Please address the vulnerabilities promptly.`;
// Check if issue already exists
const issues = await github.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['security', 'automated'],
state: 'open'
});
const existingIssue = issues.data.find(issue => issue.title.includes('Security Vulnerabilities Detected'));
if (!existingIssue) {
await github.rest.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: title,
body: body,
labels: ['security', 'high-priority', 'automated']
});
} else {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: existingIssue.number,
body: `## 🔄 Updated Security Scan Results\n\n${body}`
});
}
automated-dependency-update:
runs-on: ubuntu-latest
needs: dependency-audit
if: >
needs.dependency-audit.outputs.updates-available == 'true' &&
github.event_name == 'schedule'
steps:
- uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Update Python Dependencies
run: |
# Update requirements file with latest versions
pip-compile --upgrade .github/workflows/requirements.in \
--output-file .github/workflows/requirements.txt || true
- name: Create Pull Request
uses: peter-evans/create-pull-request@v5
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: 'chore: automated dependency updates'
title: '🤖 Automated Dependency Updates'
body: |
## 🤖 Automated Dependency Updates
This PR contains automated updates to project dependencies.
**Changes:**
- Updated Python package versions in requirements.txt
- All updates passed security vulnerability checks
**Review Instructions:**
1. Verify all tests pass
2. Check for any breaking changes in updated packages
3. Ensure Android builds still work correctly
This PR was created automatically by the dependency management workflow.
branch: automated/dependency-updates
delete-branch: true