Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mkosi generate SBOM support using finalize script #1007

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

cschneemann
Copy link
Contributor

@cschneemann cschneemann commented May 28, 2024

Tested with mkosi 22.

If Buildflag sbom is set a mkosi.finaliz script is created in a mkosi.conf.d subdirectory to not overwrite possible existent scripts and will be called at the end to call generate_sbom before mkosi creates the image.

The used version needs to support configuration dir feature and multiple scripts of same name (mkosi v18)

Mkosi builds in using tmpfs and other security features and removes everything after building, so it is not possible to call generate_sbom after mkosi run on the buildroot.

Content of /.build needs to be copied into a place under /usr because most host directories are hidden from mkosi (introduced in mkosi v20)

The name for the spdx profileis set by the ImageID of mkosi.conf. Default is image if not set.

Added support for generate_sbom through a finalize script.

Tested with mkosi 22 on Debian Testing.
The used version needs to support configuration dir feature and multiple
scripts of same name (mkosi v18)

Mkosi builds in using tmpfs and other security features and removes
everything after building, so it is not possible to call generate_sbom
after mkosi run on the buildroot.

Content of `/.build` needs to be copied into a place under `/usr`
because most host directories are hidden from mkosi (introduced in mkosi
v20)
The name for the spdx profile can be set using the macro
`%mkosi_spdx_name`  in the project configuration.
Default is `image` if not set.
--format "$format" \
--dir "$IMAGENAME" > "\$OUTPUTDIR/\${imgname}${buildnum}.${format/cyclonedx/cdx}.json"
pushd \$OUTPUTDIR >/dev/null
/usr/bin/sha256sum "\${imgname}${buildnum}.${format/cyclonedx/cdx}.json" > "\${imgname}${buildnum}.${format/cyclonedx/cdx}.json".sh256
Copy link
Contributor

Choose a reason for hiding this comment

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

.sh256 -> .sha256

echo "generating script for sbom $format"
cat << EOF >> $BUILD_ROOT/$TOPDIR/SOURCES/mkosi.conf.d/99-sbom/mkosi.finalize
#!/usr/bin/bash
# script generated by build-receipe-mkosi for sbom buildflags
Copy link
Contributor

Choose a reason for hiding this comment

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

receipe -> recipe

@cschneemann
Copy link
Contributor Author

@gollub thank you.. typos fixed

build-recipe-mkosi Outdated Show resolved Hide resolved
No special macro is needed to set the filename, take ImageID (if set) or
default to "image".
Also no sha256 generateion needs to be done, mkosi creates it for all
files in $OUTPUTDIR in "$IMAGENAME.SHA256SUMS"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants