-
Notifications
You must be signed in to change notification settings - Fork 1
1582 lines (1471 loc) · 66.9 KB
/
Copy pathbuild.yml
File metadata and controls
1582 lines (1471 loc) · 66.9 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
name: bluebuild
on:
schedule:
- cron:
"00 06 * * *"
push:
branches: [main]
pull_request:
workflow_dispatch:
concurrency:
group: ${{ github.workflow }}-${{ github.ref || github.run_id }}
cancel-in-progress: true
jobs:
source-prep:
name: "Stage 1: Source Prep"
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
bundle_sha256: ${{ steps.package.outputs.bundle_sha256 }}
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c # v6.4.0
with:
go-version: "1.26.5"
cache: false
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: "3.12"
- name: Install pinned workflow dependencies
run: python -m pip install --require-hashes -r requirements-ci.lock
- name: Verify supported Fedora base pin
run: |
python3 - <<'PY'
import re
import yaml
with open("recipes/recipe.yml", encoding="utf-8") as handle:
recipe = yaml.safe_load(handle)
version = str(recipe.get("image-version", ""))
match = re.fullmatch(r"44@(sha256:[0-9a-f]{64})", version)
if not match:
raise SystemExit(
"recipes/recipe.yml must use Fedora 44 with a canonical digest pin"
)
print(f"Configured Fedora 44 base digest: {match.group(1)}")
PY
configured_digest=$(python3 -c '
import yaml
with open("recipes/recipe.yml", encoding="utf-8") as handle:
print(str(yaml.safe_load(handle)["image-version"]).split("@", 1)[1])
')
current_digest=$(
skopeo inspect docker://ghcr.io/ublue-os/silverblue-main:44 |
jq -er '.Digest'
)
if [ "$configured_digest" != "$current_digest" ]; then
echo "::error::Fedora 44 base tag moved. Review the new image and update the recipe digest."
echo "Configured: $configured_digest"
echo "Current: $current_digest"
exit 1
fi
- name: Verify Fedora 44 package availability
run: |
# The bootc base can exceed Docker's overlay-layer depth even though
# BlueBuild/Podman can consume it. Query the same Fedora 44 repos
# through a shallow, immutable official Fedora package-check image.
package_check_ref="docker.io/library/fedora:44@sha256:6c75d5bf57cb0fa5aa4b92c6a83c86c791644496d9ac230de7711f5b8ec3b898"
mapfile -t packages < <(
python3 - <<'PY'
import yaml
with open("recipes/recipe.yml", encoding="utf-8") as handle:
recipe = yaml.safe_load(handle)
for module in recipe.get("modules", []):
if module.get("type") == "rpm-ostree":
for package in module.get("install", []):
print(package)
PY
)
if [ "${#packages[@]}" -eq 0 ]; then
echo "::error::Recipe contains no RPM package requirements"
exit 1
fi
docker pull "$package_check_ref"
docker run --rm --entrypoint /bin/bash "$package_check_ref" \
-s -- "${packages[@]}" <<'BASH'
set -euo pipefail
dnf5 -q makecache --refresh
missing=0
for package in "$@"; do
if rpm -q --quiet -- "$package" ||
dnf5 -q repoquery --available "$package" | grep -q .; then
echo "OK: ${package}"
else
echo "MISSING: ${package}" >&2
missing=$((missing + 1))
fi
done
if [ "$missing" -ne 0 ]; then
echo "Fedora package resolution failed for ${missing} package(s)" >&2
exit 1
fi
BASH
- name: Materialize verified Go dependency trees
run: |
while IFS= read -r module; do
service_dir=$(dirname "$module")
echo "Vendoring ${service_dir}"
(
cd "$service_dir"
go mod verify
go mod vendor
)
done < <(find services -mindepth 2 -maxdepth 2 -name go.mod -print | sort)
- name: Materialize Python wheelhouse
run: |
mkdir -p vendor/wheels
find vendor/wheels -mindepth 1 -maxdepth 1 -type f -delete
python3 -m pip download \
--dest vendor/wheels \
--require-hashes \
--only-binary=:all: \
-r vendor/application-requirements.lock
(
cd vendor/wheels
find . -maxdepth 1 -type f -name '*.whl' -print0 |
sort -z |
xargs -0 sha256sum > SHA256SUMS
test -s SHA256SUMS
sha256sum --check --strict SHA256SUMS
)
- name: Fetch checksum-pinned external source
run: |
python3 - <<'PY'
import hashlib
import io
import pathlib
import posixpath
import shutil
import tarfile
import urllib.request
import yaml
with open(".upstreams.lock.yaml", encoding="utf-8") as handle:
lock = yaml.safe_load(handle)
for name, entry in sorted(lock.get("upstreams", {}).items()):
commit = str(entry["pinned_commit"])
expected = str(entry["archive_sha256"])
if len(commit) != 40 or len(expected) != 64:
raise SystemExit(f"{name}: invalid source pin")
url = entry["upstream_url"].removesuffix(".git")
archive_url = f"{url}/archive/{commit}.tar.gz"
print(f"Fetching {name}@{commit}")
with urllib.request.urlopen(archive_url, timeout=60) as response:
content = response.read()
actual = hashlib.sha256(content).hexdigest()
if actual != expected:
raise SystemExit(
f"{name}: archive mismatch: expected {expected}, got {actual}"
)
destination = pathlib.Path(entry["local_path"])
shutil.rmtree(destination, ignore_errors=True)
destination.mkdir(parents=True)
with tarfile.open(fileobj=io.BytesIO(content), mode="r:gz") as archive:
members = archive.getmembers()
if not members:
raise SystemExit(f"{name}: archive is empty")
root = members[0].name.split("/", 1)[0]
if not root or root in {".", ".."}:
raise SystemExit(f"{name}: malformed archive root")
prefix = root + "/"
for member in members:
if member.islnk():
raise SystemExit(f"{name}: archive contains a hard link")
if member.name == root:
if not member.isdir():
raise SystemExit(f"{name}: malformed archive root")
continue
if not member.name.startswith(prefix):
raise SystemExit(f"{name}: malformed archive root")
relative = pathlib.PurePosixPath(member.name.removeprefix(prefix))
if relative.is_absolute() or ".." in relative.parts:
raise SystemExit(f"{name}: unsafe archive path")
if member.issym():
link = pathlib.PurePosixPath(member.linkname)
resolved_link = pathlib.PurePosixPath(
posixpath.normpath((relative.parent / link).as_posix())
)
if (
link.is_absolute()
or not member.linkname
or resolved_link.is_absolute()
or ".." in resolved_link.parts
):
raise SystemExit(
f"{name}: archive contains an unsafe symbolic link"
)
member.name = relative.as_posix()
if member.name and member.name != ".":
archive.extract(member, destination, filter="data")
PY
- name: Freeze pinned SearXNG version metadata
run: |
python3 files/scripts/prepare-searxng-source.py \
--lock .upstreams.lock.yaml \
--source upstreams/searxng
- name: Download and verify llama.cpp tarball
run: |
mkdir -p .source-prep
# Read pinned version + checksum from build-services.sh
LLAMA_CPP_VERSION=$(grep -oP 'LLAMA_CPP_VERSION:-\K[^}]+' files/scripts/build-services.sh | head -1)
LLAMA_CPP_SHA256=$(grep -oP 'LLAMA_CPP_SHA256:-\K[^}]+' files/scripts/build-services.sh | head -1)
echo "Downloading llama.cpp ${LLAMA_CPP_VERSION}..."
TARBALL="llama-cpp-${LLAMA_CPP_VERSION}.tar.gz"
curl -fsSL -o "/tmp/${TARBALL}" \
"https://github.com/ggml-org/llama.cpp/archive/refs/tags/${LLAMA_CPP_VERSION}.tar.gz"
echo "Verifying checksum..."
ACTUAL=$(sha256sum "/tmp/${TARBALL}" | awk '{print $1}')
if [ "$ACTUAL" != "$LLAMA_CPP_SHA256" ]; then
echo "::error::llama.cpp checksum mismatch: expected ${LLAMA_CPP_SHA256}, got ${ACTUAL}"
echo "Update LLAMA_CPP_SHA256 in build-services.sh if the version was bumped."
exit 1
fi
echo "OK: llama.cpp checksum verified"
echo "TARBALL_SHA256=${ACTUAL}" >> "$GITHUB_ENV"
echo "LLAMA_CPP_VERSION=${LLAMA_CPP_VERSION}" >> "$GITHUB_ENV"
mv "/tmp/${TARBALL}" ".source-prep/llama-cpp-staged.tar.gz"
- name: Emit SOURCE_PREP_MANIFEST.json
run: |
python3 -c "
import json, hashlib, os
from pathlib import Path
from datetime import datetime, timezone
import yaml
def digest(path):
with open(path, 'rb') as handle:
return hashlib.sha256(handle.read()).hexdigest()
manifest = {
'schema_version': 1,
'timestamp': datetime.now(timezone.utc).isoformat(),
'commit_sha': os.environ.get('GITHUB_SHA', 'unknown'),
'llama_cpp_version': os.environ.get('LLAMA_CPP_VERSION', 'unknown'),
'llama_cpp_tarball_sha256': os.environ.get('TARBALL_SHA256', 'unknown'),
}
required_files = [
Path('vendor/wheels/SHA256SUMS'),
Path('vendor/application-requirements.lock'),
Path('.upstreams.lock.yaml'),
]
missing = [str(path) for path in required_files if not path.is_file()]
if missing:
raise SystemExit(f'missing source-prep inputs: {missing}')
wheel_lines = [
line for line in required_files[0].read_text().splitlines() if line.strip()
]
if not wheel_lines:
raise SystemExit('wheelhouse checksum manifest is empty')
manifest['wheelhouse_sha256sums_digest'] = digest(required_files[0])
manifest['application_requirements_lock_digest'] = digest(required_files[1])
manifest['upstreams_lock_digest'] = digest(required_files[2])
manifest['wheel_count'] = len(wheel_lines)
manifest['application_dependency_mode'] = 'staged-offline'
with required_files[2].open(encoding='utf-8') as handle:
upstream_lock = yaml.safe_load(handle)
manifest['upstream_paths'] = sorted(
str(entry['local_path'])
for entry in upstream_lock.get('upstreams', {}).values()
)
if not manifest['upstream_paths']:
raise SystemExit('upstream source lock contains no materialized paths')
manifest['go_vendor_paths'] = sorted(
path.as_posix()
for path in Path('services').glob('*/vendor')
if path.is_dir() and not path.is_symlink()
)
if not manifest['go_vendor_paths']:
raise SystemExit('source preparation produced no Go vendor trees')
with open('.source-prep/SOURCE_PREP_MANIFEST.json', 'w') as f:
json.dump(manifest, f, indent=2)
f.write('\n')
print('--- SOURCE_PREP_MANIFEST.json ---')
print(json.dumps(manifest, indent=2))
"
- name: Package verified source-prep inputs
id: package
shell: bash
run: |
set -euo pipefail
mapfile -d '' -t go_vendor_paths < <(
find services -mindepth 2 -maxdepth 2 -type d -name vendor -print0 |
sort -z
)
if [ "${#go_vendor_paths[@]}" -eq 0 ]; then
echo "::error::Source preparation produced no Go vendor trees"
exit 1
fi
archive_paths=(
.source-prep
.upstreams.lock.yaml
upstreams
vendor/wheels
"${go_vendor_paths[@]}"
)
for path in "${archive_paths[@]}"; do
if [ ! -e "$path" ] || [ -L "$path" ]; then
echo "::error::Unsafe or missing source-prep root: ${path}"
exit 1
fi
done
bundle_dir="${RUNNER_TEMP}/source-prep-bundle"
mkdir -p "$bundle_dir"
bundle_path="${bundle_dir}/source-prep.tar.gz"
printf '%s\0' "${archive_paths[@]}" |
tar \
--create \
--gzip \
--file "$bundle_path" \
--sort=name \
--mtime='UTC 1970-01-01' \
--owner=0 \
--group=0 \
--numeric-owner \
--hard-dereference \
--null \
--verbatim-files-from \
--files-from=-
test -s "$bundle_path"
tar --list --gzip --file "$bundle_path" >/dev/null
bundle_sha256=$(sha256sum "$bundle_path" | awk '{print $1}')
if ! [[ "$bundle_sha256" =~ ^[0-9a-f]{64}$ ]]; then
echo "::error::Unable to calculate the source-prep bundle digest"
exit 1
fi
printf '%s source-prep.tar.gz\n' "$bundle_sha256" > \
"${bundle_path}.sha256"
echo "bundle_sha256=${bundle_sha256}" >> "$GITHUB_OUTPUT"
- name: Upload staged artifacts
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: source-prep
path: |
${{ runner.temp }}/source-prep-bundle/source-prep.tar.gz
${{ runner.temp }}/source-prep-bundle/source-prep.tar.gz.sha256
if-no-files-found: error
compression-level: 0
retention-days: 1
bluebuild_pr:
name: "Stage 2: Build Custom Image (Unprivileged PR)"
if: github.event_name == 'pull_request'
needs: [source-prep]
runs-on: ubuntu-latest
permissions:
contents: read
strategy:
fail-fast: false
matrix:
recipe:
- recipe.yml
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: "3.12"
- name: Download verified source-prep inputs
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: source-prep
path: ${{ runner.temp }}/source-prep-download
- name: Verify and restore external source tree
env:
EXPECTED_SOURCE_PREP_SHA256: ${{ needs.source-prep.outputs.bundle_sha256 }}
SOURCE_PREP_ARCHIVE: ${{ runner.temp }}/source-prep-download/source-prep.tar.gz
SOURCE_PREP_CHECKSUM: ${{ runner.temp }}/source-prep-download/source-prep.tar.gz.sha256
run: >-
python3 .github/scripts/restore-source-prep.py
--archive "$SOURCE_PREP_ARCHIVE"
--checksum "$SOURCE_PREP_CHECKSUM"
- name: Build Custom Image Without Publishing
uses: blue-build/github-action@24d146df25adc2cf579e918efe2d9bff6adea408 # v1.11.1
with:
recipe: ${{ matrix.recipe }}
cli_version: v0.9.36
skip_checkout: true
verify_install: true
# The action declares this input required, but push=false never signs.
# Pass an explicit non-secret empty value to keep forked PRs isolated.
cosign_private_key: ""
push: false
registry_token: ""
pr_event_number: ${{ github.event.number }}
maximize_build_space: true
bluebuild_publish:
name: "Stage 2: Build, Sign, and Publish Custom Image"
if: github.event_name != 'pull_request'
needs: [source-prep]
runs-on: ubuntu-latest
environment: release
outputs:
digest: ${{ steps.digest.outputs.digest }}
pinned_ref: ${{ steps.digest.outputs.pinned_ref }}
image_ref: ${{ steps.digest.outputs.image_ref }}
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix:
recipe:
# BlueBuild resolves recipe paths relative to the recipes/ directory.
# "recipe.yml" maps to "recipes/recipe.yml" by convention.
- recipe.yml
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: "3.12"
- name: Download verified source-prep inputs
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: source-prep
path: ${{ runner.temp }}/source-prep-download
- name: Verify and restore external source tree
env:
EXPECTED_SOURCE_PREP_SHA256: ${{ needs.source-prep.outputs.bundle_sha256 }}
SOURCE_PREP_ARCHIVE: ${{ runner.temp }}/source-prep-download/source-prep.tar.gz
SOURCE_PREP_CHECKSUM: ${{ runner.temp }}/source-prep-download/source-prep.tar.gz.sha256
run: >-
python3 .github/scripts/restore-source-prep.py
--archive "$SOURCE_PREP_ARCHIVE"
--checksum "$SOURCE_PREP_CHECKSUM"
- name: Build Custom Image
id: build
uses: blue-build/github-action@24d146df25adc2cf579e918efe2d9bff6adea408 # v1.11.1
with:
recipe: ${{ matrix.recipe }}
cli_version: v0.9.36
skip_checkout: true
verify_install: true
cosign_private_key: ${{ secrets.SIGNING_SECRET }}
push: true
registry_token: ${{ github.token }}
pr_event_number: ${{ github.event.number }}
maximize_build_space: true
- name: Set lowercase image ref
if: github.event_name != 'pull_request'
run: echo "IMAGE_REF=ghcr.io/${GITHUB_REPOSITORY,,}" >> "$GITHUB_ENV"
# Publish the image digest so users can pin installs to an exact build.
# The digest appears in the workflow summary and as an artifact.
- name: Resolve and verify the built image
if: github.event_name != 'pull_request'
id: digest
run: |
inspect_json=$(skopeo inspect "docker://${IMAGE_REF}:latest")
digest=$(jq -er '.Digest' <<<"$inspect_json")
revision=$(jq -er '.Labels["org.opencontainers.image.revision"]' <<<"$inspect_json")
if ! [[ "$digest" =~ ^sha256:[0-9a-f]{64}$ ]]; then
echo "::error::Registry returned a non-canonical image digest"
exit 1
fi
if [ "$revision" != "$GITHUB_SHA" ]; then
echo "::error::The published image was built from ${revision}, not ${GITHUB_SHA}"
exit 1
fi
pinned_ref="${IMAGE_REF}@${digest}"
cosign verify --key cosign.pub "$pinned_ref" >/dev/null
echo "$digest" > IMAGE_DIGEST
echo "$pinned_ref" > IMAGE_REF_PINNED
{
echo "digest=$digest"
echo "pinned_ref=$pinned_ref"
echo "image_ref=$IMAGE_REF"
} >> "$GITHUB_OUTPUT"
{
echo "## Verified image"
echo ""
echo "Source commit: \`${GITHUB_SHA}\`"
echo "Pinned image: \`${pinned_ref}\`"
} >> "$GITHUB_STEP_SUMMARY"
release_evidence:
name: "Stage 3: Release Evidence and Attestations"
if: github.event_name != 'pull_request'
needs: [bluebuild_publish]
runs-on: ubuntu-latest
timeout-minutes: 120
environment: release
permissions:
contents: read
packages: write
id-token: write
attestations: write
artifact-metadata: write
steps:
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
- name: Reserve disk for rootless OCI materialization
run: |
set -euo pipefail
# This isolated job reinstalls Python and does not use these hosted SDKs.
cleanup_threshold_kib=$((40 * 1024 * 1024))
available_kib=$(df --output=avail -k / | tail -n 1)
if [ "$available_kib" -lt "$cleanup_threshold_kib" ]; then
sudo rm -rf -- \
/opt/ghc \
/opt/hostedtoolcache/CodeQL \
/opt/hostedtoolcache/PyPy \
/opt/hostedtoolcache/Python \
/opt/hostedtoolcache/Ruby \
/opt/hostedtoolcache/go \
/opt/hostedtoolcache/node \
/usr/lib/jvm \
/usr/local/.ghcup \
/usr/local/lib/android \
/usr/share/dotnet \
/usr/share/miniconda \
/usr/share/swift
fi
df -h /
- uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0
with:
python-version: "3.12"
- name: Install pinned cosign
uses: sigstore/cosign-installer@6f9f17788090df1f26f669e9d70d6ae9567deba6 # v4.1.2
with:
cosign-release: v3.1.1
- name: Authenticate to the image registry
env:
REGISTRY_PASSWORD: ${{ github.token }}
run: |
set -euo pipefail
registry_config_dir="${RUNNER_TEMP}/secai-registry-auth"
if [ -e "$registry_config_dir" ] || [ -L "$registry_config_dir" ]; then
echo "::error::Refusing to reuse the registry credential directory" >&2
exit 1
fi
install -d -m 0700 "$registry_config_dir"
printf '%s' "$REGISTRY_PASSWORD" |
docker --config "$registry_config_dir" login ghcr.io \
--username "$GITHUB_ACTOR" --password-stdin
chmod 0600 "$registry_config_dir/config.json"
{
echo "DOCKER_CONFIG=${registry_config_dir}"
echo "REGISTRY_AUTH_FILE=${registry_config_dir}/config.json"
} >> "$GITHUB_ENV"
- name: Reverify published image identity
env:
IMAGE_DIGEST: ${{ needs.bluebuild_publish.outputs.digest }}
IMAGE_REF: ${{ needs.bluebuild_publish.outputs.image_ref }}
PINNED_REF: ${{ needs.bluebuild_publish.outputs.pinned_ref }}
run: |
set -euo pipefail
if ! [[ "$IMAGE_DIGEST" =~ ^sha256:[0-9a-f]{64}$ ]]; then
echo "::error::Build job returned a non-canonical image digest"
exit 1
fi
expected_ref="ghcr.io/${GITHUB_REPOSITORY,,}"
if [ "$IMAGE_REF" != "$expected_ref" ]; then
echo "::error::Build job returned an unexpected image repository"
exit 1
fi
if [ "$PINNED_REF" != "${IMAGE_REF}@${IMAGE_DIGEST}" ]; then
echo "::error::Build job returned an inconsistent pinned image reference"
exit 1
fi
cosign verify --key cosign.pub "$PINNED_REF" >/dev/null
index_inspect=$(skopeo inspect \
--override-os linux --override-arch amd64 \
"docker://${PINNED_REF}")
resolved_digest=$(jq -er '.Digest' <<<"$index_inspect")
if [ "$resolved_digest" != "$IMAGE_DIGEST" ]; then
echo "::error::Registry content no longer matches the published digest"
exit 1
fi
index_manifest="${RUNNER_TEMP}/secai-image-index.json"
skopeo inspect --raw "docker://${PINNED_REF}" > "$index_manifest"
platform_digest=$(
jq -er '
if (.mediaType == "application/vnd.oci.image.index.v1+json" or
.mediaType == "application/vnd.docker.distribution.manifest.list.v2+json")
then
[.manifests[]? |
select(.platform.os == "linux" and
.platform.architecture == "amd64")] |
if length == 1 then .[0].digest
else error("expected exactly one linux/amd64 image manifest")
end
else
error("published image is not a multi-platform index")
end
' "$index_manifest"
)
if ! [[ "$platform_digest" =~ ^sha256:[0-9a-f]{64}$ ]]; then
echo "::error::Image index returned a non-canonical platform digest"
exit 1
fi
platform_ref="${IMAGE_REF}@${platform_digest}"
platform_inspect=$(skopeo inspect \
--override-os linux --override-arch amd64 \
"docker://${platform_ref}")
selected_digest=$(jq -er '.Digest' <<<"$platform_inspect")
revision=$(jq -er '.Labels["org.opencontainers.image.revision"]' \
<<<"$platform_inspect")
jq -e \
'.Architecture == "amd64" and .Os == "linux"' \
<<<"$platform_inspect" >/dev/null
if [ "$selected_digest" != "$platform_digest" ]; then
echo "::error::Selected platform content does not match the image index"
exit 1
fi
if [ "$revision" != "$GITHUB_SHA" ]; then
echo "::error::Published image revision is not ${GITHUB_SHA}"
exit 1
fi
printf '%s\n' "$IMAGE_DIGEST" > IMAGE_DIGEST
printf '%s\n' "$PINNED_REF" > IMAGE_REF_PINNED
{
echo "PLATFORM_DIGEST=${platform_digest}"
echo "PLATFORM_REF=${platform_ref}"
} >> "$GITHUB_ENV"
- name: Download and verify pinned OCI tools
env:
SYFT_ARCHIVE_SHA256: 0d6be741479eddd2c8644a288990c04f3df0d609bbc1599a005532a9dff63509
SYFT_VERSION: 1.42.3
UMOCI_BINARY_SHA256: b51c267ec394499e42c6fde47f240b7b7dba57ea49df0b5acd304378b82a3b71
UMOCI_VERSION: 0.6.0
run: |
set -euo pipefail
syft_dir="${RUNNER_TEMP}/secai-syft"
syft_archive="${RUNNER_TEMP}/syft_${SYFT_VERSION}_linux_amd64.tar.gz"
umoci_path="${RUNNER_TEMP}/secai-umoci"
mkdir -p "$syft_dir"
curl --proto '=https' --tlsv1.2 -fsSL --retry 5 \
--retry-all-errors --retry-delay 2 \
-o "$syft_archive" \
"https://github.com/anchore/syft/releases/download/v${SYFT_VERSION}/syft_${SYFT_VERSION}_linux_amd64.tar.gz"
printf '%s %s\n' "$SYFT_ARCHIVE_SHA256" "$syft_archive" |
sha256sum --check --strict
tar --extract --gzip --file "$syft_archive" \
--directory "$syft_dir" --no-same-owner --no-same-permissions syft
test -f "$syft_dir/syft"
test ! -L "$syft_dir/syft"
chmod 0555 "$syft_dir/syft"
"$syft_dir/syft" version -o json |
jq -e --arg version "$SYFT_VERSION" \
'.version == $version and .platform == "linux/amd64"' >/dev/null
curl --proto '=https' --tlsv1.2 -fsSL --retry 5 \
--retry-all-errors --retry-delay 2 \
-o "$umoci_path" \
"https://github.com/opencontainers/umoci/releases/download/v${UMOCI_VERSION}/umoci.linux.amd64"
printf '%s %s\n' "$UMOCI_BINARY_SHA256" "$umoci_path" |
sha256sum --check --strict
test -f "$umoci_path"
test ! -L "$umoci_path"
chmod 0555 "$umoci_path"
"$umoci_path" --version |
grep -Fx "umoci version ${UMOCI_VERSION}" >/dev/null
{
echo "SYFT_DIR=${syft_dir}"
echo "UMOCI_PATH=${umoci_path}"
} >> "$GITHUB_ENV"
- name: Materialize final-image root without overlay storage
timeout-minutes: 45
run: |
set -euo pipefail
required_kib=$((30 * 1024 * 1024))
available_kib=$(df --output=avail -k "$RUNNER_TEMP" | tail -n 1)
if [ "$available_kib" -lt "$required_kib" ]; then
echo "::error::At least 30 GiB is required to materialize the final image"
exit 1
fi
runner_fs=$(findmnt -no FSTYPE -T "$RUNNER_TEMP")
echo "Runner temp filesystem: ${runner_fs}"
probe_dir="${RUNNER_TEMP}/secai-hardlink-probe"
install -d -m 0700 "$probe_dir"
ln -s missing-target "$probe_dir/dangling-symlink"
if ! ln -P "$probe_dir/dangling-symlink" "$probe_dir/hardlink"; then
echo "::error::Runner filesystem cannot preserve OCI hardlinks to symlinks"
exit 1
fi
if [ "$(stat -c '%d:%i' "$probe_dir/dangling-symlink")" != \
"$(stat -c '%d:%i' "$probe_dir/hardlink")" ]; then
echo "::error::Runner filesystem changed OCI hardlink identity"
exit 1
fi
unlink "$probe_dir/hardlink"
unlink "$probe_dir/dangling-symlink"
rmdir "$probe_dir"
oci_dir="${RUNNER_TEMP}/secai-final-image-oci"
bundle_dir="${RUNNER_TEMP}/secai-final-image-bundle"
test ! -e "$oci_dir"
test ! -e "$bundle_dir"
skopeo copy --retry-times 5 --preserve-digests \
--override-os linux --override-arch amd64 \
"docker://${PLATFORM_REF}" "oci:${oci_dir}:secai-os"
local_inspect=$(skopeo inspect "oci:${oci_dir}:secai-os")
local_digest=$(jq -er '.Digest' <<<"$local_inspect")
if [ "$local_digest" != "$PLATFORM_DIGEST" ]; then
echo "::error::Materialized OCI image does not match the selected platform"
exit 1
fi
"$UMOCI_PATH" unpack --rootless \
--image "${oci_dir}:secai-os" "$bundle_dir"
test -d "$bundle_dir/rootfs"
test -f "$bundle_dir/config.json"
image_rootfs="${bundle_dir}/rootfs"
scanner_uid=$(stat -c %u "$image_rootfs")
scanner_gid=$(stat -c %g "$image_rootfs")
if [ "$scanner_uid" -eq 0 ] || [ "$scanner_uid" -ne "$(id -u)" ] || \
[ "$scanner_gid" -ne "$(id -g)" ]; then
echo "::error::Rootless OCI tree has an unexpected owner mapping"
exit 1
fi
{
echo "IMAGE_ROOTFS=${image_rootfs}"
echo "SCANNER_USER=${scanner_uid}:${scanner_gid}"
} >> "$GITHUB_ENV"
- name: Generate final-image SBOM from squashed root
timeout-minutes: 90
env:
IMAGE_DIGEST: ${{ needs.bluebuild_publish.outputs.digest }}
IMAGE_REF: ${{ needs.bluebuild_publish.outputs.image_ref }}
SCANNER_IMAGE: docker.io/library/fedora@sha256:89f61a124414261868224666aa7fb8df1b78397a53623774bdfb105d1612b48b
run: |
set -euo pipefail
umask 077
docker pull --platform linux/amd64 "$SCANNER_IMAGE"
docker run --rm \
--platform linux/amd64 \
--user "$SCANNER_USER" \
--network none \
--read-only \
--memory 7g \
--memory-swap 7g \
--cpus 2 \
--pids-limit 256 \
--cap-drop ALL \
--security-opt no-new-privileges \
--tmpfs /tmp:rw,nosuid,nodev,noexec,size=512m,mode=1777 \
--mount "type=bind,source=${SYFT_DIR},target=/run/secai-sbom-scanner,readonly" \
--mount "type=bind,source=${IMAGE_ROOTFS},target=/scan-root,readonly" \
--env GOMEMLIMIT=6GiB \
--env GOMAXPROCS=2 \
--env HOME=/tmp \
--env TMPDIR=/tmp \
--env XDG_CACHE_HOME=/tmp/syft-cache \
--env SYFT_CACHE_DIR=/tmp/syft-cache \
--env SYFT_CHECK_FOR_APP_UPDATE=false \
--entrypoint /run/secai-sbom-scanner/syft \
"$SCANNER_IMAGE" \
scan dir:/scan-root \
--base-path /scan-root \
--scope squashed \
--override-default-catalogers image \
--parallelism 1 \
--source-name "$IMAGE_REF" \
--source-version "$IMAGE_DIGEST" \
--source-supplier SecAI-Hub \
--exclude './proc/**' \
--exclude './sys/**' \
--exclude './dev/**' \
--exclude './run/**' \
--exclude './tmp/**' \
--exclude './etc/hosts' \
--exclude './etc/hostname' \
--exclude './etc/resolv.conf' \
--output cyclonedx-json > sbom.cdx.json
test -s sbom.cdx.json
- name: Validate final-image SBOM
env:
IMAGE_DIGEST: ${{ needs.bluebuild_publish.outputs.digest }}
IMAGE_REF: ${{ needs.bluebuild_publish.outputs.image_ref }}
run: |
set -euo pipefail
component_count=$(jq -er '(.components // []) | length' sbom.cdx.json)
if [ "$component_count" -lt 1000 ]; then
echo "::error::Final-image SBOM is implausibly small (${component_count} components)"
exit 1
fi
jq -e \
--arg image_digest "$IMAGE_DIGEST" \
--arg image_ref "$IMAGE_REF" \
'.bomFormat == "CycloneDX"
and .metadata.component.name == $image_ref
and .metadata.component.version == $image_digest
and .metadata.component.type == "file"
and .metadata.component.supplier.name == "SecAI-Hub"
and any(.metadata.tools.components[]?;
.name == "syft" and .version == "1.42.3")
and any(.components[]?; (.purl // "") | startswith("pkg:rpm/"))
and any(.components[]?; (.purl // "") | startswith("pkg:pypi/"))' \
sbom.cdx.json >/dev/null
- name: Extract release-bound integrity baseline
env:
SCANNER_IMAGE: docker.io/library/fedora@sha256:89f61a124414261868224666aa7fb8df1b78397a53623774bdfb105d1612b48b
run: |
set -euo pipefail
docker run --rm \
--platform linux/amd64 \
--user "$SCANNER_USER" \
--network none \
--read-only \
--memory 1g \
--memory-swap 1g \
--cpus 1 \
--pids-limit 128 \
--cap-drop ALL \
--security-opt no-new-privileges \
--tmpfs /tmp:rw,nosuid,nodev,noexec,size=64m,mode=1777 \
--mount "type=bind,source=${IMAGE_ROOTFS},target=/scan-root,readonly" \
--env HOME=/tmp \
--entrypoint /bin/bash "$SCANNER_IMAGE" -c '
set -euo pipefail
rpm_db=/scan-root/usr/lib/sysimage/rpm
test -d "$rpm_db"
rpm --dbpath "$rpm_db" -q cosign >/dev/null
rpm --dbpath "$rpm_db" -ql cosign |
grep -Fx /usr/bin/cosign >/dev/null
rpm --dbpath "$rpm_db" -ql cosign |
grep -Fx /usr/bin/cosign-linux-amd64 >/dev/null
test -L /scan-root/usr/bin/cosign
test "$(readlink /scan-root/usr/bin/cosign)" = \
/usr/bin/cosign-linux-amd64
test -f /scan-root/usr/bin/cosign-linux-amd64
test -x /scan-root/usr/bin/cosign-linux-amd64
for runtime_binary in \
/usr/bin/securectl \
/usr/bin/secai-registryctl \
/usr/bin/gguf-guard; do
test -f "/scan-root${runtime_binary}"
test ! -L "/scan-root${runtime_binary}"
test -x "/scan-root${runtime_binary}"
done
for package in golang golang-bin golang-src go-filesystem cmake cmake-data gcc-c++ gcc git git-core git-core-doc perl-Git python3-pip; do
if rpm --dbpath "$rpm_db" -q --quiet -- "$package"; then
echo "FATAL: build-only package remains in final image: $package" >&2
exit 1
fi
done
for command_name in go cmake gcc g++ git pip pip3; do
for directory in usr/local/sbin usr/local/bin usr/sbin usr/bin; do
command_path="/scan-root/${directory}/${command_name}"
if [ -e "$command_path" ] || [ -L "$command_path" ]; then
echo "FATAL: build-only command remains in final image: $command_name" >&2
exit 1
fi
done
done
'
install -m 0600 \
"$IMAGE_ROOTFS/usr/share/secure-ai/integrity/release-baseline.json" \
RELEASE_BASELINE.json
mkdir -p image-root/usr/lib/systemd image-root/usr image-root/etc
cp -a --no-preserve=ownership \
"$IMAGE_ROOTFS/usr/lib/systemd/system" image-root/usr/lib/systemd/
cp -a --no-preserve=ownership \
"$IMAGE_ROOTFS/usr/libexec" image-root/usr/
cp -a --no-preserve=ownership \
"$IMAGE_ROOTFS/etc/greenboot" image-root/etc/
python3 .github/scripts/check-assembled-execstart.py \
--rootfs image-root
jq -e \
--arg source_commit "$GITHUB_SHA" \
'.version == 1
and .source_commit == $source_commit
and (.files | type == "array" and length > 0)
and all(.files[];
(.path | startswith("/"))
and (.sha256 | test("^[0-9a-f]{64}$"))
and (.size | type == "number" and . >= 0))' \
RELEASE_BASELINE.json >/dev/null
for required_path in \
/usr/bin/securectl \
/usr/bin/secai-registryctl \
/usr/bin/gguf-guard; do
jq -e --arg required_path "$required_path" \
'any(.files[]?; .path == $required_path)' \
RELEASE_BASELINE.json >/dev/null
done
python3 - <<'PY'
import hashlib
import json
import os
import re
import stat
from pathlib import Path, PurePosixPath
root = Path(os.environ["IMAGE_ROOTFS"]).resolve(strict=True)
document = json.loads(
Path("RELEASE_BASELINE.json").read_text(encoding="utf-8")
)
seen: set[str] = set()
for entry in document["files"]:
raw_path = entry["path"]
image_path = PurePosixPath(raw_path)
if (
not image_path.is_absolute()
or image_path.as_posix() != raw_path
or any(part in {"", ".", ".."} for part in image_path.parts[1:])
or raw_path in seen
):
raise SystemExit(f"unsafe or duplicate baseline path: {raw_path!r}")
seen.add(raw_path)
candidate = root.joinpath(*image_path.parts[1:])
resolved = candidate.resolve(strict=True)
try:
resolved.relative_to(root)
except ValueError as error:
raise SystemExit(
f"release baseline path escapes image root: {raw_path}"
) from error
file_stat = candidate.stat(follow_symlinks=False)
if not stat.S_ISREG(file_stat.st_mode):
raise SystemExit(f"release baseline path is not regular: {raw_path}")
if file_stat.st_size != entry["size"]:
raise SystemExit(f"release baseline size mismatch: {raw_path}")
expected = entry["sha256"]
if not isinstance(expected, str) or not re.fullmatch(
r"[0-9a-f]{64}", expected
):
raise SystemExit(f"invalid baseline digest: {raw_path}")
digest = hashlib.sha256()
with candidate.open("rb") as handle:
for chunk in iter(lambda: handle.read(1024 * 1024), b""):
digest.update(chunk)
if digest.hexdigest() != expected:
raise SystemExit(f"release baseline hash mismatch: {raw_path}")
print(f"Verified {len(seen)} release-baseline files against image root")
PY