forked from thrixxy-technologies/flavorsnap
-
Notifications
You must be signed in to change notification settings - Fork 0
214 lines (180 loc) · 6.28 KB
/
Copy pathsecurity.yml
File metadata and controls
214 lines (180 loc) · 6.28 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
name: Security Scanning
on:
push:
branches: [ main, master, develop ]
pull_request:
branches: [ main, master, develop ]
schedule:
# Run security scans daily at 2 AM UTC
- cron: '0 2 * * *'
jobs:
python-security-scan:
runs-on: ubuntu-latest
name: Python Security Scan
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.9'
- name: Cache pip dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install safety bandit semgrep
- name: Run Safety (dependency vulnerability scanning)
run: |
find . -name "requirements.txt" -exec safety check -r {} \; || true
safety check --json --output safety-report.json || true
- name: Run Bandit (code security analysis)
run: |
bandit -r . -f json -o bandit-report.json || true
bandit -r . || true
- name: Run Semgrep (static analysis)
run: |
semgrep --config=auto --json --output=semgrep-report.json || true
semgrep --config=auto || true
- name: Upload security scan results
uses: actions/upload-artifact@v3
if: always()
with:
name: python-security-reports
path: |
safety-report.json
bandit-report.json
semgrep-report.json
retention-days: 30
rust-security-scan:
runs-on: ubuntu-latest
name: Rust Security Scan
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
components: rustfmt, clippy
- name: Cache cargo dependencies
uses: actions/cache@v3
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-
- name: Install cargo-audit
run: cargo install cargo-audit
- name: Run cargo audit (dependency vulnerability scanning)
run: |
cargo audit --json > audit-report.json || true
cargo audit || true
- name: Run cargo clippy (linting)
run: |
cargo clippy --all-targets --all-features -- -D warnings || true
- name: Run cargo fmt check
run: cargo fmt --all -- --check
- name: Upload Rust security scan results
uses: actions/upload-artifact@v3
if: always()
with:
name: rust-security-reports
path: |
audit-report.json
retention-days: 30
secret-scan:
runs-on: ubuntu-latest
name: Secret Scanning
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Run TruffleHog (secret scanning)
uses: trufflesecurity/trufflehog@main
with:
path: ./
base: main
head: HEAD
extra_args: --debug --only-verified
- name: Run Gitleaks (secret scanning)
uses: gitleaks/gitleaks-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITLEAKS_LICENSE: ${{ secrets.GITLEAKS_LICENSE }}
docker-security-scan:
runs-on: ubuntu-latest
name: Docker Security Scan
if: contains(github.event.head_commit.modified, 'Dockerfile') || github.event_name == 'schedule'
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Build Docker image
run: |
if [ -f "Dockerfile" ]; then
docker build -t flavorsnap-test .
else
echo "No Dockerfile found, skipping Docker security scan"
exit 0
fi
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
image-ref: flavorsnap-test
format: 'sarif'
output: 'trivy-results.sarif'
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v2
if: always()
with:
sarif_file: 'trivy-results.sarif'
security-summary:
runs-on: ubuntu-latest
name: Security Summary
needs: [python-security-scan, rust-security-scan, secret-scan]
if: always()
steps:
- name: Download all artifacts
uses: actions/download-artifact@v3
- name: Create security summary
run: |
echo "# Security Scan Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "## Scan Results" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ -d "python-security-reports" ]; then
echo "### Python Security" >> $GITHUB_STEP_SUMMARY
if [ -f "python-security-reports/safety-report.json" ]; then
echo "- ✅ Safety dependency scan completed" >> $GITHUB_STEP_SUMMARY
else
echo "- ⚠️ Safety scan had issues" >> $GITHUB_STEP_SUMMARY
fi
if [ -f "python-security-reports/bandit-report.json" ]; then
echo "- ✅ Bandit code analysis completed" >> $GITHUB_STEP_SUMMARY
else
echo "- ⚠️ Bandit scan had issues" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
fi
if [ -d "rust-security-reports" ]; then
echo "### Rust Security" >> $GITHUB_STEP_SUMMARY
if [ -f "rust-security-reports/audit-report.json" ]; then
echo "- ✅ Cargo audit completed" >> $GITHUB_STEP_SUMMARY
else
echo "- ⚠️ Cargo audit had issues" >> $GITHUB_STEP_SUMMARY
fi
echo "" >> $GITHUB_STEP_SUMMARY
fi
echo "### Recommendations" >> $GITHUB_STEP_SUMMARY
echo "- Review any security findings in the uploaded artifacts" >> $GITHUB_STEP_SUMMARY
echo "- Address high-severity vulnerabilities promptly" >> $GITHUB_STEP_SUMMARY
echo "- Regular updates of dependencies are recommended" >> $GITHUB_STEP_SUMMARY