Skip to content

Commit

Permalink
Allow extra scanners to be configured
Browse files Browse the repository at this point in the history
fixes #109
  • Loading branch information
cdupuis committed Dec 9, 2024
1 parent 747aaae commit 39535d7
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 5 deletions.
1 change: 1 addition & 0 deletions examples/npm-lock/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build/
19 changes: 19 additions & 0 deletions examples/npm-lock/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# syntax=docker/dockerfile:1

# Copyright 2022 buildkit-syft-scanner authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

FROM scratch

COPY package-lock.json /package-lock.json
18 changes: 18 additions & 0 deletions examples/npm-lock/checks/sbom.spdx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"_type": "https://in-toto.io/Statement/v0.1",
"predicateType": "https://spdx.dev/Document",
"predicate": {
"SPDXID": "SPDXRef-DOCUMENT",
"name": "sbom",
"packages": [
{
"SPDXID": "=package",
"name": "lodash"
},
{
"SPDXID": "=package",
"name": "npm"
}
]
}
}
22 changes: 22 additions & 0 deletions examples/npm-lock/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion hack/check-example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ GENERATOR=$1
for example in "${@:2}"; do
example=$(basename "$example")
echo "[-] Building example ${example}..."
docker buildx build "./examples/${example}" --sbom=generator="${GENERATOR}" --output="./examples/${example}/build"

if [[ ${example} == "npm-lock" ]]; then
docker buildx build "./examples/${example}" --sbom="generator=${GENERATOR},SELECT_CATALOGERS=+javascript-lock-cataloger" --output="./examples/${example}/build"
else
docker buildx build "./examples/${example}" --sbom="generator=${GENERATOR}" --output="./examples/${example}/build"
fi


echo "[-] Checking example ${example}..."
for file in "./examples/${example}"/checks/*.json; do
Expand Down
15 changes: 11 additions & 4 deletions internal/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ package internal
import (
"context"
"fmt"
"os"
"path/filepath"
"strings"

"github.com/anchore/syft/syft"
"github.com/anchore/syft/syft/cataloging/pkgcataloging"
Expand All @@ -43,14 +45,19 @@ func (t Target) Scan(ctx context.Context) (sbom.SBOM, error) {
return sbom.SBOM{}, fmt.Errorf("failed to get source from %q: %w", t.Path, err)
}

sr := pkgcataloging.NewSelectionRequest().
WithDefaults(pkgcataloging.ImageTag).
WithAdditions("sbom-cataloger")

if v, ok := os.LookupEnv("BUILDKIT_SCAN_SELECT_CATALOGERS"); ok {
sr = pkgcataloging.NewSelectionRequest().WithExpression(strings.Split(v, ",")...)
}

result, err := syft.CreateSBOM(
ctx,
src,
syft.DefaultCreateSBOMConfig().
WithCatalogerSelection(
pkgcataloging.NewSelectionRequest().
WithDefaults(pkgcataloging.ImageTag).
WithAdditions("sbom-cataloger")))
WithCatalogerSelection(sr))
if err != nil {
return sbom.SBOM{}, err
}
Expand Down

0 comments on commit 39535d7

Please sign in to comment.