Skip to content

Commit

Permalink
explore skipping SBOM generation
Browse files Browse the repository at this point in the history
Signed-off-by: arewm <[email protected]>
  • Loading branch information
arewm committed Oct 14, 2024
1 parent 82dc8d4 commit f071b76
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 28 deletions.
1 change: 1 addition & 0 deletions task/buildah-oci-ta/0.2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ When prefetch-dependencies task was activated it is using its artifacts to run b
|IMAGE_EXPIRES_AFTER|Delete image tag after specified time. Empty means to keep the image tag. Time values could be something like 1h, 2d, 3w for hours, days, and weeks, respectively.|""|false|
|LABELS|Additional key=value labels that should be applied to the image|[]|false|
|PREFETCH_INPUT|In case it is not empty, the prefetched content should be made available to the build.|""|false|
|SKIP_SBOM|Skip SBOM-related operations. This will likely cause EC policies to fail if enabled|false|false|
|SKIP_UNUSED_STAGES|Whether to skip stages in Containerfile that seem unused by subsequent stages|true|false|
|SOURCE_ARTIFACT|The Trusted Artifact URI pointing to the artifact with the application source code.||true|
|SQUASH|Squash all new and previous layers added as a part of this build, as per --squash|false|false|
Expand Down
37 changes: 30 additions & 7 deletions task/buildah-oci-ta/0.2/buildah-oci-ta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ spec:
be made available to the build.
type: string
default: ""
- name: SKIP_SBOM
description: Skip SBOM-related operations. This will likely cause EC
policies to fail if enabled
type: string
default: "false"
- name: SKIP_UNUSED_STAGES
description: Whether to skip stages in Containerfile that seem unused
by subsequent stages
Expand Down Expand Up @@ -500,6 +505,10 @@ spec:
- mountPath: /shared
name: shared
script: |
if [ "${SKIP_SBOM}" == "true" ]; then
echo "Skipping SBOM generation"
exit 0
fi
echo "Running syft on the source directory"
syft dir:"/var/workdir/$SOURCE_CODE_DIR/$CONTEXT" --output cyclonedx-json="/var/workdir/sbom-source.json"
echo "Running syft on the image filesystem"
Expand Down Expand Up @@ -587,7 +596,12 @@ spec:
base_image_name=$(buildah inspect --format '{{ index .ImageAnnotations "org.opencontainers.image.base.name"}}' $IMAGE | cut -f1 -d'@')
base_image_digest=$(buildah inspect --format '{{ index .ImageAnnotations "org.opencontainers.image.base.digest"}}' $IMAGE)
container=$(buildah from --pull-never $IMAGE)
buildah copy $container sbom-cyclonedx.json sbom-purl.json /root/buildinfo/content_manifests/
if [ "${SKIP_SBOM}" == "true" ]; then
echo "Skipping SBOM injection"
else
buildah copy $container sbom-cyclonedx.json sbom-purl.json /root/buildinfo/content_manifests/
fi
buildah config -a org.opencontainers.image.base.name=${base_image_name} -a org.opencontainers.image.base.digest=${base_image_digest} $container
BUILDAH_ARGS=()
Expand Down Expand Up @@ -621,11 +635,16 @@ spec:
cat "/var/workdir/image-digest"
} >"$(results.IMAGE_REF.path)"
# Remove tag from IMAGE while allowing registry to contain a port number.
sbom_repo="${IMAGE%:*}"
sbom_digest="$(sha256sum sbom-cyclonedx.json | cut -d' ' -f1)"
# The SBOM_BLOB_URL is created by `cosign attach sbom`.
echo -n "${sbom_repo}@sha256:${sbom_digest}" | tee "$(results.SBOM_BLOB_URL.path)"
if [ "${SKIP_SBOM}" == "true" ]; then
echo "Skipping generation of SBOM_BLOB_URL result"
echo -n "" | tee "$(results.SBOM_BLOB_URL.path)"
else
# Remove tag from IMAGE while allowing registry to contain a port number.
sbom_repo="${IMAGE%:*}"
sbom_digest="$(sha256sum sbom-cyclonedx.json | cut -d' ' -f1)"
# The SBOM_BLOB_URL is created by `cosign attach sbom`.
echo -n "${sbom_repo}@sha256:${sbom_digest}" | tee "$(results.SBOM_BLOB_URL.path)"
fi
computeResources:
limits:
cpu: "4"
Expand Down Expand Up @@ -653,7 +672,11 @@ spec:
update-ca-trust
fi
cosign attach sbom --sbom sbom-cyclonedx.json --type cyclonedx "$(cat "$(results.IMAGE_REF.path)")"
if [ "${SKIP_SBOM}" == "true" ]; then
echo "Skipping upload of SBOM result"
else
cosign attach sbom --sbom sbom-cyclonedx.json --type cyclonedx "$(cat "$(results.IMAGE_REF.path)")"
fi
computeResources:
limits:
cpu: 200m
Expand Down
37 changes: 30 additions & 7 deletions task/buildah-remote-oci-ta/0.2/buildah-remote-oci-ta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ spec:
to the build.
name: PREFETCH_INPUT
type: string
- default: "false"
description: Skip SBOM-related operations. This will likely cause EC policies
to fail if enabled
name: SKIP_SBOM
type: string
- default: "true"
description: Whether to skip stages in Containerfile that seem unused by subsequent
stages
Expand Down Expand Up @@ -603,6 +608,10 @@ spec:
IMAGE="${IMAGE}-${PLATFORM//[^a-zA-Z0-9]/-}"
export IMAGE
fi
if [ "${SKIP_SBOM}" == "true" ]; then
echo "Skipping SBOM generation"
exit 0
fi
echo "Running syft on the source directory"
syft dir:"/var/workdir/$SOURCE_CODE_DIR/$CONTEXT" --output cyclonedx-json="/var/workdir/sbom-source.json"
echo "Running syft on the image filesystem"
Expand Down Expand Up @@ -705,7 +714,12 @@ spec:
base_image_name=$(buildah inspect --format '{{ index .ImageAnnotations "org.opencontainers.image.base.name"}}' $IMAGE | cut -f1 -d'@')
base_image_digest=$(buildah inspect --format '{{ index .ImageAnnotations "org.opencontainers.image.base.digest"}}' $IMAGE)
container=$(buildah from --pull-never $IMAGE)
buildah copy $container sbom-cyclonedx.json sbom-purl.json /root/buildinfo/content_manifests/
if [ "${SKIP_SBOM}" == "true" ]; then
echo "Skipping SBOM injection"
else
buildah copy $container sbom-cyclonedx.json sbom-purl.json /root/buildinfo/content_manifests/
fi
buildah config -a org.opencontainers.image.base.name=${base_image_name} -a org.opencontainers.image.base.digest=${base_image_digest} $container
BUILDAH_ARGS=()
Expand Down Expand Up @@ -739,11 +753,16 @@ spec:
cat "/var/workdir/image-digest"
} >"$(results.IMAGE_REF.path)"
# Remove tag from IMAGE while allowing registry to contain a port number.
sbom_repo="${IMAGE%:*}"
sbom_digest="$(sha256sum sbom-cyclonedx.json | cut -d' ' -f1)"
# The SBOM_BLOB_URL is created by `cosign attach sbom`.
echo -n "${sbom_repo}@sha256:${sbom_digest}" | tee "$(results.SBOM_BLOB_URL.path)"
if [ "${SKIP_SBOM}" == "true" ]; then
echo "Skipping generation of SBOM_BLOB_URL result"
echo -n "" | tee "$(results.SBOM_BLOB_URL.path)"
else
# Remove tag from IMAGE while allowing registry to contain a port number.
sbom_repo="${IMAGE%:*}"
sbom_digest="$(sha256sum sbom-cyclonedx.json | cut -d' ' -f1)"
# The SBOM_BLOB_URL is created by `cosign attach sbom`.
echo -n "${sbom_repo}@sha256:${sbom_digest}" | tee "$(results.SBOM_BLOB_URL.path)"
fi
securityContext:
capabilities:
add:
Expand Down Expand Up @@ -779,7 +798,11 @@ spec:
update-ca-trust
fi
cosign attach sbom --sbom sbom-cyclonedx.json --type cyclonedx "$(cat "$(results.IMAGE_REF.path)")"
if [ "${SKIP_SBOM}" == "true" ]; then
echo "Skipping upload of SBOM result"
else
cosign attach sbom --sbom sbom-cyclonedx.json --type cyclonedx "$(cat "$(results.IMAGE_REF.path)")"
fi
volumeMounts:
- mountPath: /mnt/trusted-ca
name: trusted-ca
Expand Down
37 changes: 30 additions & 7 deletions task/buildah-remote/0.2/buildah-remote.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@ spec:
description: Additional key=value labels that should be applied to the image
name: LABELS
type: array
- default: "false"
description: Skip SBOM-related operations. This will likely cause EC policies
to fail if enabled
name: SKIP_SBOM
type: string
- description: The platform to build on
name: PLATFORM
type: string
Expand Down Expand Up @@ -579,6 +584,10 @@ spec:
IMAGE="${IMAGE}-${PLATFORM//[^a-zA-Z0-9]/-}"
export IMAGE
fi
if [ "${SKIP_SBOM}" == "true" ]; then
echo "Skipping SBOM generation"
exit 0
fi
echo "Running syft on the source directory"
syft dir:"$(workspaces.source.path)/$SOURCE_CODE_DIR/$CONTEXT" --output cyclonedx-json="$(workspaces.source.path)/sbom-source.json"
echo "Running syft on the image filesystem"
Expand Down Expand Up @@ -681,7 +690,12 @@ spec:
base_image_name=$(buildah inspect --format '{{ index .ImageAnnotations "org.opencontainers.image.base.name"}}' $IMAGE | cut -f1 -d'@')
base_image_digest=$(buildah inspect --format '{{ index .ImageAnnotations "org.opencontainers.image.base.digest"}}' $IMAGE)
container=$(buildah from --pull-never $IMAGE)
buildah copy $container sbom-cyclonedx.json sbom-purl.json /root/buildinfo/content_manifests/
if [ "${SKIP_SBOM}" == "true" ]; then
echo "Skipping SBOM injection"
else
buildah copy $container sbom-cyclonedx.json sbom-purl.json /root/buildinfo/content_manifests/
fi
buildah config -a org.opencontainers.image.base.name=${base_image_name} -a org.opencontainers.image.base.digest=${base_image_digest} $container
BUILDAH_ARGS=()
Expand Down Expand Up @@ -715,11 +729,16 @@ spec:
cat "$(workspaces.source.path)/image-digest"
} > "$(results.IMAGE_REF.path)"
# Remove tag from IMAGE while allowing registry to contain a port number.
sbom_repo="${IMAGE%:*}"
sbom_digest="$(sha256sum sbom-cyclonedx.json | cut -d' ' -f1)"
# The SBOM_BLOB_URL is created by `cosign attach sbom`.
echo -n "${sbom_repo}@sha256:${sbom_digest}" | tee "$(results.SBOM_BLOB_URL.path)"
if [ "${SKIP_SBOM}" == "true" ]; then
echo "Skipping generation of SBOM_BLOB_URL result"
echo -n "" | tee "$(results.SBOM_BLOB_URL.path)"
else
# Remove tag from IMAGE while allowing registry to contain a port number.
sbom_repo="${IMAGE%:*}"
sbom_digest="$(sha256sum sbom-cyclonedx.json | cut -d' ' -f1)"
# The SBOM_BLOB_URL is created by `cosign attach sbom`.
echo -n "${sbom_repo}@sha256:${sbom_digest}" | tee "$(results.SBOM_BLOB_URL.path)"
fi
securityContext:
capabilities:
add:
Expand Down Expand Up @@ -755,7 +774,11 @@ spec:
update-ca-trust
fi
cosign attach sbom --sbom sbom-cyclonedx.json --type cyclonedx "$(cat "$(results.IMAGE_REF.path)")"
if [ "${SKIP_SBOM}" == "true" ]; then
echo "Skipping upload of SBOM result"
else
cosign attach sbom --sbom sbom-cyclonedx.json --type cyclonedx "$(cat "$(results.IMAGE_REF.path)")"
fi
volumeMounts:
- mountPath: /mnt/trusted-ca
name: trusted-ca
Expand Down
36 changes: 29 additions & 7 deletions task/buildah/0.2/buildah.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ spec:
description: Additional key=value labels that should be applied to the image
type: array
default: []
- name: SKIP_SBOM
description: Skip SBOM-related operations. This will likely cause EC policies to fail if enabled
type: string
default: "false"

results:
- description: Digest of the image just built
Expand Down Expand Up @@ -443,6 +447,10 @@ spec:
memory: 1Gi
cpu: 500m
script: |
if [ "${SKIP_SBOM}" == "true" ]; then
echo "Skipping SBOM generation"
exit 0
fi
echo "Running syft on the source directory"
syft dir:"$(workspaces.source.path)/$SOURCE_CODE_DIR/$CONTEXT" --output cyclonedx-json="$(workspaces.source.path)/sbom-source.json"
echo "Running syft on the image filesystem"
Expand Down Expand Up @@ -530,7 +538,12 @@ spec:
base_image_name=$(buildah inspect --format '{{ index .ImageAnnotations "org.opencontainers.image.base.name"}}' $IMAGE | cut -f1 -d'@')
base_image_digest=$(buildah inspect --format '{{ index .ImageAnnotations "org.opencontainers.image.base.digest"}}' $IMAGE)
container=$(buildah from --pull-never $IMAGE)
buildah copy $container sbom-cyclonedx.json sbom-purl.json /root/buildinfo/content_manifests/
if [ "${SKIP_SBOM}" == "true" ]; then
echo "Skipping SBOM injection"
else
buildah copy $container sbom-cyclonedx.json sbom-purl.json /root/buildinfo/content_manifests/
fi
buildah config -a org.opencontainers.image.base.name=${base_image_name} -a org.opencontainers.image.base.digest=${base_image_digest} $container
BUILDAH_ARGS=()
Expand Down Expand Up @@ -564,11 +577,16 @@ spec:
cat "$(workspaces.source.path)/image-digest"
} > "$(results.IMAGE_REF.path)"
# Remove tag from IMAGE while allowing registry to contain a port number.
sbom_repo="${IMAGE%:*}"
sbom_digest="$(sha256sum sbom-cyclonedx.json | cut -d' ' -f1)"
# The SBOM_BLOB_URL is created by `cosign attach sbom`.
echo -n "${sbom_repo}@sha256:${sbom_digest}" | tee "$(results.SBOM_BLOB_URL.path)"
if [ "${SKIP_SBOM}" == "true" ]; then
echo "Skipping generation of SBOM_BLOB_URL result"
echo -n "" | tee "$(results.SBOM_BLOB_URL.path)"
else
# Remove tag from IMAGE while allowing registry to contain a port number.
sbom_repo="${IMAGE%:*}"
sbom_digest="$(sha256sum sbom-cyclonedx.json | cut -d' ' -f1)"
# The SBOM_BLOB_URL is created by `cosign attach sbom`.
echo -n "${sbom_repo}@sha256:${sbom_digest}" | tee "$(results.SBOM_BLOB_URL.path)"
fi
securityContext:
runAsUser: 0
capabilities:
Expand All @@ -592,7 +610,11 @@ spec:
update-ca-trust
fi
cosign attach sbom --sbom sbom-cyclonedx.json --type cyclonedx "$(cat "$(results.IMAGE_REF.path)")"
if [ "${SKIP_SBOM}" == "true" ]; then
echo "Skipping upload of SBOM result"
else
cosign attach sbom --sbom sbom-cyclonedx.json --type cyclonedx "$(cat "$(results.IMAGE_REF.path)")"
fi
computeResources:
limits:
memory: 512Mi
Expand Down

0 comments on commit f071b76

Please sign in to comment.