Skip to content

Commit ab0245b

Browse files
committed
Add support for direct deps
1 parent e47b58c commit ab0245b

File tree

6 files changed

+205
-57
lines changed

6 files changed

+205
-57
lines changed

README.md

+69-28
Original file line numberDiff line numberDiff line change
@@ -26,57 +26,70 @@
2626
```sh
2727
go install github.com/interlynk-io/sbomgr@latest
2828
```
29+
2930
other installations [options](#installation)
3031

3132
# SBOM Card
32-
[![SBOMCard](https://api.interlynk.io/api/v1/badges?type=hcard&project_group_id=e8e2ba0c-3d04-4a2e-9b37-dca774bd08bd
33-
)](https://app.interlynk.io/customer/products?id=e8e2ba0c-3d04-4a2e-9b37-dca774bd08bd&signed_url_params=eyJfcmFpbHMiOnsibWVzc2FnZSI6IklqSmtaakkyTkRRMUxXSTBaR0V0TkdJME9TMWhPVFpqTFRBd09UZGtZMlptTWpabU9TST0iLCJleHAiOm51bGwsInB1ciI6InNoYXJlX2x5bmsvc2hhcmVfbHluayJ9fQ==--6d74d14e40d6676522b1c529d44e4a320f05bcf3d42121e61e1275a1297a3453)
33+
34+
[![SBOMCard](https://api.interlynk.io/api/v1/badges?type=hcard&project_group_id=e8e2ba0c-3d04-4a2e-9b37-dca774bd08bd)](https://app.interlynk.io/customer/products?id=e8e2ba0c-3d04-4a2e-9b37-dca774bd08bd&signed_url_params=eyJfcmFpbHMiOnsibWVzc2FnZSI6IklqSmtaakkyTkRRMUxXSTBaR0V0TkdJME9TMWhPVFpqTFRBd09UZGtZMlptTWpabU9TST0iLCJleHAiOm51bGwsInB1ciI6InNoYXJlX2x5bmsvc2hhcmVfbHluayJ9fQ==--6d74d14e40d6676522b1c529d44e4a320f05bcf3d42121e61e1275a1297a3453)
3435

3536
# Basic usage
37+
3638
Search for packages with exact name matching "abbrev".
39+
3740
```sh
3841
sbomgr packages -N 'abbrev' <sbom file or dir>
3942
```
4043

4144
Search for packages with regexp name matching "log4"
45+
4246
```sh
4347
sbomgr packages -EN 'log4' <sbom file or dir>
4448
```
4549

4650
Search for packages in air gapped environment for name matching "log4"
51+
4752
```sh
4853
export INTERLYNK_DISABLE_VERSION_CHECK=true sbomgr packages -EN 'log4' <sbom file or dir>
4954
```
55+
5056
# Features
57+
5158
- SBOM format agnostic and currently supports searching through SPDX and CycloneDX.
5259
- Blazing Fast :rocket:
5360
- Output search results as [jsonl](https://jsonlines.org/).
5461
- Supports RE2 [regular expressions](https://github.com/google/re2/wiki/Syntax)
5562

56-
5763
# Use cases
64+
5865
`sbomgr` can answer some of the most common SBOM use cases by searching an SBOM file or SBOM repository.
5966

6067
#### How many SBOM and packages exist in the repository?
68+
6169
```sh
6270
➜ sbomgr packages -c ~/data/sbom-repo/docker-images
6371
sbom_files_matched: 86
6472
packages_matched: 33556
6573
```
74+
6675
#### Are there packages with `zlib` in the name?
76+
6777
```sh
6878
➜ sbomgr packages -cEN 'zlib' ~/data/sbom-repo/docker-images
6979
sbom_files_matched: 71
7080
packages_matched: 145
7181
```
82+
7283
#### Are there packages with a given checksum?
84+
7385
```sh
7486
➜ sbomgr packages -c -H '5c260231de4f62ee26888776190b4c3fda6cbe14' ~/data/sbom-repo/docker-images
7587
sbom_files_matched: 2
7688
packages_matched: 2
7789
```
7890

7991
#### Create a json report of packages with .zip files
92+
8093
```sh
8194
➜ sbomgr packages -jrE -N '\.zip$' ~/data/ | jq .
8295
{
@@ -96,6 +109,7 @@ packages_matched: 2
96109
```
97110

98111
#### Create a json report of all licenses included in an sbom
112+
99113
```sh
100114
➜ sbomgr packages -jl ~/data/some-sboms/julia.spdx | jq .
101115
{
@@ -116,8 +130,8 @@ packages_matched: 2
116130
},
117131
```
118132
119-
120133
#### During CI check if a malicious package is present??
134+
121135
```sh
122136
➜ sbomgr packages -qN 'abbrev' ~/tmp/app.spdx.json
123137
echo $?
@@ -128,21 +142,26 @@ packages_matched: 2
128142
```
129143
130144
#### extract data using user-defined output
145+
131146
```sh
132147
sbomgr packages -O 'toolv,tooln,pkgn,pkgv' ~/tmp/app.spdx.json
133148
2.0.88 Microsoft.SBOMTool Coordinated Packages 229170
134149
2.0.88 Microsoft.SBOMTool chalk 2.4.2
135150
2.0.88 Microsoft.SBOMTool async-settle 1.0.0
136151
```
152+
137153
#### Using containerized sbomgr
138154
139155
```sh
140156
$docker run [volume-maps] ghcr.io/interlynk-io/sbomgr [command] [options]
141157
```
158+
142159
Example
160+
143161
```sh
144162
$docker run -v ~/interlynk/sbomlc/:/app/sbomlc ghcr.io/interlynk-io/sbomgr packages -c /app/sbomlc
145163
```
164+
146165
```
147166
Unable to find image 'ghcr.io/interlynk-io/sbomgr:latest' locally
148167
latest: Pulling from interlynk-io/sbomgr
@@ -160,28 +179,37 @@ Matching package count: 716953
160179
# Search flags
161180
162181
## Packages
182+
163183
This section explains the flags relevant to the packages search feature.
164184
The packages search takes only a single argument, either a file or a directory. There are man flags which can be specified to control its behaviour.
165185
166-
#### *Match Criteria*
186+
#### _Match Criteria_
187+
167188
---
189+
168190
- `-N` or `--name` used for package/component name search.
169191
- `-C` or `--cpe` used for package/component cpe search.
170192
- `-P` or `--purl` used for pacakge/component purl search.
171193
- `-H` or `--checksum` used for package/component checksum value search.
172194
173195
all of these match criteria are exclusive to each other.
174196
175-
#### *Patter Matching*
176-
---------
197+
#### _Patter Matching_
198+
199+
---
200+
177201
- `-E` or `--extended-regexp` flag can be used to indicate if the match criteria is a regular expression. Syntax supported is https://github.com/google/re2/wiki/Syntax.
178202
179-
#### *Matching Control*
180-
-----
203+
#### _Matching Control_
204+
205+
---
206+
181207
- `-i` or `--ignore-case` case insensitive matching.
182208
183-
#### *Output Control*
184-
----
209+
#### _Output Control_
210+
211+
---
212+
185213
- `-l` or `--license` this includes the license of the package/component in the output.
186214
- `-q` or `--quiet` this suppresses all output of the tool, the return value of the tool is 0 indicating success, if it finds the search criteria.
187215
- `--no-filename` removes the filename from the output.
@@ -191,32 +219,40 @@ all of these match criteria are exclusive to each other.
191219
- `filen` - filepath
192220
- `tooln` - tool with which sbom was generated, only prints the first one
193221
- `toolv` - tool version
194-
- `docn` - sbom document name
195-
- `docv` - sbom document version
196-
- `cpe` - package cpe, only prints the first one, indicates how many cpe's exists.
197-
- `purl` - package purl
198-
- `pkgn` - package name
199-
- `pkgv` - package version
200-
- `pkgl` - package licenses
222+
- `docn` - sbom document name
223+
- `docv` - sbom document version
224+
- `cpe` - package cpe, only prints the first one, indicates how many cpe's exists.
225+
- `purl` - package purl
226+
- `pkgn` - package name
227+
- `pkgv` - package version
228+
- `pkgl` - package licenses
201229
- `specn` - spec of the sbom document, spdx or cdx.
202-
- `chkn` - checksum name
203-
- `chkv` - checksum value
204-
- `repo` - repository url
230+
- `chkn` - checksum name
231+
- `chkv` - checksum value
232+
- `repo` - repository url
233+
- `direct` - package is a direct dependency
234+
235+
#### _Stats Control_
236+
237+
---
205238
206-
#### *Stats Control*
207-
----
208239
- `-c` or `--count` suppresses the normal output and print matching counts of sbom filenames and packages.
209240
210-
#### *Directory Control*
211-
----
241+
#### _Directory Control_
242+
243+
---
244+
212245
- `-r` or `--recurse` when set, recursively scans all sub directories.
213246
214-
#### *Spec Control*
215-
----
247+
#### _Spec Control_
248+
249+
---
250+
216251
- `--spdx` searches only files which are SPDX.
217252
- `--cdx` searches only files which are CycloneDX.
218253
219254
# Future work
255+
220256
- Search using files.
221257
- Search using tool metadata.
222258
- Search using CVE-ID.
@@ -225,6 +261,7 @@ all of these match criteria are exclusive to each other.
225261
- Provide a list of malicious packages
226262
227263
# SBOM Samples
264+
228265
- A sample set of SBOM is present in the [samples](https://github.com/interlynk-io/sbomgr/tree/main/samples) directory above.
229266
- [SBOM Benchmark](https://www.sbombenchmark.dev) is a repository of SBOM and quality score for most popular containers and repositories
230267
- [SBOM Explorer](https://github.com/interlynk-io/sbomex) is a command line utility to search and pull SBOMs
@@ -238,6 +275,7 @@ https://github.com/interlynk-io/sbomgr/releases
238275
```
239276
240277
## Using Homebrew
278+
241279
```console
242280
brew tap interlynk-io/interlynk
243281
brew install sbomgr
@@ -258,8 +296,8 @@ This approach involves cloning the repo and building it.
258296
3. make build
259297
4. To test if the build was successful run the following command `./build/sbomgr version`
260298
261-
262299
# Contributions
300+
263301
We look forward to your contributions, below are a few guidelines on how to submit them
264302
265303
- Fork the repo
@@ -269,13 +307,16 @@ We look forward to your contributions, below are a few guidelines on how to subm
269307
- Create a new pull-request
270308
271309
# Other SBOM Open Source tools
310+
272311
- [SBOM Assembler](https://github.com/interlynk-io/sbomasm) - A tool to compose a single SBOM by combining other (part) SBOMs
273312
- [SBOM Quality Score](https://github.com/interlynk-io/sbomqs) - A tool for evaluating the quality and completeness of SBOMs
274313
- [SBOM Search Tool](https://github.com/interlynk-io/sbomagr) - A tool to grep style semantic search in SBOMs
275314
- [SBOM Explorer](https://github.com/interlynk-io/sbomex) - A tool for discovering and downloading SBOM from a public repository
276315
277316
# Contact
317+
278318
We appreciate all feedback. The best ways to get in touch with us:
319+
279320
- :phone: [Live Chat](https://www.interlynk.io/#hs-chat-open)
280321
- 📫 [Email Us](mailto:[email protected])
281322
- 🐛 [Report a bug or enhancement](https://github.com/interlynk-io/sbomex/issues)

pkg/search/cdx/document.go

+38-8
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ import (
2626
)
2727

2828
type cdxDoc struct {
29-
doc *cydx.BOM
30-
ro *options.RuntimeOptions
31-
opts options.SearchOptions
32-
allComps []*cydx.Component
29+
doc *cydx.BOM
30+
ro *options.RuntimeOptions
31+
opts options.SearchOptions
32+
allComps []*cydx.Component
33+
directComps map[string]bool
3334
}
3435

3536
func loadDoc(ro *options.RuntimeOptions, opts options.SearchOptions) (*cdxDoc, error) {
@@ -54,10 +55,11 @@ func loadDoc(ro *options.RuntimeOptions, opts options.SearchOptions) (*cdxDoc, e
5455
}
5556

5657
doc := &cdxDoc{
57-
doc: bom,
58-
ro: ro,
59-
opts: opts,
60-
allComps: extractAllComponents(bom),
58+
doc: bom,
59+
ro: ro,
60+
opts: opts,
61+
allComps: extractAllComponents(bom),
62+
directComps: directComps(bom),
6163
}
6264
return doc, nil
6365
}
@@ -81,6 +83,34 @@ func extractAllComponents(bom *cydx.BOM) []*cydx.Component {
8183
return all_comps
8284
}
8385

86+
func directComps(bom *cydx.BOM) map[string]bool {
87+
directComps := map[string]bool{}
88+
89+
if bom.Dependencies == nil {
90+
return directComps
91+
}
92+
93+
if bom.Metadata == nil {
94+
return directComps
95+
}
96+
97+
if bom.Metadata.Component == nil {
98+
return directComps
99+
}
100+
101+
priRef := bom.Metadata.Component.BOMRef
102+
103+
for _, dep := range *bom.Dependencies {
104+
if dep.Ref == priRef {
105+
for _, depComps := range *dep.Dependencies {
106+
directComps[depComps] = true
107+
}
108+
break
109+
}
110+
}
111+
return directComps
112+
}
113+
84114
func walkComponents(comps *[]cydx.Component, store map[string]*cydx.Component) {
85115
if comps == nil {
86116
return

pkg/search/cdx/results.go

+6
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ func (doc *cdxDoc) pkgResults(pIndices []int) []results.Package {
9393
}
9494
}
9595

96+
if doc.directComps != nil {
97+
if _, ok := doc.directComps[comp.BOMRef]; ok {
98+
res.Direct = true
99+
}
100+
}
101+
96102
if comp.Hashes != nil {
97103
for _, c := range *comp.Hashes {
98104
res.Checksums = append(res.Checksums, results.Checksum{

0 commit comments

Comments
 (0)