-
Notifications
You must be signed in to change notification settings - Fork 4
369 lines (324 loc) · 12.4 KB
/
build-containers.yml
File metadata and controls
369 lines (324 loc) · 12.4 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
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
name: Build, Scan & Test Containers
# Single workflow for container lifecycle on PRs:
# 1. Build custom images from the branch (once)
# 2. Scan images with Trivy + Grype
# 3. Test argus CLI using the built images
# 4. Post PR comment with aggregated results
#
# Images are built ONCE and shared via docker save/load artifacts.
# No triple-build. No masked failures.
on:
pull_request:
paths:
- 'docker/**'
- 'argus/**'
- 'argus.yml'
- '.github/workflows/build-containers.yml'
push:
branches: [main]
paths:
- 'docker/**'
- 'argus/**'
workflow_dispatch:
permissions:
contents: read
security-events: write
pull-requests: write
concurrency:
group: containers-${{ github.ref }}
cancel-in-progress: true
jobs:
# ── Step 1: Build all custom images ──────────────────────────────────
build:
name: Build Images
runs-on: ubuntu-latest
timeout-minutes: 15
strategy:
fail-fast: true
matrix:
include:
- image: scanner-bandit
dockerfile: docker/Dockerfile.bandit
- image: scanner-opengrep
dockerfile: docker/Dockerfile.opengrep
- image: scanner-supply-chain
dockerfile: docker/Dockerfile.supply-chain
- image: cli
dockerfile: docker/Dockerfile.cli
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Build image
run: |
docker build \
--tag "${IMAGE_REGISTRY}/${IMAGE_NAME}:${IMAGE_TAG}" \
--file "${DOCKERFILE}" \
--label "org.opencontainers.image.revision=${COMMIT_SHA}" \
.
env:
IMAGE_REGISTRY: ghcr.io/huntridge-labs/argus
IMAGE_NAME: ${{ matrix.image }}
IMAGE_TAG: ${{ github.sha }}
DOCKERFILE: ${{ matrix.dockerfile }}
COMMIT_SHA: ${{ github.sha }}
- name: Save image to artifact
run: |
docker save "${IMAGE_REGISTRY}/${IMAGE_NAME}:${IMAGE_TAG}" \
| gzip > "/tmp/${IMAGE_NAME}.tar.gz"
env:
IMAGE_REGISTRY: ghcr.io/huntridge-labs/argus
IMAGE_NAME: ${{ matrix.image }}
IMAGE_TAG: ${{ github.sha }}
- name: Upload image artifact
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7
with:
name: image-${{ matrix.image }}
path: /tmp/${{ matrix.image }}.tar.gz
retention-days: 1
# ── Step 2: Scan each image with Trivy + Grype ──────────────────────
scan:
name: Scan ${{ matrix.image }}
needs: [build]
runs-on: ubuntu-latest
timeout-minutes: 15
strategy:
fail-fast: false
matrix:
include:
- image: scanner-bandit
- image: scanner-opengrep
- image: scanner-supply-chain
- image: cli
steps:
- name: Download image artifact
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4
with:
name: image-${{ matrix.image }}
path: /tmp
- name: Load image
run: |
gunzip -c "/tmp/${IMAGE_NAME}.tar.gz" | docker load
env:
IMAGE_NAME: ${{ matrix.image }}
- name: Checkout (for argus SDK)
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
- name: Set up Python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6
with:
python-version: '3.13'
- name: Install Argus SDK
run: |
pip install --quiet pyyaml
echo "PYTHONPATH=$GITHUB_WORKSPACE" >> "$GITHUB_ENV"
# Scan with ALL severities — perception is protection
- name: Scan with Trivy (SARIF)
uses: aquasecurity/trivy-action@57a97c7e7821a5776cebc9bb87c984fa69cba8f1 # 0.35.0
with:
image-ref: "ghcr.io/huntridge-labs/argus/${{ matrix.image }}:${{ github.sha }}"
format: 'sarif'
output: 'trivy-results.sarif'
- name: Upload Trivy SARIF
if: always()
uses: github/codeql-action/upload-sarif@c10b8064de6f491fea524254123dbe5e09572f13 # v4
with:
sarif_file: trivy-results.sarif
category: "container-${{ matrix.image }}"
continue-on-error: true
- name: Scan with Grype
uses: anchore/scan-action@e1165082ffb1fe366ebaf02d8526e7c4989ea9d2 # v7
with:
image: "ghcr.io/huntridge-labs/argus/${{ matrix.image }}:${{ github.sha }}"
fail-build: false
severity-cutoff: critical
- name: Scan with Trivy (JSON)
if: always()
uses: aquasecurity/trivy-action@57a97c7e7821a5776cebc9bb87c984fa69cba8f1 # 0.35.0
with:
image-ref: "ghcr.io/huntridge-labs/argus/${{ matrix.image }}:${{ github.sha }}"
format: 'json'
output: 'trivy-results.json'
# Use argus container scanner parser + container markdown reporter
- name: Generate report with Argus
if: always()
run: |
mkdir -p scanner-summaries
python3 << 'PYEOF'
import sys, os
sys.path.insert(0, os.environ.get("PYTHONPATH", "."))
from pathlib import Path
from argus.scanners.container import ContainerScanner
from argus.container.scanner import ContainerScanResult, ContainerScanSummary
from argus.reporters.container_markdown import ContainerMarkdownReporter
image_name = os.environ["IMAGE_NAME"]
image_tag = os.environ.get("IMAGE_TAG", "latest")
image_ref = f"ghcr.io/huntridge-labs/argus/{image_name}:{image_tag}"
trivy_json = Path("trivy-results.json")
scanner = ContainerScanner()
trivy_findings = scanner.parse_trivy_results(trivy_json) if trivy_json.exists() else []
result = ContainerScanResult(
name=image_name,
image_ref=image_ref,
trivy_findings=trivy_findings,
combined_findings=trivy_findings,
)
summary = ContainerScanSummary(results=[result])
reporter = ContainerMarkdownReporter()
reporter.report(summary, "scanner-summaries")
# Rename for per-image aggregation
src = Path("scanner-summaries/container-scan.md")
dst = Path(f"scanner-summaries/{image_name}.md")
if src.exists():
dst.write_text(src.read_text())
PYEOF
env:
IMAGE_NAME: ${{ matrix.image }}
IMAGE_TAG: ${{ github.sha }}
- name: Upload scan artifacts
if: always()
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7
with:
name: scanner-summary-container-${{ matrix.image }}
path: scanner-summaries/
retention-days: 7
# ── Step 3: Test argus CLI using built images ───────────────────────
test-cli:
name: Test Argus CLI
needs: [build]
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6
with:
python-version: '3.13'
- name: Install Argus
run: |
pip install --quiet pyyaml
echo "PYTHONPATH=$GITHUB_WORKSPACE" >> "$GITHUB_ENV"
# Load all custom images built in step 1
- name: Download all image artifacts
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4
with:
pattern: image-*
merge-multiple: true
path: /tmp/images
- name: Load and retag images
run: |
for tarball in /tmp/images/*.tar.gz; do
gunzip -c "$tarball" | docker load
done
# Retag from SHA to version tag that containers.py expects
for image in scanner-bandit scanner-opengrep scanner-supply-chain cli; do
SHA_TAG="ghcr.io/huntridge-labs/argus/${image}:${GITHUB_SHA}"
VERSION_TAG="ghcr.io/huntridge-labs/argus/${image}:1.0.0"
if docker image inspect "$SHA_TAG" > /dev/null 2>&1; then
docker tag "$SHA_TAG" "$VERSION_TAG"
fi
done
env:
GITHUB_SHA: ${{ github.sha }}
- name: Test scanner listing
run: |
OUTPUT=$(python -m argus scan --list)
echo "$OUTPUT"
for scanner in bandit clamav trivy-iac gitleaks osv checkov opengrep supply-chain zap container; do
echo "$OUTPUT" | grep -q "$scanner" || { echo "FAIL: $scanner not listed"; exit 1; }
done
- name: Run argus scan
run: |
set +e
python -m argus scan \
--config argus.yml \
--format terminal \
--format sarif \
--format json \
--output-dir ./cli-test-results \
--verbose
EXIT_CODE=$?
set -e
if [ "$EXIT_CODE" -eq 2 ]; then
echo "::error::Argus scan failed with error (exit code 2)"
exit 2
fi
echo "Scan completed with exit code $EXIT_CODE"
- name: Verify outputs
run: |
for f in cli-test-results/argus-results.json cli-test-results/argus-results.sarif; do
test -f "$f" || { echo "FAIL: $f not produced"; exit 1; }
done
- name: Validate SARIF
run: |
python3 -c "
import json
data = json.load(open('cli-test-results/argus-results.sarif'))
assert data.get('version') == '2.1.0', f'Bad SARIF version: {data.get(\"version\")}'
assert 'runs' in data, 'Missing runs'
print(f'SARIF valid: {len(data[\"runs\"])} run(s)')
"
- name: Validate JSON results
run: |
python3 -c "
import json
data = json.load(open('cli-test-results/argus-results.json'))
results = data.get('results', [])
assert len(results) > 0, 'No scanner results'
scanners = [r['scanner'] for r in results]
total = sum(len(r.get('findings', [])) for r in results)
print(f'Scanners: {scanners}')
print(f'Total findings: {total}')
"
- name: Upload test results
if: always()
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7
with:
name: argus-cli-test-results
path: cli-test-results/
retention-days: 7
# ── Step 4: Post PR comment using argus markdown + comment-pr action ─
comment-pr:
name: Container Scan Summary
if: always() && github.event_name == 'pull_request'
needs: [scan, test-cli]
runs-on: ubuntu-latest
steps:
- name: Checkout (for comment-pr action)
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
# Download the argus-generated markdown from each scan matrix job
- name: Download scanner summaries
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4
with:
pattern: scanner-summary-container-*
merge-multiple: true
path: scanner-summaries
- name: Download CLI test results
uses: actions/download-artifact@95815c38cf2ff2164869cbab79da8d1f422bc89e # v4
with:
name: argus-cli-test-results
path: cli-results
continue-on-error: true
# Combine per-image argus markdown reports into one file
- name: Combine scanner summaries
run: |
mkdir -p scanner-summaries
{
for md in scanner-summaries/*.md; do
[ -f "$md" ] && cat "$md" && echo ""
done
if [ -f "cli-results/argus-summary.md" ]; then
echo "---"
echo ""
cat cli-results/argus-summary.md
fi
} > scanner-summaries/combined-container-scan.md
# Post using the existing comment-pr composite action
- name: Comment PR with scan results
uses: ./.github/actions/comment-pr
with:
summary_file: scanner-summaries/combined-container-scan.md
comment_marker: argus-container-scan
title: '🔒 Argus Container Security Scan'
fallback_message: 'No container scan results available'