Skip to content

Commit 95e6555

Browse files
author
Ian Lewis
authored
docs: Add docs for npm package verification (#587)
Signed-off-by: Ian Lewis <[email protected]>
1 parent 3a4e992 commit 95e6555

File tree

5 files changed

+680
-5
lines changed

5 files changed

+680
-5
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.idea
2+
node_modules
23
vendor

Makefile

+24
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ help: ## Shows all targets and help from the Makefile (this message).
1717
} \
1818
}'
1919

20+
node_modules/.installed: package.json package-lock.json
21+
npm ci
22+
touch node_modules/.installed
23+
2024
## Testing
2125
#####################################################################
2226

@@ -32,6 +36,26 @@ regression-test: ## Runs all regression and unit tests.
3236
# NOTE: go test builds packages even if there are no tests.
3337
go test -mod=vendor -tags=regression -v -timeout=25m ./...
3438

39+
## Tools
40+
#####################################################################
41+
42+
.PHONY: markdown-toc
43+
markdown-toc: node_modules/.installed ## Runs markdown-toc on markdown files.
44+
@# NOTE: Do not include issue templates since they contain Front Matter.
45+
@# markdown-toc will update Front Matter even if there is no TOC in the file.
46+
@# See: https://github.com/jonschlinkert/markdown-toc/issues/151
47+
@set -euo pipefail; \
48+
md_files=$$( \
49+
find . -name '*.md' -type f \
50+
-not -iwholename '*/.git/*' \
51+
-not -iwholename '*/vendor/*' \
52+
-not -iwholename '*/node_modules/*' \
53+
-not -iwholename '*/.github/ISSUE_TEMPLATE/*' \
54+
); \
55+
for filename in $${md_files}; do \
56+
npm run markdown-toc "$${filename}"; \
57+
done;
58+
3559
## Linters
3660
#####################################################################
3761

README.md

+75-5
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
- [Compilation from source](#compilation-from-source)
2121
- [Option 1: Install via go](#option-1-install-via-go)
2222
- [Option 2: Compile manually](#option-2-compile-manually)
23-
- [Use the installer Action on GitHub](#use-the-installer-action-on-github-actions)
23+
- [Use the installer Action on GitHub Actions](#use-the-installer-action-on-github-actions)
2424
- [Download the binary](#download-the-binary)
2525
- [Available options](#available-options)
2626
- [Option list](#option-list)
@@ -31,6 +31,9 @@
3131
- [Verification for Google Cloud Build](#verification-for-google-cloud-build)
3232
- [Artifacts](#artifacts-1)
3333
- [Containers](#containers-1)
34+
- [Verification for npm packages](#verification-for-npm-packages)
35+
- [The verify-npm-package command](#the-verify-npm-package-command)
36+
- [Verify npm packages built using the SLSA3 Node.js builder](#verify-npm-packages-built-using-the-slsa3-nodejs-builder)
3437
- [Known Issues](#known-issues)
3538
- [tuf: invalid key](#tuf-invalid-key)
3639
- [panic: assignment to entry in nil map](#panic-assignment-to-entry-in-nil-map)
@@ -217,11 +220,17 @@ Verified build using builder https://github.com/slsa-framework/slsa-github-gener
217220
PASSED: Verified SLSA provenance
218221
```
219222

220-
The verified in-toto statement may be written to stdout with the `--print-provenance` flag to pipe into policy engines.
223+
The verified in-toto statement may be written to stdout with the
224+
`--print-provenance` flag to pipe into policy engines.
221225

222-
Only GitHub URIs are supported with the `--source-uri` flag. A tag should not be specified, even if the provenance was built at some tag. If you intend to do source versioning validation, use `--print-provenance` and inspect the commit SHA of the config source or materials.
226+
Only GitHub URIs are supported with the `--source-uri` flag. A tag should not
227+
be specified, even if the provenance was built at some tag. If you intend to do
228+
source versioning validation, you can use `--source-tag` to validate the
229+
release tag. For commit SHA validation, use `--print-provenance` and inspect
230+
the commit SHA of the config source or materials.
223231

224-
Multiple artifacts built from the same GitHub builder can be verified in the same command, by passing them in the same command line as arguments:
232+
Multiple artifacts built from the same GitHub builder can be verified in the
233+
same command, by passing them in the same command line as arguments:
225234

226235
```bash
227236
$ slsa-verifier verify-artifact \
@@ -316,10 +325,71 @@ You should see that the verification passed in the output.
316325
PASSED: Verified SLSA provenance
317326
```
318327

319-
The verified in-toto statement may be written to stdout with the `--print-provenance` flag to pipe into policy engines.
328+
The verified in-toto statement may be written to stdout with the
329+
`--print-provenance` flag to pipe into policy engines.
320330

321331
Note that `--source-uri` supports GitHub repository URIs like `github.com/$OWNER/$REPO` when the build was enabled with a Cloud Build [GitHub trigger](https://cloud.google.com/build/docs/automating-builds/github/build-repos-from-github). Otherwise, the build provenance will contain the name of the Cloud Storage bucket used to host the source files, usually of the form `gs://[PROJECT_ID]_cloudbuild/source` (see [Running build](https://cloud.google.com/build/docs/running-builds/submit-build-via-cli-api#running_builds)). We recommend using GitHub triggers in order to preserve the source provenance and valiate that the source came from an expected, version-controlled repository. You _may_ match on the fully-qualified tar like `gs://[PROJECT_ID]_cloudbuild/source/1665165360.279777-955d1904741e4bbeb3461080299e929a.tgz`.
322332

333+
## Verification for npm packages
334+
335+
Verification of npm packages is currently an experimental feature.
336+
337+
### The verify-npm-package command
338+
339+
```bash
340+
$ slsa-verifier verify-npm-package --help
341+
Verifies SLSA provenance for an npm package tarball [experimental]
342+
343+
Usage:
344+
slsa-verifier verify-npm-package [flags] tarball
345+
346+
Flags:
347+
--attestations-path string path to a file containing the attestations
348+
--build-workflow-input map[] [optional] a workflow input provided by a user at trigger time in the format 'key=value'. (Only for 'workflow_dispatch' events on GitHub Actions). (default map[])
349+
--builder-id string [optional] the unique builder ID who created the provenance
350+
-h, --help help for verify-npm-package
351+
--package-name string [optional] the package name
352+
--package-version string [optional] the package version
353+
--print-provenance [optional] print the verified provenance to stdout
354+
--source-branch string [optional] expected branch the binary was compiled from
355+
--source-tag string [optional] expected tag the binary was compiled from
356+
--source-uri string expected source repository that should have produced the binary, e.g. github.com/some/repo
357+
--source-versioned-tag string [optional] expected version the binary was compiled from. Uses semantic version to match the tag
358+
```
359+
360+
### Verify npm packages built using the SLSA3 Node.js builder
361+
362+
This section describes how to verify packages built using the SLSA Build L3
363+
[Node.js builder](https://github.com/slsa-framework/slsa-github-generator/blob/main/internal/builders/nodejs/README.md).
364+
365+
To verify a npm packages, first download the package tarball and attestations.
366+
367+
```shell
368+
curl -Sso attestations.json $(npm view @ianlewis/[email protected] --json | jq -r '.dist.attestations.url') && \
369+
curl -Sso actions-test.tgz "$(npm view @ianlewis/[email protected] --json | jq -r '.dist.tarball')"
370+
```
371+
372+
You can then verify the package by running the following command:
373+
374+
```shell
375+
$ SLSA_VERIFIER_EXPERIMENTAL=1 slsa-verifier verify-npm-package actions-test.tgz \
376+
--attestations-path attestations.json \
377+
--builder-id "https://github.com/slsa-framework/slsa-github-generator/.github/workflows/builder_nodejs_slsa3.yml" \
378+
--package-name "@ianlewis/actions-test" \
379+
--package-version 0.1.126 \
380+
--source-uri github.com/ianlewis/actions-test
381+
```
382+
383+
The verified in-toto statement may be written to stdout with the
384+
`--print-provenance` flag to pipe into policy engines.
385+
386+
Only GitHub URIs are supported with the `--source-uri` flag. A tag should not
387+
be specified, even if the provenance was built at some tag. If you intend to do
388+
source versioning validation, you can use `--source-tag` to validate the
389+
release tag and `--package-version` to validate the package version. For commit
390+
SHA validation, use `--print-provenance` and inspect the commit SHA of the
391+
config source or materials.
392+
323393
## Known Issues
324394

325395
### tuf: invalid key

0 commit comments

Comments
 (0)