Skip to content

Commit

Permalink
fix(sbom): change error to warning for multiple OSes (#6541)
Browse files Browse the repository at this point in the history
Signed-off-by: knqyf263 <knqyf263@gmail.com>
  • Loading branch information
knqyf263 committed Apr 24, 2024
1 parent 164b025 commit d2d4022
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
21 changes: 21 additions & 0 deletions integration/testdata/fixtures/sbom/minikube-kbom.json
Expand Up @@ -48,6 +48,22 @@
}
]
},
{
"bom-ref": "b6f66546-5a5c-4fe8-a30f-acb04013c151",
"type": "operating-system",
"name": "ubuntu",
"version": "22.04.2",
"properties": [
{
"name": "aquasecurity:trivy:Class",
"value": "os-pkgs"
},
{
"name": "aquasecurity:trivy:Type",
"value": "ubuntu"
}
]
},
{
"bom-ref": "a62abb1f-cb38-4fde-90f3-2bda3b87ddb2",
"type": "application",
Expand Down Expand Up @@ -325,6 +341,10 @@
"ref": "5262e708-f1a3-4fca-a1c3-0a8384f7f4a5",
"dependsOn": []
},
{
"ref": "b6f66546-5a5c-4fe8-a30f-acb04013c151",
"dependsOn": []
},
{
"ref": "a62abb1f-cb38-4fde-90f3-2bda3b87ddb2",
"dependsOn": [
Expand All @@ -336,6 +356,7 @@
"ref": "a6350ac3-52f6-4c5f-a3e3-184b9a634bef",
"dependsOn": [
"5262e708-f1a3-4fca-a1c3-0a8384f7f4a5",
"b6f66546-5a5c-4fe8-a30f-acb04013c151",
"a62abb1f-cb38-4fde-90f3-2bda3b87ddb2"
]
},
Expand Down
17 changes: 13 additions & 4 deletions pkg/sbom/io/decode.go
Expand Up @@ -5,6 +5,7 @@ import (
"slices"
"sort"
"strconv"
"sync"

debver "github.com/knqyf263/go-deb-version"
rpmver "github.com/knqyf263/go-rpm-version"
Expand Down Expand Up @@ -32,13 +33,16 @@ type Decoder struct {
osID uuid.UUID
pkgs map[uuid.UUID]*ftypes.Package
apps map[uuid.UUID]*ftypes.Application

logger *log.Logger
}

func NewDecoder(bom *core.BOM) *Decoder {
return &Decoder{
bom: bom,
pkgs: make(map[uuid.UUID]*ftypes.Package),
apps: make(map[uuid.UUID]*ftypes.Application),
bom: bom,
pkgs: make(map[uuid.UUID]*ftypes.Package),
apps: make(map[uuid.UUID]*ftypes.Application),
logger: log.WithPrefix("sbom"),
}
}

Expand Down Expand Up @@ -106,11 +110,16 @@ func (m *Decoder) decodeRoot(s *types.SBOM) error {
}

func (m *Decoder) decodeComponents(sbom *types.SBOM) error {
onceMultiOSWarn := sync.OnceFunc(func() {
m.logger.Warn("Multiple OS components are not supported, taking the first one and ignoring the rest")
})

for id, c := range m.bom.Components() {
switch c.Type {
case core.TypeOS:
if m.osID != uuid.Nil {
return xerrors.New("multiple OS components are not supported")
onceMultiOSWarn()
continue
}
m.osID = id
sbom.Metadata.OS = &ftypes.OS{
Expand Down

0 comments on commit d2d4022

Please sign in to comment.