-
Notifications
You must be signed in to change notification settings - Fork 3
1400 lines (1262 loc) · 67 KB
/
Copy pathbuild.yaml
File metadata and controls
1400 lines (1262 loc) · 67 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
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Copyright (c) 2025 Erick Bourgeois, firestoned
# SPDX-License-Identifier: Apache-2.0
name: Build
on:
pull_request:
branches:
- main
paths:
- 'src/**'
- 'Cargo.toml'
- 'Cargo.lock'
- 'Dockerfile*'
- '.github/workflows/build.yaml'
- '.github/actions/**'
- '.vex/**'
push:
branches:
- main
release:
types:
- published
# Top-level GITHUB_TOKEN is read-only by default (OpenSSF Scorecard
# Token-Permissions rule). Jobs that need elevated scopes — id-token:write
# for keyless Cosign / Sigstore, security-events:write for SARIF upload to
# Code Scanning, packages:write for GHCR push, attestations:write for
# actions/attest-build-provenance, contents:write for release-asset upload
# — declare them explicitly at job level. See the docker / attest /
# build-vex / iac-scan / grype / sign-artifacts / slsa-provenance /
# upload-release-assets jobs below. (Semgrep SAST runs from sast.yaml.)
permissions:
contents: read
env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1
# Override the cross-compilation linkers set in .cargo/config.toml.
# config.toml specifies the Homebrew cross-compilers needed when a macOS
# developer runs `cargo build --target x86_64-unknown-linux-gnu` locally.
# On Linux CI runners the native target IS x86_64/aarch64-unknown-linux-gnu,
# so cargo would try to invoke those cross-compilers — which are not
# installed. Setting these vars to `cc` restores the default system linker.
CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER: cc
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: cc
jobs:
# ─────────────────────────────────────────────────────────────────────────────
# License headers — always runs (PRs are pre-filtered by path at the trigger).
# ─────────────────────────────────────────────────────────────────────────────
license-check:
name: ⚖️ Verify SPDX License Headers
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- name: Check license headers
uses: firestoned/github-actions/security/license-check@53b483254bc648903c364ee3c73a546d0936a91e # v1.3.6
with:
copyright-holder: "Erick Bourgeois, firestoned"
license-id: "Apache-2.0"
# ─────────────────────────────────────────────────────────────────────────────
# Commit signatures — verify-mode differs by event type.
# ─────────────────────────────────────────────────────────────────────────────
verify-commits:
name: 🔐 Verify Signed Commits
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
with:
fetch-depth: 0
- name: Verify commits (PR)
if: github.event_name == 'pull_request'
uses: firestoned/github-actions/security/verify-signed-commits@53b483254bc648903c364ee3c73a546d0936a91e # v1.3.6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
base-ref: origin/${{ github.base_ref }}
verify-mode: pr
- name: Verify commits (push to main)
if: github.event_name == 'push'
uses: firestoned/github-actions/security/verify-signed-commits@53b483254bc648903c364ee3c73a546d0936a91e # v1.3.6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
verify-mode: push
- name: Verify commits (release)
if: github.event_name == 'release'
uses: firestoned/github-actions/security/verify-signed-commits@53b483254bc648903c364ee3c73a546d0936a91e # v1.3.6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
verify-mode: release
# ─────────────────────────────────────────────────────────────────────────────
# PR only: formatting + clippy.
# ─────────────────────────────────────────────────────────────────────────────
format:
name: 🎨 Check Formatting
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
needs: [license-check, verify-commits]
steps:
- name: Checkout code
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8 # stable (moving ref — re-pin quarterly)
with:
components: rustfmt
- name: Check formatting
run: cargo fmt -- --check
clippy:
name: 📎 Clippy
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
needs: [format]
steps:
- name: Checkout code
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8 # stable (moving ref — re-pin quarterly)
with:
components: clippy
- name: Cache cargo dependencies
uses: firestoned/github-actions/rust/cache-cargo@53b483254bc648903c364ee3c73a546d0936a91e # v1.3.6
- name: Run clippy
run: cargo clippy --all-targets --all-features -- -D warnings
# ─────────────────────────────────────────────────────────────────────────────
# VEX parse gate — PR only.
# Every .vex/<id>.json is a single-statement OpenVEX document (the native
# OpenVEX shape). vexctl merge parses each one as input; any malformed file
# fails the merge, giving us free schema + enum + structural validation
# from upstream tooling. No custom validator to maintain.
# ─────────────────────────────────────────────────────────────────────────────
validate-vex:
name: 🧾 Validate VEX Statements
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
needs: [verify-commits]
steps:
- name: Checkout code
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- name: Install vexctl
run: make vexctl-install
- name: Parse every .vex/*.json via vexctl merge
run: make vex-validate
# ─────────────────────────────────────────────────────────────────────────────
# Auto-VEX pre-submission gate — PR + push (ADR 0008).
# The auto-VEX suppressions must be generated, reviewed, and signed off
# (committed) BEFORE submission. This job regenerates .vex/auto/* from the
# frozen .vex/snapshot/ with pinned @id/author/timestamp and byte-exact diffs
# the result against the committed output. A mismatch hard-fails the build:
# the contributor must run `make vex-auto`, review the suppressions, and commit.
# This is the upstream human checkpoint; the Security team's release-time
# counter-signature (see docs/src/security/vex.md) remains the downstream net.
# ─────────────────────────────────────────────────────────────────────────────
validate-autovex:
name: 🔏 Validate Auto-VEX Sign-off
if: github.event_name == 'pull_request' || github.event_name == 'push'
runs-on: ubuntu-latest
needs: [verify-commits]
steps:
- name: Checkout code
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8 # stable (moving ref — re-pin quarterly)
- name: Cache cargo dependencies
uses: firestoned/github-actions/rust/cache-cargo@53b483254bc648903c364ee3c73a546d0936a91e # v1.3.6
# Regenerate .vex/auto/* from the committed .vex/snapshot/ and fail if the
# committed output is stale. Output is byte-deterministic (pinned
# @id/author/timestamp + CVE-sorted generators), so a plain git diff is the
# whole gate.
- name: Verify committed auto-VEX matches a fresh regeneration
run: make vex-auto-check
# ─────────────────────────────────────────────────────────────────────────────
# Extract version — all events; downstream build jobs depend on this.
# format/clippy are independent PR quality checks and do not gate the build.
# ─────────────────────────────────────────────────────────────────────────────
extract-version:
name: 🏷️ Extract Version Information
runs-on: ubuntu-latest
needs: [license-check, verify-commits]
outputs:
version: ${{ steps.version-chainguard.outputs.version }}
tag_name: ${{ steps.version-chainguard.outputs.tag-name }}
image-tag-chainguard: ${{ steps.version-chainguard.outputs.image-tag }}
image-tag-distroless: ${{ steps.version-distroless.outputs.image-tag }}
image-repository-chainguard: ${{ steps.version-chainguard.outputs.image-repository }}
image-repository-distroless: ${{ steps.version-distroless.outputs.image-repository }}
short-sha: ${{ steps.version-chainguard.outputs.short-sha }}
steps:
- name: Checkout code
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- name: Extract version for Chainguard
id: version-chainguard
uses: ./.github/actions/extract-version
with:
repository: ${{ github.repository }}
workflow-type: ${{ github.event_name == 'pull_request' && 'pr' || github.event_name == 'push' && 'main' || 'release' }}
pr-number: ${{ github.event.pull_request.number }}
release-tag: ${{ github.event.release.tag_name }}
image-tag-suffix: ""
- name: Extract version for Distroless
id: version-distroless
uses: ./.github/actions/extract-version
with:
repository: ${{ github.repository }}
workflow-type: ${{ github.event_name == 'pull_request' && 'pr' || github.event_name == 'push' && 'main' || 'release' }}
pr-number: ${{ github.event.pull_request.number }}
release-tag: ${{ github.event.release.tag_name }}
image-tag-suffix: "-distroless"
# ─────────────────────────────────────────────────────────────────────────────
# Build binary — all events.
# On release the Cargo.toml version is bumped to match the release tag.
# ─────────────────────────────────────────────────────────────────────────────
build:
name: 🦀 Build - ${{ matrix.platform.name }}
runs-on: ${{ matrix.platform.runner }}
needs: [extract-version]
strategy:
fail-fast: false
matrix:
platform:
- name: Linux x86_64
runner: ubuntu-24.04
artifact_name: 5spot-linux-amd64
binary_name: 5spot
- name: Linux ARM64
runner: ubuntu-24.04-arm
artifact_name: 5spot-linux-arm64
binary_name: 5spot
steps:
- name: Checkout code
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- name: Update Cargo.toml version
if: github.event_name == 'release'
run: |
perl -i -pe 's/^version = ".*"/version = "${{ needs.extract-version.outputs.version }}"/' Cargo.toml
echo "Updated Cargo.toml to version ${{ needs.extract-version.outputs.version }}"
grep '^version = ' Cargo.toml
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8 # stable (moving ref — re-pin quarterly)
- name: Cache cargo dependencies
uses: firestoned/github-actions/rust/cache-cargo@53b483254bc648903c364ee3c73a546d0936a91e # v1.3.6
- name: Build binary
run: cargo build --release
- name: Install cargo-cyclonedx
run: cargo install cargo-cyclonedx --locked --quiet
- name: Generate SBOM
run: |
cargo cyclonedx --format json
find . -maxdepth 1 -name "*.cdx.json" -exec mv {} target/release/ \;
# PR and push artifacts expire after 1 day — they are not release assets.
- name: Upload artifacts (PR / push)
if: github.event_name != 'release'
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: ${{ matrix.platform.artifact_name }}
path: |
target/release/${{ matrix.platform.binary_name }}
target/release/*.cdx.json
retention-days: 1
# Release artifacts keep the default retention so re-runs remain possible.
- name: Upload artifacts (release)
if: github.event_name == 'release'
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: ${{ matrix.platform.artifact_name }}
path: |
target/release/${{ matrix.platform.binary_name }}
target/release/*.cdx.json
# ─────────────────────────────────────────────────────────────────────────────
# Tests — all events; running unconditionally lets docker depend on it simply.
# ─────────────────────────────────────────────────────────────────────────────
test:
name: 🧪 Test
runs-on: ubuntu-latest
needs: [build]
steps:
- name: Checkout code
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8 # stable (moving ref — re-pin quarterly)
- name: Download x86_64 build artifact
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: 5spot-linux-amd64
path: target/release/
- name: Cache cargo dependencies
uses: firestoned/github-actions/rust/cache-cargo@53b483254bc648903c364ee3c73a546d0936a91e # v1.3.6
- name: Run tests
run: cargo test --all --verbose
# ─────────────────────────────────────────────────────────────────────────────
# Docker build and push — all events.
#
# Metadata tags vary by event (three separate metadata steps, only one runs
# per invocation; empty outputs from skipped steps are filtered out by
# docker/build-push-action). On release, Cosign signing and SBOM generation
# steps are also enabled.
# ─────────────────────────────────────────────────────────────────────────────
docker:
name: 🐳 Build and Push Docker Image - ${{ matrix.variant.name }}
runs-on: ubuntu-latest
needs: [build, extract-version, test]
permissions:
contents: read
packages: write
id-token: write
outputs:
digest-chainguard: ${{ steps.export-digest.outputs.digest-chainguard }}
digest-distroless: ${{ steps.export-digest.outputs.digest-distroless }}
strategy:
fail-fast: false
matrix:
variant:
- name: Chainguard
dockerfile: Dockerfile.chainguard
suffix: ""
description: "5-Spot Chainguard Zero-CVE (glibc, FIPS-ready)"
image-tag: ${{ needs.extract-version.outputs.image-tag-chainguard }}
image-repository: ${{ needs.extract-version.outputs.image-repository-chainguard }}
- name: Distroless
dockerfile: Dockerfile
suffix: "-distroless"
description: "5-Spot Google Distroless (glibc)"
image-tag: ${{ needs.extract-version.outputs.image-tag-distroless }}
image-repository: ${{ needs.extract-version.outputs.image-repository-distroless }}
steps:
- name: Checkout code
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- name: Prepare Docker binaries
uses: ./.github/actions/prepare-docker-binaries
- name: Setup Docker environment
uses: firestoned/github-actions/docker/setup-docker@53b483254bc648903c364ee3c73a546d0936a91e # v1.3.6
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
# Only one of the three metadata steps below runs per job instance.
# docker/build-push-action concatenates all tags/labels outputs and
# silently drops the empty lines produced by the two skipped steps.
- name: Extract metadata (PR)
id: meta-pr
if: github.event_name == 'pull_request'
uses: docker/metadata-action@80c7e94dd9b9319bd5eb7a0e0fe9291e23a2a2e9 # v6.1.0
with:
images: ghcr.io/${{ matrix.variant.image-repository }}
tags: |
type=raw,value=${{ matrix.variant.image-tag }}
type=raw,value=sha-${{ needs.extract-version.outputs.short-sha }}
flavor: |
latest=false
- name: Extract metadata (push to main)
id: meta-main
if: github.event_name == 'push'
uses: docker/metadata-action@80c7e94dd9b9319bd5eb7a0e0fe9291e23a2a2e9 # v6.1.0
with:
images: ghcr.io/${{ matrix.variant.image-repository }}
tags: |
type=raw,value=${{ matrix.variant.image-tag }}
type=raw,value=main-{{date 'YYYY-MM-DD'}}
type=raw,value=sha-${{ needs.extract-version.outputs.short-sha }}
type=raw,value=latest
flavor: |
latest=false
- name: Extract metadata (release)
id: meta-release
if: github.event_name == 'release'
uses: docker/metadata-action@80c7e94dd9b9319bd5eb7a0e0fe9291e23a2a2e9 # v6.1.0
with:
images: ghcr.io/${{ matrix.variant.image-repository }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=raw,value=sha-${{ needs.extract-version.outputs.short-sha }}${{ matrix.variant.suffix }}
flavor: |
latest=false
prefix=v
suffix=${{ matrix.variant.suffix }}
- name: Build and push Docker image (${{ matrix.variant.name }})
id: docker_build
uses: docker/build-push-action@f9f3042f7e2789586610d6e8b85c8f03e5195baf # v7.2.0
with:
context: .
file: ${{ matrix.variant.dockerfile }}
platforms: linux/amd64,linux/arm64
push: true
tags: |
${{ steps.meta-pr.outputs.tags }}
${{ steps.meta-main.outputs.tags }}
${{ steps.meta-release.outputs.tags }}
labels: |
${{ steps.meta-pr.outputs.labels }}
${{ steps.meta-main.outputs.labels }}
${{ steps.meta-release.outputs.labels }}
org.opencontainers.image.description=${{ matrix.variant.description }}
build-args: |
${{ github.event_name == 'release' && format('VERSION={0}', needs.extract-version.outputs.version) || '' }}
cache-from: type=gha,scope=${{ matrix.variant.name }}
cache-to: type=gha,mode=max,scope=${{ matrix.variant.name }}
sbom: true
provenance: true
# Push to main and release: sign the image with Cosign (keyless, Sigstore).
# PR images are ephemeral and not deployed, so signing them is skipped.
# Sign by digest (not tag) to guarantee we sign exactly what was pushed.
- name: Install Cosign
if: github.event_name != 'pull_request'
uses: sigstore/cosign-installer@6f9f17788090df1f26f669e9d70d6ae9567deba6 # v4.1.2
- name: Sign container image with Cosign
if: github.event_name != 'pull_request'
run: |
cosign sign --yes \
ghcr.io/${{ matrix.variant.image-repository }}@${{ steps.docker_build.outputs.digest }}
# Push + release: generate a CycloneDX SBOM for the published image.
# Needed on push (not just release) because auto-vex-presence
# (roadmap Phase 2) uses it to decide whether a Grype finding's purl
# is actually present in the product.
- name: Generate Docker SBOM for ${{ matrix.variant.name }}
if: github.event_name != 'pull_request'
uses: anchore/sbom-action@e22c389904149dbc22b58101806040fa8d37a610 # v0.24.0
with:
image: ghcr.io/${{ matrix.variant.image-repository }}:${{ matrix.variant.image-tag }}
format: cyclonedx-json
output-file: docker-sbom-${{ matrix.variant.name }}.json
upload-release-assets: false
- name: Upload Docker SBOM as artifact
if: github.event_name != 'pull_request'
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: docker-sbom-${{ matrix.variant.name }}
path: docker-sbom-${{ matrix.variant.name }}.json
- name: Export image digest
id: export-digest
run: |
case "${{ matrix.variant.name }}" in
Chainguard) echo "digest-chainguard=${{ steps.docker_build.outputs.digest }}" >> "$GITHUB_OUTPUT" ;;
Distroless) echo "digest-distroless=${{ steps.docker_build.outputs.digest }}" >> "$GITHUB_OUTPUT" ;;
esac
# ─────────────────────────────────────────────────────────────────────────────
# GitHub Artifact Attestation — all events.
# ─────────────────────────────────────────────────────────────────────────────
attest:
name: 🔏 Attest Docker Image - ${{ matrix.variant.name }}
runs-on: ubuntu-latest
needs: [docker, extract-version]
permissions:
id-token: write
attestations: write
packages: write
strategy:
fail-fast: false
matrix:
variant:
- name: Chainguard
image-repository: ${{ needs.extract-version.outputs.image-repository-chainguard }}
digest: ${{ needs.docker.outputs.digest-chainguard }}
- name: Distroless
image-repository: ${{ needs.extract-version.outputs.image-repository-distroless }}
digest: ${{ needs.docker.outputs.digest-distroless }}
steps:
- name: Log in to GHCR
uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4.2.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Attest ${{ matrix.variant.name }} image provenance
uses: actions/attest-build-provenance@a2bbfa25375fe432b6a289bc6b6cd05ecd0c4c32 # v4.1.0
with:
subject-name: ghcr.io/${{ matrix.variant.image-repository }}
subject-digest: ${{ matrix.variant.digest }}
push-to-registry: true
# ─────────────────────────────────────────────────────────────────────────────
# Grype triage scan — push + release.
# Runs Grype against each image variant WITHOUT VEX suppression and emits
# JSON (not SARIF). Its output feeds auto-vex-presence so we can see the
# raw set of CVEs before any suppression. The subsequent `grype` job
# (after build-vex) still runs with the final VEX for SARIF upload to
# Code Scanning. Two passes; costs ~30 s per variant; keeps the
# dependency graph acyclic (presence-check needs grype output; final
# grype needs the VEX that includes the presence-check output).
# ─────────────────────────────────────────────────────────────────────────────
grype-triage:
name: 🔭 Grype Triage Scan - ${{ matrix.variant.name }}
if: github.event_name != 'pull_request'
runs-on: ubuntu-latest
needs: [docker, extract-version]
permissions:
contents: read
packages: read
strategy:
fail-fast: false
matrix:
variant:
- name: Chainguard
image-tag: ${{ needs.extract-version.outputs.image-tag-chainguard }}
image-repository: ${{ needs.extract-version.outputs.image-repository-chainguard }}
- name: Distroless
image-tag: ${{ needs.extract-version.outputs.image-tag-distroless }}
image-repository: ${{ needs.extract-version.outputs.image-repository-distroless }}
steps:
- name: Log in to GHCR
uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4.2.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Pinned version matches the later grype job. Bump both together.
- name: Install Grype
env:
GRYPE_VERSION: '0.87.0'
run: |
set -euo pipefail
url="https://github.com/anchore/grype/releases/download/v${GRYPE_VERSION}/grype_${GRYPE_VERSION}_linux_amd64.tar.gz"
curl -fsSLo grype.tgz "$url"
tar -xzf grype.tgz grype
sudo install -m 0755 grype /usr/local/bin/grype
grype version
- name: Run Grype triage (no VEX)
env:
IMAGE_REF: ghcr.io/${{ matrix.variant.image-repository }}:${{ matrix.variant.image-tag }}
run: |
grype "$IMAGE_REF" \
--output json \
--file grype-triage-${{ matrix.variant.name }}.json
- name: Upload triage artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: grype-triage-${{ matrix.variant.name }}
path: grype-triage-${{ matrix.variant.name }}.json
if-no-files-found: error
# ─────────────────────────────────────────────────────────────────────────────
# Auto-VEX (presence-based) — push + release. Roadmap Phase 2.
#
# For each Grype triage finding whose affected purl is absent from every
# image SBOM and whose CVE id is not already covered by a hand-authored
# .vex/*.json statement, emit a `not_affected + component_not_present`
# OpenVEX statement. The result is uploaded as the `vex-auto-presence`
# artifact and is also merged unconditionally into the signed VEX
# document by `build-vex`. Verification is downstream (Security team
# counter-signs after their own re-evaluation); our side emits
# aggressively.
# ─────────────────────────────────────────────────────────────────────────────
auto-vex-presence:
name: 🤖 Auto-VEX (presence)
if: github.event_name != 'pull_request'
runs-on: ubuntu-latest
needs: [docker, extract-version, grype-triage]
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8 # stable (moving ref — re-pin quarterly)
- name: Cache cargo dependencies
uses: firestoned/github-actions/rust/cache-cargo@53b483254bc648903c364ee3c73a546d0936a91e # v1.3.6
- name: Build auto-vex-presence
run: cargo build --release --bin auto-vex-presence
- name: Download triage scan artifacts
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
pattern: grype-triage-*
path: ./triage
merge-multiple: true
- name: Download Docker SBOM artifacts
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
pattern: docker-sbom-*
path: ./sboms
merge-multiple: true
# One auto-presence document per image variant, then merged at the
# end. We keep variants separate because Grype's triage scan is
# per-image and we want each statement's `products` to correctly
# scope to the image it was derived from. For simplicity in Phase 2,
# both variants use the same `pkg:oci/5-spot` product purl (matching
# the existing hand-authored statements).
- name: Run auto-vex-presence
run: |
set -euo pipefail
vex_id="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}/auto-vex-presence"
ts="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
per_variant=()
for variant in Chainguard Distroless; do
triage="triage/grype-triage-${variant}.json"
sbom="sboms/docker-sbom-${variant}.json"
if [ ! -f "$triage" ] || [ ! -f "$sbom" ]; then
echo "missing $triage or $sbom; skipping variant $variant"
continue
fi
out="vex.auto-presence-${variant}.json"
./target/release/auto-vex-presence \
--grype-json "$triage" \
--sbom "$sbom" \
--vex-dir .vex \
--product-purl "pkg:oci/5-spot" \
--id "${vex_id}/${variant}" \
--author "auto-vex-presence" \
--timestamp "$ts" \
--output "$out"
per_variant+=("$out")
done
if [ ${#per_variant[@]} -eq 0 ]; then
echo "ERROR: no variant produced an auto-presence document"
exit 1
fi
- name: Merge per-variant auto-presence documents
run: |
make vexctl-install
vexctl merge \
--id "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}/auto-vex-presence" \
--author "auto-vex-presence" \
vex.auto-presence-*.json > vex.auto-presence.json
echo "── vex.auto-presence.json ─────────────────────────────────────────"
cat vex.auto-presence.json
- name: Upload auto-presence artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: vex-auto-presence
path: vex.auto-presence.json
if-no-files-found: error
# ─────────────────────────────────────────────────────────────────────────────
# Auto-VEX (symbol-import reachability) — push + release. Roadmap Phase 3.
#
# For each Grype triage finding whose CVE id maps to a list of
# affected library function names in `.vex/.affected-functions.json`,
# check whether the release binary's dynamic symbol-import table
# contains any of those names. If none → emit a `not_affected +
# vulnerable_code_not_in_execute_path` statement. The result is
# uploaded as the `vex-auto-reachability` artifact and merged
# unconditionally into the signed VEX document by `build-vex`.
#
# Why "symbol-import reachability" instead of full LLVM-IR call graph:
# cargo audit reports zero open Rust-level vulnerabilities for this
# codebase; every CVE we triage is a base-image glibc/zlib finding
# surfaced by Grype. Those CVEs are not tracked in RustSec, so the
# original roadmap's RustSec-affected-functions approach addresses
# zero current findings. Symbol-import absence is the mechanical
# equivalent for our actual data: if our Rust binary doesn't link
# against `glob`/`scanf`/`iconv`, the affected glibc code paths
# cannot be reached through documented entry points.
# ─────────────────────────────────────────────────────────────────────────────
auto-vex-reachability:
name: 🤖 Auto-VEX (reachability)
if: github.event_name != 'pull_request'
runs-on: ubuntu-latest
needs: [build, extract-version, grype-triage]
permissions:
contents: read
steps:
- name: Checkout code
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8 # stable (moving ref — re-pin quarterly)
- name: Cache cargo dependencies
uses: firestoned/github-actions/rust/cache-cargo@53b483254bc648903c364ee3c73a546d0936a91e # v1.3.6
- name: Build auto-vex-reachability
run: cargo build --release --bin auto-vex-reachability
- name: Download release binary (5spot-linux-amd64)
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: 5spot-linux-amd64
path: ./bin
- name: Download triage scan artifacts
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
pattern: grype-triage-*
path: ./triage
merge-multiple: true
# Capture the binary's dynamic symbol-import table. This is the
# ELF view; on Linux runners we can use nm -D --undefined-only
# directly. The output becomes the evidence the Security team
# re-derives downstream during counter-signing.
- name: Capture binary symbol imports
run: |
set -euo pipefail
chmod +x bin/5spot
nm -D --undefined-only bin/5spot > symbols.txt
echo "── imported symbol count ──"
wc -l symbols.txt
echo "── first 20 symbols ──"
head -20 symbols.txt
# Run once per variant (binary symbols are identical across
# variants but Grype findings differ), merge per-variant outputs
# at the end.
- name: Run auto-vex-reachability
run: |
set -euo pipefail
vex_id="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}/auto-vex-reachability"
ts="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
per_variant=()
for variant in Chainguard Distroless; do
triage="triage/grype-triage-${variant}.json"
if [ ! -f "$triage" ]; then
echo "missing $triage; skipping variant $variant"
continue
fi
out="vex.auto-reachability-${variant}.json"
./target/release/auto-vex-reachability \
--grype-json "$triage" \
--binary-symbols symbols.txt \
--affected-functions .vex/.affected-functions.json \
--vex-dir .vex \
--product-purl "pkg:oci/5-spot" \
--id "${vex_id}/${variant}" \
--author "auto-vex-reachability" \
--timestamp "$ts" \
--output "$out"
per_variant+=("$out")
done
if [ ${#per_variant[@]} -eq 0 ]; then
echo "ERROR: no variant produced an auto-reachability document"
exit 1
fi
- name: Merge per-variant auto-reachability documents
run: |
make vexctl-install
vexctl merge \
--id "https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}/auto-vex-reachability" \
--author "auto-vex-reachability" \
vex.auto-reachability-*.json > vex.auto-reachability.json
echo "── vex.auto-reachability.json ─────────────────────────────────"
cat vex.auto-reachability.json
- name: Upload auto-reachability artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: vex-auto-reachability
path: vex.auto-reachability.json
if-no-files-found: error
# The symbols.txt evidence is uploaded separately so the Security
# team can re-run the same reachability analysis against the
# release-attested binary digest and confirm the auto-emitted
# statements.
- name: Upload symbol-imports evidence
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: vex-auto-reachability-evidence
path: symbols.txt
if-no-files-found: error
# ─────────────────────────────────────────────────────────────────────────────
# VEX document — push to main + release.
#
# Reads hand-authored per-CVE triage from .vex/*.json (each file is a
# single-statement native OpenVEX document), merges them into a single
# document via `vexctl merge`, and (on push/release only) Cosign-attests
# it to both image digests. The `openvex` artifact is always uploaded so
# the `grype` container scan job can consume it via `--vex` and suppress
# already-triaged findings from GitHub Code Scanning. On release, the
# GitHub build-provenance bundle is also emitted and attached to the
# release.
#
# vexctl merge fails on any malformed input, so there's no separate
# validator step — a bad merge slipping past the PR gate would also fail
# the assembly here.
#
# Trust model: this job emits and Cosign-attests the VEX document. The
# auto-presence (Phase 2) and auto-reachability (Phase 3) artifacts are
# merged unconditionally alongside the hand-authored `.vex/*.json`
# statements. Verification of the resulting claims is performed
# downstream by the Security team, which independently re-evaluates the
# VEX against the attached evidence (SBOMs, symbol-imports,
# Cosign attestations, SLSA provenance) and counter-signs if they
# agree. There is no feature-flag gate on our side — automation is
# aggressive, verification is external.
# ─────────────────────────────────────────────────────────────────────────────
build-vex:
name: 🧾 Assemble OpenVEX
if: github.event_name != 'pull_request'
runs-on: ubuntu-latest
needs: [docker, extract-version, auto-vex-presence, auto-vex-reachability]
permissions:
contents: read
id-token: write
attestations: write
packages: write
steps:
- name: Checkout code
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- name: Install vexctl
run: make vexctl-install
- name: Download auto-presence artifact
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: vex-auto-presence
path: ./auto
- name: Download auto-reachability artifact
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: vex-auto-reachability
path: ./auto
# Canonical @id varies by event so downstream consumers can link back
# to the exact commit or release tag that produced the document.
# Both auto-* documents are merged alongside hand-authored
# statements on every build.
- name: Assemble OpenVEX document
id: assemble
run: |
set -euo pipefail
case "${{ github.event_name }}" in
release)
vex_id="https://github.com/${{ github.repository }}/releases/tag/${{ needs.extract-version.outputs.tag_name }}/vex"
;;
push)
vex_id="https://github.com/${{ github.repository }}/commit/${{ github.sha }}/vex"
;;
*)
vex_id="https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}/vex"
;;
esac
test -f auto/vex.auto-presence.json || { echo "ERROR: auto-presence artifact missing"; exit 1; }
test -f auto/vex.auto-reachability.json || { echo "ERROR: auto-reachability artifact missing"; exit 1; }
vexctl merge \
--id "$vex_id" \
--author "${{ github.event.release.author.login || github.actor }}" \
.vex/*.json auto/vex.auto-presence.json auto/vex.auto-reachability.json > vex.openvex.json
echo "── vex.openvex.json ─────────────────────────────────────────"
cat vex.openvex.json
# Always upload the assembled document so the `grype` scan job can
# download it via actions/download-artifact@v4 regardless of event.
- name: Upload OpenVEX document artifact
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: openvex
path: vex.openvex.json
if-no-files-found: error
- name: Install Cosign
uses: sigstore/cosign-installer@6f9f17788090df1f26f669e9d70d6ae9567deba6 # v4.1.2
- name: Log in to GHCR (for cosign attest)
uses: docker/login-action@650006c6eb7dba73a995cc03b0b2d7f5ca915bee # v4.2.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Cosign-attest the OpenVEX document to each image digest (keyless OIDC,
# writes to the Sigstore transparency log + registry). Runs on both
# main push and release so staging images have the same VEX posture
# as release images.
- name: Cosign attest OpenVEX to Chainguard image
run: |
cosign attest --yes \
--predicate vex.openvex.json \
--type openvex \
ghcr.io/${{ needs.extract-version.outputs.image-repository-chainguard }}@${{ needs.docker.outputs.digest-chainguard }}
- name: Cosign attest OpenVEX to Distroless image
run: |
cosign attest --yes \
--predicate vex.openvex.json \
--type openvex \
ghcr.io/${{ needs.extract-version.outputs.image-repository-distroless }}@${{ needs.docker.outputs.digest-distroless }}
# GitHub-native attestation parity with other release artifacts.
# Release-only because the bundle is attached as a release asset and
# the attestation links to the release tag.
- name: Attest OpenVEX build provenance
if: github.event_name == 'release'
uses: actions/attest-build-provenance@a2bbfa25375fe432b6a289bc6b6cd05ecd0c4c32 # v4.1.0
id: attest-vex
with:
subject-path: vex.openvex.json
# The attest-build-provenance action writes the sigstore bundle to a
# path exposed via its `bundle-path` output. Copy it next to the VEX
# document so the release-assets job can pick it up.
- name: Stage VEX bundle beside document
if: github.event_name == 'release'
run: |
set -euo pipefail
if [ -n "${{ steps.attest-vex.outputs.bundle-path }}" ]; then
cp "${{ steps.attest-vex.outputs.bundle-path }}" vex.openvex.json.bundle
fi
ls -lh vex.openvex.json.bundle
- name: Upload OpenVEX bundle artifact (release)
if: github.event_name == 'release'
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: openvex-bundle
path: vex.openvex.json.bundle
if-no-files-found: error
# ─────────────────────────────────────────────────────────────────────────────
# Security scan — all events.
# Gitleaks secret scan only runs on PRs; release uploads the audit report.
# ─────────────────────────────────────────────────────────────────────────────
security:
name: 🛡️ Security Vulnerability Scan
runs-on: ubuntu-latest
needs: [verify-commits]
steps:
- name: Checkout code
uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # v6.0.3
- name: Install Rust toolchain
uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8 # stable (moving ref — re-pin quarterly)
- name: Run security scan (PR / push)
if: github.event_name != 'release'
uses: firestoned/github-actions/rust/security-scan@53b483254bc648903c364ee3c73a546d0936a91e # v1.3.6
with:
cargo-audit-version: "0.22.0"
- name: Run security scan (release)
if: github.event_name == 'release'
uses: firestoned/github-actions/rust/security-scan@53b483254bc648903c364ee3c73a546d0936a91e # v1.3.6
with:
cargo-audit-version: "0.22.0"
upload-artifact-name: cargo-audit-report-release
- name: Run gitleaks (secret scanning)
if: github.event_name == 'pull_request'
run: make gitleaks
# Semgrep SAST moved to .github/workflows/sast.yaml so it runs on every
# PR and push with no `paths:` filter (Scorecard's SAST check records
# skipped commits as uncovered otherwise).
# ─────────────────────────────────────────────────────────────────────────────
# IaC security scan (Trivy config) — PR + push to main.