Skip to content
Open
1 change: 1 addition & 0 deletions .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ github_checks_aliases:
# Include files that contain various tasks, task groups, and build variant definitions
include:
- filename: .evergreen/config/functions.yml
- filename: .evergreen/config/sbom.yml

- filename: .evergreen/config/build-task-groups.yml
- filename: .evergreen/config/build-variants.yml
Expand Down
46 changes: 46 additions & 0 deletions .evergreen/config/functions.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,50 @@
functions:
"generate-sbom":
- command: subprocess.exec
type: setup
display_name: Generate SBOM
params:
working_dir: src
binary: bash
args:
- .evergreen/generate-sbom.sh

"upload-sbom":
- command: ec2.assume_role
display_name: Assume ECR readonly IAM role
params:
role_arn: &ecr_ro_role_arn arn:aws:iam::901841024863:role/ecr-role-evergreen-ro
- command: subprocess.exec
type: setup
display_name: Log in to ECR
params:
working_dir: src
binary: bash
include_expansions_in_env:
- AWS_ACCESS_KEY_ID
- AWS_SECRET_ACCESS_KEY
- AWS_SESSION_TOKEN
args:
- -c
- aws ecr get-login-password --region us-east-1 | docker login --username AWS --password-stdin 901841024863.dkr.ecr.us-east-1.amazonaws.com
Comment thread
jasonhills-mongodb marked this conversation as resolved.
- command: ec2.assume_role
display_name: Assume Silkbomb IAM role
params:
role_arn: &silkbomb_role_arn arn:aws:iam::901841024863:role/silkbomb
- command: subprocess.exec
type: test
display_name: Upload SBOM via Silkbomb
params:
working_dir: src
binary: bash
include_expansions_in_env:
- branch_name
- AWS_ACCESS_KEY_ID
- AWS_SECRET_ACCESS_KEY
- AWS_SESSION_TOKEN
args:
- .evergreen/upload-sbom.sh

"fetch source":
# Executes git clone and applies the submitted patch, if any
- command: git.get_project
Expand Down
24 changes: 24 additions & 0 deletions .evergreen/config/sbom.yml
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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The 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
37 changes: 37 additions & 0 deletions .evergreen/generate-sbom.sh
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
Comment thread
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
Comment thread
jasonhills-mongodb marked this conversation as resolved.

echo "Updating dependencies"
Comment thread
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
Comment thread
jasonhills-mongodb marked this conversation as resolved.
Comment thread
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why --no-validate?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The 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"
18 changes: 18 additions & 0 deletions .evergreen/upload-sbom.sh
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"
Comment thread
jasonhills-mongodb marked this conversation as resolved.
docker pull "${silkbomb}"
Comment thread
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
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
version: 2
updates:
- package-ecosystem: "composer"
directory: "/"
schedule:
interval: "daily"
allow:
- dependency-type: "production"

- package-ecosystem: "github-actions"
directory: "/"
schedule:
Expand Down
85 changes: 0 additions & 85 deletions sbom.json

This file was deleted.

Loading