-
Notifications
You must be signed in to change notification settings - Fork 263
PHPLIB-1866: Add automated SBOM generation using cyclonedx-php-composer #1921
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
base: v2.x
Are you sure you want to change the base?
Changes from all commits
e67bcfc
a4cc964
09a1020
2d01bd4
556579d
d8a22e1
4e9f685
709c671
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| tasks: | ||
| - name: upload-sbom | ||
| tags: ["ssdlc"] | ||
| allowed_requesters: ["commit"] | ||
| exec_timeout_secs: 600 | ||
| # pre_error_fails_task: false allows the task to proceed even if pre steps such as | ||
| # "fetch extension" fail. PHP and Composer (needed by generate-sbom.sh) are available | ||
| # from the earlier "install dependencies" and "install composer" pre steps. | ||
| pre_error_fails_task: false | ||
| commands: | ||
| - func: "generate-sbom" | ||
| - func: "upload-sbom" | ||
|
|
||
| buildvariants: | ||
| - name: sbom | ||
| display_name: "SBOM" | ||
| allowed_requesters: ["commit"] | ||
| stepback: false | ||
| paths: | ||
| - composer.json | ||
|
Comment on lines
+19
to
+20
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choice was made not to check in the composer.lock in #158 . |
||
| run_on: | ||
| - ubuntu2004-small | ||
| tasks: | ||
| - name: upload-sbom | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| #!/usr/bin/env bash | ||
| # Environment Variables: | ||
| # None required — all inputs are derived from the repository. | ||
| set -eo pipefail | ||
|
|
||
| SERIAL_NUMBER="urn:uuid:dc42a43b-4ace-4c42-9a6e-0b9e28fdd100" | ||
|
|
||
|
|
||
| # composer require modifies composer.json. Save and restore it so the cyclonedx | ||
| # plugin is not added to the project's dependencies. | ||
| cp composer.json composer.json.bak | ||
| trap 'mv composer.json.bak composer.json' EXIT | ||
|
jasonhills-mongodb marked this conversation as resolved.
|
||
|
|
||
| echo "Installing CycloneDX PHP Composer plugin" | ||
| composer config allow-plugins.cyclonedx/cyclonedx-php-composer true | ||
| composer require --dev cyclonedx/cyclonedx-php-composer:6.2.0 --no-update | ||
|
jasonhills-mongodb marked this conversation as resolved.
|
||
|
|
||
| echo "Updating dependencies" | ||
|
jasonhills-mongodb marked this conversation as resolved.
|
||
| # --ignore-platform-reqs: SBOM generation doesn't need to run the code, so extension | ||
| # availability and exact PHP patch versions don't matter here. | ||
| # --no-scripts: skip git submodule updates and other scripts that require a full dev setup. | ||
| composer update --ignore-platform-reqs --no-scripts | ||
|
jasonhills-mongodb marked this conversation as resolved.
jasonhills-mongodb marked this conversation as resolved.
|
||
|
|
||
| echo "Generating SBOM" | ||
| composer CycloneDX:make-sbom \ | ||
| --spec-version=1.5 \ | ||
| --output-format=JSON \ | ||
| --output-file=sbom.cdx.json \ | ||
| --omit dev \ | ||
| --no-validate | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is redundant, as we do a more thorough validation downstream that provides better output for resolution of the issue. Added in a clarifying comment. |
||
| # --no-validate: skips the plugin's built-in schema validation. Silkbomb will | ||
| # reject a malformed SBOM on upload. | ||
|
|
||
| jq --argjson v 1 --arg serial "$SERIAL_NUMBER" \ | ||
| '.version = $v | .serialNumber = $serial' sbom.cdx.json > sbom.json | ||
| rm sbom.cdx.json | ||
|
|
||
| echo "Generated sbom.json" | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| #!/usr/bin/env bash | ||
| set -eo pipefail | ||
|
|
||
| : "${branch_name:?}" | ||
| : "${AWS_ACCESS_KEY_ID:?}" | ||
| : "${AWS_SECRET_ACCESS_KEY:?}" | ||
| : "${AWS_SESSION_TOKEN:?}" | ||
|
|
||
| silkbomb="901841024863.dkr.ecr.us-east-1.amazonaws.com/release-infrastructure/silkbomb:2.0" | ||
|
jasonhills-mongodb marked this conversation as resolved.
|
||
| docker pull "${silkbomb}" | ||
|
jasonhills-mongodb marked this conversation as resolved.
|
||
|
|
||
| docker run --rm -v "$(pwd):/pwd" \ | ||
| --user "$(id -u):$(id -g)" \ | ||
| --env 'AWS_ACCESS_KEY_ID' --env 'AWS_SECRET_ACCESS_KEY' --env 'AWS_SESSION_TOKEN' \ | ||
| "${silkbomb}" upload \ | ||
| --repo mongodb/mongo-php-library \ | ||
| --branch "${branch_name}" \ | ||
| --sbom-in /pwd/sbom.json | ||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.