Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added twoliter/embedded/.rpm2img.swp
Binary file not shown.
44 changes: 44 additions & 0 deletions twoliter/embedded/rpm2img
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,50 @@ printf "%s\n" "${INVENTORY_DATA}" >"${ROOT_MOUNT}/usr/share/bottlerocket/applica
# can access the inventory without needed to dig into the generated image.
printf "%s\n" "${INVENTORY_DATA}" >"${OUTPUT_DIR}/application-inventory.json"

# Install SBOM subpackages for each installed RPM (only for EROFS images)
if [[ "${EROFS_ROOT_PARTITION}" == "yes" ]]; then
Comment on lines +259 to +260
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This restriction doesn't make much sense as build system policy - "we will only produce SBOM artifacts if you're using EROFS".

Options:

  1. Drop it and do it unconditionally.
  2. Add a different image feature flag that's related to SBOM.
  3. Compress the SBOM files on disk, if that gives enough space?
  4. Emit the build artifacts always, and only add to the image if we're using EROFS?

Not sure which is best, assuming you can't just always include SBOM artifacts.

SBOM_RPMS=()
while IFS= read -r rpm_name; do
sbom_rpm="${rpm_name}-sbom"
if rpm -q --root "${ROOT_MOUNT}" "${sbom_rpm}" >/dev/null 2>&1; then
SBOM_RPMS+=("${sbom_rpm}")
else
Comment on lines +264 to +266
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to handle the case where someone adds foo-sbom to their variant's package list, so we've installed it? That seems pretty weird.

# Check if SBOM package file exists in local packages or external kits
sbom_file=$(find "${PACKAGE_DIR}" -maxdepth 1 -name "${sbom_rpm}*.rpm" -print -quit)
if [[ -z "${sbom_file}" && -n "${EXTERNAL_KITS_PATH}" ]]; then
sbom_file=$(find "${EXTERNAL_KITS_PATH}" -name "${sbom_rpm}*.rpm" -print -quit)
Comment on lines +267 to +270
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems pretty hacky and I think we can do better:

  1. Add an "sbom" subpackage to metadata.spec.
  2. Have it Provides: %{_cross_os}image-metadata(sbom) (and Requires: %{name}).
  3. Copy rpmdb from ${ROOT_MOUNT} into new temp dir ${SBOM_MOUNT}.
  4. Install metadata-sbom into ${SBOM_MOUNT} via rpm -iv.
  5. For each of the RPM SBOM packages, add Supplements: (%{_cross_os}image-metadata(sbom) if %{name}).

That should give you a new temporary directory with only the SBOM files installed, which you can then concatenate together.

fi
if [[ -n "${sbom_file}" ]]; then
if rpm -iv --ignorearch --root "${ROOT_MOUNT}" "${sbom_file}" >/dev/null 2>&1; then
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't install packages only to turn around and erase them. We can rpm -iv them into a separate directory, not the final root.

SBOM_RPMS+=("${sbom_rpm}")
fi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to fix your editor settings to not insert a mix of tabs/spaces. Please make sure this follows existing whitespace conventions.

fi
fi
done < <(rpm -qa --root "${ROOT_MOUNT}" --queryformat "%{NAME}\n")

# Merge SBOMs into a single json file
KIT_SBOMS_DIR="${ROOT_MOUNT}/usr/share/sboms"
if [ -d "${KIT_SBOMS_DIR}" ]; then
IMAGE_SBOM_DIR="${ROOT_MOUNT}/usr/share/bottlerocket"
mkdir -p "${IMAGE_SBOM_DIR}"
for format in "spdx" "cyclonedx"; do
image_sbom="${format}-sbom.json"
image_sbom_path="${IMAGE_SBOM_DIR}/${image_sbom}"
find "${KIT_SBOMS_DIR}" -name "*-${format}.json" -type f -exec sbomtool merge --output "${image_sbom_path}" {} \+

# Write the inventory to a file in the local build output directory
cp "${image_sbom_path}" "${OUTPUT_DIR}/${image_sbom}"
done
# Clean up old SBOM packages
rm -rf "${KIT_SBOMS_DIR}"
fi

# Uninstall SBOM subpackages
for sbom_rpm in "${SBOM_RPMS[@]}"; do
rpm -e --root "${ROOT_MOUNT}" "${sbom_rpm}" >/dev/null 2>&1 || true
done
fi

# Regenerate module dependencies, if possible.
KMOD_DIR="${ROOT_MOUNT}/lib/modules"
# First decompress the kernel modules, so they can be recompressed by EROFS.
Expand Down
Loading