-
Notifications
You must be signed in to change notification settings - Fork 50
296 lines (264 loc) · 9.97 KB
/
Copy pathsecurity-scans.yaml
File metadata and controls
296 lines (264 loc) · 9.97 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
290
291
292
293
294
295
296
# Security Scans - Comprehensive security checks
#
# Jobs:
# - Dependency Review (always)
# - Shellcheck (shell scripts)
# - YAML Lint (workflows, charts)
# - Helm Lint (charts/)
# - Hadolint (Dockerfiles)
# - Trivy (filesystem + IaC)
# - CodeQL (Go)
# - Action Pinning (informational)
#
name: Security Scans
on:
pull_request:
branches: [main]
permissions: {}
jobs:
# ============================================================================
# Phase 0: Foundations
# ============================================================================
dependency-review:
name: Dependency Review
runs-on: ubuntu-latest
# TODO: Remove continue-on-error after enabling Dependency Graph in
# repo Settings > Code security and analysis
continue-on-error: true
permissions:
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Dependency Review
uses: actions/dependency-review-action@a1d282b36b6f3519aa1f3fc636f609c47dddb294 # v4
with:
fail-on-severity: moderate
deny-licenses: GPL-3.0, AGPL-3.0
comment-summary-in-pr: never
shellcheck:
name: Shell Script Lint
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Install shellcheck
run: sudo apt-get install -y shellcheck
- name: Run shellcheck
run: |
SCRIPTS=$(find . -name "*.sh" -type f 2>/dev/null | grep -v ".git/" || true)
if [ -z "$SCRIPTS" ]; then
echo "No shell scripts found"
exit 0
fi
echo "Found scripts:"
echo "$SCRIPTS"
echo ""
FAILED=0
for script in $SCRIPTS; do
echo "Checking: $script"
if ! shellcheck --severity=error "$script"; then
FAILED=1
fi
done
if [ $FAILED -eq 1 ]; then
echo "ERROR: Some scripts have shellcheck errors."
exit 1
fi
echo "All scripts passed shellcheck (error level)"
# ============================================================================
# Phase A: Linting
# ============================================================================
yamllint:
name: YAML Lint
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Install yamllint
run: pip install yamllint==1.*
- name: Create config
run: |
cat > .yamllint.yaml << 'EOF'
extends: relaxed
ignore: |
charts/*/templates/
rules:
line-length:
max: 150
level: warning
truthy:
check-keys: false
document-start: disable
comments:
min-spaces-from-content: 1
indentation:
spaces: 2
indent-sequences: whatever
EOF
- name: Lint YAML files
run: |
yamllint -c .yamllint.yaml \
.github/workflows/ \
charts/ || true
echo ""
echo "=== Summary ==="
yamllint -c .yamllint.yaml -f parsable \
.github/workflows/ charts/ > /tmp/yamllint_output.txt 2>&1 || true
ERROR_COUNT=$(grep -c ":error:" /tmp/yamllint_output.txt 2>/dev/null || echo "0")
echo "Errors: $ERROR_COUNT"
if [ "$ERROR_COUNT" -gt 0 ] 2>/dev/null; then
echo "ERROR: YAML files have syntax errors."
exit 1
fi
helm-lint:
name: Helm Chart Lint
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Set up Helm
uses: azure/setup-helm@9bc31f4ebc9c6b171d7bfbaa5d006ae7abdb4310 # v5.0.1
with:
version: 'v3.14.0'
- name: Lint Helm charts
run: |
for chart in charts/*/; do
if [ -f "$chart/Chart.yaml" ]; then
echo "Linting: $chart"
# Informational only — don't fail on pre-existing chart issues
helm lint "$chart" 2>&1 || true
echo ""
fi
done
- name: Install yq
uses: mikefarah/yq@c14f446382944492701b16c1ddb48bb9dbe683e3 # v4
- name: Guard — AuthBridge injection images must be version-pinned (no floating tags)
# Catches a :latest / floating-tag regression at PR-review time rather than
# mid-release (rossoctl/rossoctl#508). Positive assertion: every injection image
# must carry a :vX.Y.Z tag, in BOTH the chart values and the compiled Go fallbacks
# (config/defaults.go, which the platform-config ConfigMap overlays on top of — a
# no-ConfigMap deploy would otherwise still inject :latest).
run: |
set -euo pipefail
fail=0
for k in envoyProxy authbridge authbridgeLite proxyInit; do
img=$(yq ".defaults.images.$k" charts/operator/values.yaml)
if [[ ! "$img" =~ :v[0-9]+\.[0-9]+\.[0-9]+ ]]; then
echo "::error file=charts/operator/values.yaml::defaults.images.$k not version-pinned: $img"
fail=1
fi
done
while IFS= read -r img; do
if [[ ! "$img" =~ :v[0-9]+\.[0-9]+\.[0-9]+ ]]; then
echo "::error file=operator/internal/webhook/config/defaults.go::compiled default not version-pinned: $img"
fail=1
fi
done < <(grep -oE 'ghcr\.io/rossoctl/cortex/[a-z-]+:[^"]+' operator/internal/webhook/config/defaults.go)
if [ "$fail" -ne 0 ]; then
echo "::error::pin the flagged AuthBridge injection image(s) to a cortex release tag (rossoctl/rossoctl#508)"
exit 1
fi
echo "AuthBridge injection images are version-pinned OK (values.yaml + config/defaults.go)"
# ============================================================================
# Phase B: Container/IaC Security
# ============================================================================
hadolint:
name: Dockerfile Lint (Hadolint)
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Find Dockerfiles
id: find-dockerfiles
run: |
DOCKERFILES=$(find . -name "Dockerfile*" -type f 2>/dev/null | grep -v ".git/" || true)
if [ -z "$DOCKERFILES" ]; then
echo "has_dockerfiles=false" >> "$GITHUB_OUTPUT"
else
echo "Found Dockerfiles:"
echo "$DOCKERFILES"
echo "has_dockerfiles=true" >> "$GITHUB_OUTPUT"
fi
- name: Run Hadolint
if: steps.find-dockerfiles.outputs.has_dockerfiles == 'true'
uses: hadolint/hadolint-action@06be81baf89a55ffd0e24b8f04a4185738dd3387 # v3.5.0
with:
dockerfile: "**/Dockerfile*"
recursive: true
failure-threshold: error
# DL3007: Using latest tag, DL3008: Unpinned apt packages
# DL3015: No --no-install-recommends, DL3059: Multiple consecutive RUN
ignore: DL3007,DL3008,DL3015,DL3059
trivy-fs:
name: Trivy Filesystem Scan
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Dependency vulnerability scan (informational)
uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0
with:
scan-type: 'fs'
scan-ref: '.'
severity: 'CRITICAL,HIGH'
exit-code: '0'
ignore-unfixed: true
format: 'table'
- name: IaC config scan (informational)
# Informational until pre-existing K8s security issues are addressed
uses: aquasecurity/trivy-action@ed142fd0673e97e23eac54620cfb913e5ce36c25 # v0.36.0
with:
scan-type: 'config'
scan-ref: '.'
severity: 'CRITICAL,HIGH,MEDIUM'
skip-dirs: 'operator/demos'
exit-code: '0'
format: 'table'
# ============================================================================
# Phase C: Advanced Security
# ============================================================================
codeql:
name: CodeQL Analysis (Go)
runs-on: ubuntu-latest
permissions:
security-events: write
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Initialize CodeQL
uses: github/codeql-action/init@cdf488f595d80d6e07e03d4674febd5ab45fa938 # v4
with:
languages: go
queries: security-extended
- name: Autobuild
uses: github/codeql-action/autobuild@cdf488f595d80d6e07e03d4674febd5ab45fa938 # v4
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@cdf488f595d80d6e07e03d4674febd5ab45fa938 # v4
with:
category: "/language:go"
action-pinning:
name: Verify Action Pinning
runs-on: ubuntu-latest
permissions:
contents: read
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Check for unpinned GitHub Actions
run: |
echo "=== Checking for unpinned GitHub Actions ==="
UNPINNED=$(grep -rh 'uses:' .github/workflows/ | grep -E 'uses:.*@' | grep -vE '@[0-9a-f]{40}' | sort -u || true)
if [ -n "$UNPINNED" ]; then
echo "::warning::Found actions not pinned to SHA commits:"
echo "$UNPINNED"
COUNT=$(echo "$UNPINNED" | wc -l | tr -d ' ')
echo "Total unpinned actions: $COUNT"
echo "NOTE: This check is informational."
else
echo "All actions are pinned to SHA commits!"
fi
exit 0