Skip to content

Commit 3a91d53

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 3a91d53

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

scripts/image-build/build-vyos-image

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -727,17 +727,26 @@ Pin-Priority: 600
727727
manifest['artifacts'].append(iso_file)
728728

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

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

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

0 commit comments

Comments
 (0)