-
Notifications
You must be signed in to change notification settings - Fork 231
USHIFT-6920: feat: add crypto_scan auto-rebase for cbom generation #7051
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
Open
fracappa
wants to merge
1
commit into
openshift:main
Choose a base branch
from
fracappa:fca/add-ushift-cbom
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+97
−0
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| #!/usr/bin/bash | ||
| set -euo pipefail | ||
|
|
||
| SCANNER_IMAGE="images.paas.redhat.com/exd-sp-guild-security/rh-crypto-scanner-image:latest" | ||
| REPOROOT="$(readlink -f "$(dirname "${BASH_SOURCE[0]}")/../..")" | ||
| CBOM_OUTPUT="${REPOROOT}/cbom-microshift.json" | ||
| SPDX_OUTPUT="${REPOROOT}/sbom-microshift-crypto.spdx.json" | ||
|
|
||
| echo "Running crypto scanner against MicroShift source..." | ||
| echo "Scanner image: ${SCANNER_IMAGE}" | ||
| echo "Source directory: ${REPOROOT}" | ||
|
|
||
| if ! podman pull "${SCANNER_IMAGE}"; then | ||
| echo "WARNING: failed to pull scanner image, skipping CBOM generation" >&2 | ||
| exit 0 | ||
| fi | ||
|
|
||
| # The scanner skips directories named "vendor/" by default. | ||
| # Mount vendor directories under non-skipped names so the scanner | ||
| # processes them. The "deps/" directory is excluded because it is a | ||
| # patched copy of upstream Kubernetes vendor and would duplicate | ||
| # findings already covered by "vendor/". | ||
| # We stage a scan directory with only the sources we want scanned. | ||
| SCAN_DIR=$(mktemp -d) | ||
| trap 'rm -rf "${SCAN_DIR}"' EXIT | ||
|
|
||
| cp -a "${REPOROOT}/pkg" "${SCAN_DIR}/pkg" | ||
| cp -a "${REPOROOT}/cmd" "${SCAN_DIR}/cmd" | ||
| cp -a "${REPOROOT}/vendor" "${SCAN_DIR}/vendor-deps" | ||
| cp -a "${REPOROOT}/etcd/cmd" "${SCAN_DIR}/etcd-cmd" | ||
| cp -a "${REPOROOT}/etcd/vendor" "${SCAN_DIR}/etcd-deps" | ||
|
|
||
| if ! podman run --rm \ | ||
| -v "${SCAN_DIR}:/workspace:z" \ | ||
| "${SCANNER_IMAGE}" \ | ||
| /workspace > "${CBOM_OUTPUT}"; then | ||
| echo "WARNING: crypto scan failed, skipping CBOM generation" >&2 | ||
| exit 0 | ||
| fi | ||
|
|
||
| echo "CBOM generated: " | ||
| ls -lh "${CBOM_OUTPUT}" | ||
|
|
||
| # SPDX 2.3 has no native crypto asset support. As a workaround agreed | ||
| # with prod sec, cryptoProperties are serialized into the SPDX package | ||
| # "comment" field. | ||
| if ! jq '{ | ||
| spdxVersion: "SPDX-2.3", | ||
| dataLicense: "CC0-1.0", | ||
| SPDXID: "SPDXRef-DOCUMENT", | ||
| name: "MicroShift-CBOM", | ||
| documentNamespace: "https://microshift.io/spdx/cbom", | ||
| packages: ( | ||
| [{ | ||
| SPDXID: "SPDXRef-Package-RootPackage", | ||
| name: "microshift", | ||
| downloadLocation: "NOASSERTION", | ||
| filesAnalyzed: false | ||
| }] + | ||
| [.components[] | { | ||
| SPDXID: ("SPDXRef-Package-" + (.name | gsub("[^a-zA-Z0-9.-]"; "-"))), | ||
| name: .name, | ||
| comment: (.cryptoProperties | tojson), | ||
| description: "Converted CBOM component from CycloneDX to SPDX", | ||
| downloadLocation: "NOASSERTION", | ||
| filesAnalyzed: false | ||
| }] | ||
| ), | ||
| relationships: ( | ||
| [{ | ||
| spdxElementId: "SPDXRef-DOCUMENT", | ||
| relatedSpdxElement: "SPDXRef-Package-RootPackage", | ||
| relationshipType: "DESCRIBES" | ||
| }] + | ||
| [.components[] | { | ||
| spdxElementId: "SPDXRef-Package-RootPackage", | ||
| relatedSpdxElement: ("SPDXRef-Package-" + (.name | gsub("[^a-zA-Z0-9.-]"; "-"))), | ||
| relationshipType: "CONTAINS" | ||
| }] | ||
| ) | ||
| }' "${CBOM_OUTPUT}" > "${SPDX_OUTPUT}"; then | ||
| echo "WARNING: SPDX conversion failed" >&2 | ||
| exit 0 | ||
| fi | ||
|
|
||
| echo "SPDX generated: " | ||
| ls -lh "${SPDX_OUTPUT}" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we want to commit it to the root ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I spoke with @pacevedom and we agreed to push it on the root directory, but feel free to provide any suggestion if you believe there could be better places