-
Notifications
You must be signed in to change notification settings - Fork 24
260 lines (221 loc) · 7.19 KB
/
security.yml
File metadata and controls
260 lines (221 loc) · 7.19 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
name: Security
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main, develop ]
schedule:
- cron: '0 6 * * *' # Run daily at 6 AM UTC
env:
CARGO_TERM_COLOR: always
jobs:
audit:
name: Security Audit
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Install cargo-audit
run: cargo install cargo-audit
- name: Cache Cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
key: ${{ runner.os }}-cargo-audit-${{ hashFiles('**/Cargo.lock') }}
- name: Run cargo audit
run: cargo audit --json > audit-results.json
- name: Parse audit results
run: |
if [ -s audit-results.json ]; then
echo "## Security Audit Results" > audit-summary.md
echo "" >> audit-summary.md
# Check if there are any vulnerabilities
if jq -e '.vulnerabilities.found | length > 0' audit-results.json > /dev/null; then
echo "❌ **Vulnerabilities Found**" >> audit-summary.md
echo "" >> audit-summary.md
jq -r '.vulnerabilities.list[] | "- **\(.package.name)** \(.package.version): \(.advisory.title)"' audit-results.json >> audit-summary.md
echo "" >> audit-summary.md
else
echo "✅ **No vulnerabilities found**" >> audit-summary.md
echo "" >> audit-summary.md
fi
# Check for warnings
if jq -e '.warnings | length > 0' audit-results.json > /dev/null; then
echo "⚠️ **Warnings**" >> audit-summary.md
echo "" >> audit-summary.md
jq -r '.warnings[] | "- \(.kind): \(.package.name) \(.package.version)"' audit-results.json >> audit-summary.md
fi
else
echo "✅ **Security audit completed successfully with no issues**" > audit-summary.md
fi
- name: Upload audit results
uses: actions/upload-artifact@v5
with:
name: security-audit-results
path: |
audit-results.json
audit-summary.md
- name: Fail on vulnerabilities
run: |
if jq -e '.vulnerabilities.found | length > 0' audit-results.json > /dev/null; then
echo "❌ Security vulnerabilities found!"
exit 1
fi
dependency-check:
name: Dependency Check
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Install cargo-deny
run: cargo install cargo-deny
- name: Cache Cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
key: ${{ runner.os }}-cargo-deny-${{ hashFiles('**/Cargo.lock') }}
- name: Create deny.toml config
run: |
cat > deny.toml << 'EOF'
[licenses]
allow = [
"MIT",
"Apache-2.0",
"Apache-2.0 WITH LLVM-exception",
"BSD-2-Clause",
"BSD-3-Clause",
"ISC",
"Unicode-DFS-2016",
"CC0-1.0",
]
deny = [
"GPL-2.0",
"GPL-3.0",
"AGPL-3.0",
]
[[licenses.exceptions]]
allow = ["Unicode-DFS-2016"]
name = "unicode-ident"
[bans]
multiple-versions = "warn"
wildcards = "allow"
deny = [
{ name = "openssl", version = "*" }, # Prefer rustls
]
[advisories]
vulnerability = "deny"
unmaintained = "warn"
yanked = "deny"
notice = "warn"
[sources]
unknown-registry = "deny"
unknown-git = "deny"
allow-registry = ["https://github.com/rust-lang/crates.io-index"]
EOF
- name: Run dependency check
run: cargo deny check
- name: Check for outdated dependencies
run: |
cargo install cargo-outdated
cargo outdated --root-deps-only > outdated-deps.txt || true
echo "## Outdated Dependencies Report" > outdated-report.md
echo "" >> outdated-report.md
echo '```' >> outdated-report.md
cat outdated-deps.txt >> outdated-report.md
echo '```' >> outdated-report.md
- name: Upload dependency reports
uses: actions/upload-artifact@v5
with:
name: dependency-reports
path: |
outdated-deps.txt
outdated-report.md
supply-chain:
name: Supply Chain Security
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
- name: Install cargo-supply-chain
run: cargo install cargo-supply-chain
- name: Analyze supply chain
run: |
echo "## Supply Chain Analysis" > supply-chain-report.md
echo "" >> supply-chain-report.md
echo "Generated on: $(date)" >> supply-chain-report.md
echo "" >> supply-chain-report.md
echo "### Crate Authors Analysis" >> supply-chain-report.md
echo '```' >> supply-chain-report.md
cargo supply-chain authors >> supply-chain-report.md || echo "Analysis completed" >> supply-chain-report.md
echo '```' >> supply-chain-report.md
- name: Upload supply chain analysis
uses: actions/upload-artifact@v5
with:
name: supply-chain-analysis
path: supply-chain-report.md
semgrep:
name: Static Analysis (Semgrep)
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Run Semgrep
uses: semgrep/semgrep-action@v1
with:
config: >-
p/security-audit
p/rust
p/secrets
generateSarif: "1"
- name: Upload SARIF file
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: semgrep.sarif
if: always()
clippy-security:
name: Clippy Security Lints
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v5
- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y build-essential pkg-config libssl-dev
- name: Cache Cargo registry
uses: actions/cache@v4
with:
path: |
~/.cargo/registry
~/.cargo/git
target
key: ${{ runner.os }}-cargo-clippy-security-${{ hashFiles('**/Cargo.lock') }}
- name: Run security-focused Clippy lints
run: |
cargo clippy --workspace --all-targets --all-features -- \
-W clippy::integer_overflow \
-W clippy::panic \
-W clippy::unwrap_used \
-W clippy::expect_used \
-W clippy::indexing_slicing \
-W clippy::arithmetic_side_effects \
-W clippy::as_conversions \
-W clippy::cast_precision_loss \
-W clippy::cast_possible_truncation \
-W clippy::cast_sign_loss \
-W clippy::float_cmp \
-W clippy::lossy_float_literal