Skip to content

Commit 702bd8c

Browse files
committed
sbom: T9098: syft should run un squashfs instead of unpacked chroot
lb (live-build) binary runs binary_rootfs first, then binary_grub-efi. binary_grub-efi temporarily installs EFI tooling and then runs: "apt remove --auto-remove --purge --allow-remove-essential" That cleanup is safe for the already-generated squashfs, but it mutates build/chroot and can remove vyos-1x, breaking subsequent work that expects chroot to remain intact for SBOM generation. But why unpacking the squashfs? In an ideal world we could call syft on the compressed squashfs file which is supported. In our world, we do use a BCJ pre-filter chained with LZMA2 for compressing the squashfs, which will increase the compression ratio without a decompression penalty. Difference: ~14.3 MB, ~2.7% smaller This is unsupported by fyft which means we do need to unpack the squashfs first before checking the files and generating the SBOM file.
1 parent 5e2e9a3 commit 702bd8c

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

scripts/image-build/build-vyos-image

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ def build():
156156
'qemu-utils',
157157
'gdisk',
158158
'kpartx',
159+
'squashfs-tools',
159160
'dosfstools'
160161
],
161162
'binaries': []
@@ -727,17 +728,26 @@ Pin-Priority: 600
727728
manifest['artifacts'].append(iso_file)
728729

729730
# Now create SBOM
730-
syft_target_dir = 'chroot'
731+
syft_target_dir = 'unsquashfs_rootfs'
731732
syft_base_path = os.getcwd() + f'/{syft_target_dir}'
732733
base_filename = iso_file.rstrip('.iso')
733-
syft_cmd = [['syft', syft_target_dir,
734+
# lb config builds the amd64 squashfs as xz with -Xbcj x86 (a BCJ pre-filter
735+
# chained with LZMA2. Real unsquashfs/mksquashfs fully support multi-filter
736+
# xz streams; syft's own Go-based squashfs/xz decoder apparently only handles
737+
# plain single-filter. Extract squashfs first
738+
print("I: Unpack squashfs for SBOM generation")
739+
syft_cmd = [['unsquashfs', '-quiet', '-no-progress', '-dest', syft_target_dir, '-file', 'binary/live/filesystem.squashfs']]
740+
# run syft on extracted content
741+
syft_cmd.append(['syft', syft_target_dir,
734742
'--source-name', 'VyOS', '--source-version', version,
735743
'-o', f'cyclonedx-json={base_filename}.cdx.json',
736-
'-o', f'spdx-json={base_filename}.spdx.json']]
744+
'-o', f'spdx-json={base_filename}.spdx.json'])
737745

738746
# syft bug for CycloneDX https://github.com/anchore/syft/issues/4592#issuecomment-4567247328
739747
syft_cmd.append(['sed', '-i', '-e', f's@{syft_base_path}@@g', f'{base_filename}.cdx.json'])
740748
syft_cmd.append(['sed', '-i', '-e', f's@{syft_base_path}@//@g', f'{base_filename}.spdx.json'])
749+
# remove temporary unpacked squashfs
750+
syft_cmd.append(['rm', '-rf', syft_target_dir])
741751

742752
for c in syft_cmd:
743753
with subprocess.Popen(c, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,

0 commit comments

Comments
 (0)