Skip to content

Commit

Permalink
fix: inaccurate value "using docker" in sbom (#3045)
Browse files Browse the repository at this point in the history
* fix: inaccurate value for if using docker image in sbom
	generated content of docker.txt by get env variable:BUILDIMAGESHA passed from "doccker run"
* fix: set default to "N.A" if no env.variable BUILDIMAGESHA passed from docker
* fix: add check if cyclonedbx existing
  • Loading branch information
zdtsw authored Jan 12, 2023
1 parent 151c6cb commit 18f343c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
17 changes: 12 additions & 5 deletions sbin/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,6 @@ generateSBoM() {
# Add OS full version (Kernel is covered in the first field)
addSBOMMetadataProperty "${javaHome}" "${classpath}" "${sbomJson}" "OS version" "${BUILD_CONFIG[OS_FULL_VERSION]^}"
addSBOMMetadataProperty "${javaHome}" "${classpath}" "${sbomJson}" "OS architecture" "${BUILD_CONFIG[OS_ARCHITECTURE]^}"
addSBOMMetadataProperty "${javaHome}" "${classpath}" "${sbomJson}" "Use Docker for build" "${BUILD_CONFIG[USE_DOCKER]^}"

# Create JDK Component
addSBOMComponent "${javaHome}" "${classpath}" "${sbomJson}" "Eclipse Temurin" "${fullVer}" "${BUILD_CONFIG[BUILD_VARIANT]^} JDK Component"
Expand Down Expand Up @@ -794,9 +793,17 @@ generateSBoM() {
addSBOMMetadataTools "${javaHome}" "${classpath}" "${sbomJson}" "FreeType" "$(cat ${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[TARGET_DIR]}/metadata/dependency_version_freetype.txt)"
# Add FreeMarker 3rd party (openj9)
addSBOMMetadataTools "${javaHome}" "${classpath}" "${sbomJson}" "FreeMarker" "$(cat ${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[TARGET_DIR]}/metadata/dependency_version_freemarker.txt)"
# Add Build Docker image SHA1
addSBOMMetadataTools "${javaHome}" "${classpath}" "${sbomJson}" "Docker image SHA1" "$(cat ${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[TARGET_DIR]}/metadata/docker.txt)"

# Add Build Docker image SHA1
buildimagesha=$(cat ${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[TARGET_DIR]}/metadata/docker.txt)
# ${BUILD_CONFIG[USE_DOCKER]^} always set to false cannot rely on it.
if [ -n "${buildimagesha}" ] && [ "${buildimagesha}" != "N.A" ]; then
addSBOMMetadataProperty "${javaHome}" "${classpath}" "${sbomJson}" "Use Docker for build" "true"
addSBOMMetadataTools "${javaHome}" "${classpath}" "${sbomJson}" "Docker image SHA1" "${buildimagesha}"
else
addSBOMMetadataProperty "${javaHome}" "${classpath}" "${sbomJson}" "Use Docker for build" "false"
fi

# Print SBOM json
echo "CycloneDX SBOM:"
cat "${sbomJson}"
Expand Down Expand Up @@ -1803,7 +1810,7 @@ if [[ "${BUILD_CONFIG[ASSEMBLE_EXPLODED_IMAGE]}" == "true" ]]; then
printJavaVersionString
addInfoToReleaseFile
addInfoToJson
if [[ "${BUILD_CONFIG[CREATE_SBOM]}" == "true" ]]; then
if [[ "${BUILD_CONFIG[CREATE_SBOM]}" == "true" ]] && [[ -d "${CYCLONEDB_DIR}" ]]; then
javaHome="$(setupAntEnv)"
buildCyclonedxLib "${javaHome}"
generateSBoM "${javaHome}"
Expand Down Expand Up @@ -1839,7 +1846,7 @@ if [[ "${BUILD_CONFIG[MAKE_EXPLODED]}" != "true" ]]; then
printJavaVersionString
addInfoToReleaseFile
addInfoToJson
if [[ "${BUILD_CONFIG[CREATE_SBOM]}" == "true" ]]; then
if [[ "${BUILD_CONFIG[CREATE_SBOM]}" == "true" ]] && [[ -d "${CYCLONEDB_DIR}" ]]; then
javaHome="$(setupAntEnv)"
buildCyclonedxLib "${javaHome}"
generateSBoM "${javaHome}"
Expand Down
6 changes: 6 additions & 0 deletions sbin/prepareWorkspace.sh
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,11 @@ checkingAndDownloadingFreeType() {
echo "${FREETYPE_BUILD_INFO}" > "${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[TARGET_DIR]}/metadata/dependency_version_freetype.txt"
}

# Recording Build image SHA into docker.txt
writeDockerImageSHA(){
echo "${BUILDIMAGESHA-N.A}" > "${BUILD_CONFIG[WORKSPACE_DIR]}/${BUILD_CONFIG[TARGET_DIR]}/metadata/docker.txt"
}

# Generates cacerts file
prepareMozillaCacerts() {
echo "Generating cacerts from Mozilla's bundle"
Expand Down Expand Up @@ -682,4 +687,5 @@ function configureWorkspace() {
prepareMozillaCacerts
fi
fi
writeDockerImageSHA
}

0 comments on commit 18f343c

Please sign in to comment.