Skip to content

Commit de60ed2

Browse files
alcaeusjmikola
andauthored
PHPC-2380: Add SBOM file and tooling to update it (#1577)
* Add SBOM file and script for updating it * Update instructions for updating bundled code * Apply suggestions from code review Co-authored-by: Jeremy Mikola <[email protected]> * Improve instructions to update SBOM --------- Co-authored-by: Jeremy Mikola <[email protected]>
1 parent 74e4459 commit de60ed2

File tree

4 files changed

+180
-54
lines changed

4 files changed

+180
-54
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,6 @@ mongodb-*tgz
6767

6868
# Coverage files
6969
coverage*
70+
71+
# temporary purls file
72+
/purls.txt

CONTRIBUTING.md

Lines changed: 61 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -182,63 +182,72 @@ a 1.23.1 tag also existed at the time. The bump to libmongoc 1.23.1 was left to
182182
another PHPC ticket in the 1.15.0 milestone, which actually depended on the
183183
libmongoc changes therein.
184184

185-
### Updating libmongoc and libbson
185+
### Updating bundled libraries
186186

187-
#### Update libmongoc submodule
187+
The following steps are the same for libmongoc and libmongocrypt. When updating
188+
libmongocrypt, follow the same steps but replace `libmongoc` with
189+
`libmongocrypt`, retaining the same capitalization. The following examples
190+
always refer to libmongoc.
188191

189-
```
190-
$ cd src/libmongoc
191-
$ git fetch
192-
$ git checkout 1.20.0
192+
#### Update submodule
193+
194+
```shell
195+
cd src/libmongoc
196+
git fetch
197+
git checkout 1.20.0
193198
```
194199

195-
During development, it may be necessary to temporarily point the libmongoc
196-
submodule to a commit on the developer's fork of libmongoc. For instance, the
197-
developer may be working on a PHP driver feature that depends on an unmerged
198-
pull request to libmongoc. In this case, `git remote add` can be used to add
199-
the fork before fetching and checking out the target commit. Additionally, the
200-
submodule path in
201-
[`.gitmodules`](https://github.com/mongodb/mongo-php-driver/blob/master/.gitmodules)
202-
must also be updated to refer to the fork.
200+
During development, it may be necessary to temporarily point the submodule to a
201+
commit on the developer's fork. For instance, the developer may be working on a
202+
PHP driver feature that depends on unmerged or unreleased changes. In this case,
203+
the submodule path can be updated using the `git submodules set-url` command can
204+
be used to change the URL, and `git submodules set-branch` can be used to point
205+
the submodule to a development branch:
203206

204-
#### Ensure libmongoc version information is correct
207+
```shell
208+
git submodules set-url src/libmongoc https://github.com/<owner>/<repo>.git
209+
git submodules set-branch -b <branch> src/libmongoc
210+
```
205211

206-
The build process for Autotools and Windows rely on
207-
`src/LIBMONGOC_VERSION_CURRENT` to infer version information for libmongoc and
208-
libbson. This file can be regenerated using the following Makefile target:
212+
#### Ensure version information is correct
209213

210-
```
211-
$ make libmongoc-version-current
214+
Various build processes and tools rely on the version files to infer version
215+
information. This file can be regenerated using Makefile targets:
216+
217+
```shell
218+
make libmongoc-version-current
212219
```
213220

214-
Alternatively, the `build/calc_release_version.py` script in libmongoc can be
215-
executed directly.
221+
Alternatively, the `build/calc_release_version.py` script in the submodule can
222+
be executed directly.
216223

217-
Note: If the libmongoc submodule points to a non-release, non-master branch, the
218-
script may fail to correctly detect the version. This issue is being tracked in
219-
[CDRIVER-3315](https://jira.mongodb.org/browse/CDRIVER-3315) and can be safely
220-
ignored since this should only happen during development (any PHP driver release
221-
should point to a tagged libmongoc release).
224+
Note: If the submodule points to a non-release, non-master branch, the script
225+
may fail to correctly detect the version. This issue is being tracked in
226+
[CDRIVER-3315](https://jira.mongodb.org/browse/CDRIVER-3315) and can be safely ignored since this should only happen
227+
during development (any PHP driver release should point to a tagged submodule
228+
version).
222229

223230
#### Update sources in build configurations
224231

225232
The Autotools and Windows build configurations (`config.m4` and `config.w32`,
226233
respectively) define several variables (e.g. `PHP_MONGODB_MONGOC_SOURCES`) that
227-
collectively enumerate all of the the sources within the libmongoc submodule to
228-
include in a bundled build.
234+
collectively enumerate all of the sources within the submodules to include in a
235+
bundled build.
229236

230237
These variables should each have a shell command in a preceding comment, which
231238
should be run to regenerate that particular list of source files. Each command
232239
may be run manually or `scripts/update-submodule-sources.php` may be used to
233-
update all variables. In the event that either libmongoc or libbson introduce a
234-
new source directory, that will need to be manually added (follow prior art).
240+
update all variables. In the event that a new source directory is introduced,
241+
this directory will need to be manually added following prior art.
235242

236243
#### Update package dependencies
237244

238245
The Autotools configuration additionally includes some `pkg-config` commands for
239-
using libmongoc and libbson as system libraries (in lieu of a bundled build).
240-
When bumping the libmongoc version, be sure to update the version check _and_
241-
error message in the `pkg-config` blocks for both libmongoc and libbson.
246+
using libmongoc, libbson, and libmongocrypt as system libraries (in lieu of a
247+
bundled build). When bumping the bundled version, be sure to update the version
248+
check _and_ error message in the `pkg-config` blocks for the submodule being
249+
updated. When updating libmongoc, be sure to update both version checks for
250+
libmongoc and libbson.
242251

243252
For example, the following lines might be updated for libmongoc:
244253

@@ -250,7 +259,7 @@ if $PKG_CONFIG libmongoc-1.0 --atleast-version 1.20.0; then
250259
AC_MSG_ERROR(system libmongoc must be upgraded to version >= 1.20.0)
251260
```
252261

253-
#### Update tested versions in Evergreen configuration
262+
#### Update tested versions in Evergreen configuration (libmongoc only)
254263

255264
Evergreen tests against multiple versions of libmongoc. When updating to a newer
256265
libmongoc version, make sure to update the libmongoc build tasks in `.evergreen/config/templates/build/build-libmongoc.yml`
@@ -264,32 +273,30 @@ against two additional versions of libmongoc:
264273

265274
#### Update sources in PECL package generation script
266275

267-
If either libmongoc or libbson introduce a new source directory, that may also
276+
If a new version of a submodule introduces a new source directory, that may also
268277
require updating the glob patterns in the `bin/prep-release.php` script to
269278
ensure new source files will be included in any generated PECL package.
270279

271-
#### Test and commit your changes
280+
#### Update SBOM file
272281

273-
Verify that the upgrade was successful by ensuring that the driver can compile
274-
using both the bundled sources and system libraries for libmongoc and libbson,
275-
and by ensuring that the test suite passes. Once done, commit the changes to all
276-
of the above files/paths. For example:
282+
After updating dependencies, the SBOM file needs to be updated. There is a
283+
script to automate this process:
277284

278-
```
279-
$ git commit -m "Bump libmongoc to 1.20.0" config.m4 config.w32 src/libmongoc src/LIBMONGOC_VERSION_CURRENT
285+
```shell
286+
./scripts/update-sbom.sh
280287
```
281288

282-
### Updating libmongocrypt
289+
This script will generate a temporary purl file with our dependencies, then run
290+
the internal silkbomb tool to update the SBOM. Note that you need to have docker
291+
installed in order to run this.
283292

284-
To update libmongocrypt, the steps are similar to the above:
293+
#### Test and commit your changes
285294

286-
```
287-
$ cd src/libmongocrypt
288-
$ git fetch
289-
$ git checkout 1.3.0
290-
$ make libmongocrypt-version-current
291-
```
295+
Verify that the upgrade was successful by ensuring that the driver can compile
296+
using both the bundled sources and system libraries, and by ensuring that the
297+
test suite passes. Once done, commit the changes to all of the above
298+
files/paths. For example:
292299

293-
Package dependencies in `config.m4` must also be updated (either manually or
294-
with `scripts/update-submodule-sources.php`), as do the sources in the PECL
295-
generation script.
300+
```shell
301+
git commit -m "Bump libmongoc to 1.20.0" config.m4 config.w32 src/libmongoc src/LIBMONGOC_VERSION_CURRENT sbom.json
302+
```

sbom.json

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
{
2+
"components": [
3+
{
4+
"bom-ref": "pkg:github/mongodb/[email protected]",
5+
"externalReferences": [
6+
{
7+
"type": "distribution",
8+
"url": "https://github.com/mongodb/libmongocrypt/archive/refs/tags/1.10.0.tar.gz"
9+
},
10+
{
11+
"type": "website",
12+
"url": "https://github.com/mongodb/libmongocrypt/tree/1.10.0"
13+
}
14+
],
15+
"group": "mongodb",
16+
"name": "libmongocrypt",
17+
"purl": "pkg:github/mongodb/[email protected]",
18+
"type": "library",
19+
"version": "1.10.0"
20+
},
21+
{
22+
"bom-ref": "pkg:github/mongodb/[email protected]",
23+
"externalReferences": [
24+
{
25+
"type": "distribution",
26+
"url": "https://github.com/mongodb/mongo-c-driver/archive/refs/tags/1.27.2.tar.gz"
27+
},
28+
{
29+
"type": "website",
30+
"url": "https://github.com/mongodb/mongo-c-driver/tree/1.27.2"
31+
}
32+
],
33+
"group": "mongodb",
34+
"name": "mongo-c-driver",
35+
"purl": "pkg:github/mongodb/[email protected]",
36+
"type": "library",
37+
"version": "1.27.2"
38+
}
39+
],
40+
"dependencies": [
41+
{
42+
"ref": "pkg:github/mongodb/[email protected]"
43+
},
44+
{
45+
"ref": "pkg:github/mongodb/[email protected]"
46+
}
47+
],
48+
"metadata": {
49+
"timestamp": "2024-06-06T07:13:52.679415+00:00",
50+
"tools": [
51+
{
52+
"externalReferences": [
53+
{
54+
"type": "build-system",
55+
"url": "https://github.com/CycloneDX/cyclonedx-python-lib/actions"
56+
},
57+
{
58+
"type": "distribution",
59+
"url": "https://pypi.org/project/cyclonedx-python-lib/"
60+
},
61+
{
62+
"type": "documentation",
63+
"url": "https://cyclonedx-python-library.readthedocs.io/"
64+
},
65+
{
66+
"type": "issue-tracker",
67+
"url": "https://github.com/CycloneDX/cyclonedx-python-lib/issues"
68+
},
69+
{
70+
"type": "license",
71+
"url": "https://github.com/CycloneDX/cyclonedx-python-lib/blob/main/LICENSE"
72+
},
73+
{
74+
"type": "release-notes",
75+
"url": "https://github.com/CycloneDX/cyclonedx-python-lib/blob/main/CHANGELOG.md"
76+
},
77+
{
78+
"type": "vcs",
79+
"url": "https://github.com/CycloneDX/cyclonedx-python-lib"
80+
},
81+
{
82+
"type": "website",
83+
"url": "https://github.com/CycloneDX/cyclonedx-python-lib/#readme"
84+
}
85+
],
86+
"name": "cyclonedx-python-lib",
87+
"vendor": "CycloneDX",
88+
"version": "6.4.4"
89+
}
90+
]
91+
},
92+
"serialNumber": "urn:uuid:acb30d08-ee47-4ff0-b301-d66ef1f54082",
93+
"version": 1,
94+
"$schema": "http://cyclonedx.org/schema/bom-1.5.schema.json",
95+
"bomFormat": "CycloneDX",
96+
"specVersion": "1.5"
97+
}

scripts/update-sbom.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
3+
SCRIPT_DIR=$(dirname ${BASH_SOURCE[0]})
4+
ROOT_DIR=$(realpath "${SCRIPT_DIR}/../")
5+
PURLS_FILE="${ROOT_DIR}/purls.txt"
6+
7+
LIBMONGOC_VERSION=$(cat ${ROOT_DIR}/src/LIBMONGOC_VERSION_CURRENT | tr -d '[:space:]')
8+
LIBMONGOCRYPT_VERSION=$(cat ${ROOT_DIR}/src/LIBMONGOCRYPT_VERSION_CURRENT | tr -d '[:space:]')
9+
10+
# Generate purls file from stored versions
11+
echo "pkg:github/mongodb/mongo-c-driver@${LIBMONGOC_VERSION}" > $PURLS_FILE
12+
echo "pkg:github/mongodb/libmongocrypt@${LIBMONGOCRYPT_VERSION}" >> $PURLS_FILE
13+
14+
# Use silkbomb to update the sbom.json file
15+
docker run --platform="linux/amd64" -it --rm -v ${ROOT_DIR}:/pwd \
16+
artifactory.corp.mongodb.com/release-tools-container-registry-public-local/silkbomb:1.0 \
17+
update --sbom-in /pwd/sbom.json --purls /pwd/purls.txt --sbom-out /pwd/sbom.json
18+
19+
rm $PURLS_FILE

0 commit comments

Comments
 (0)