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 <[email protected]>
  • Loading branch information
knqyf263 committed Apr 24, 2024
1 parent 9aa9e17 commit e47fd48
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
21 changes: 21 additions & 0 deletions integration/testdata/fixtures/sbom/minikube-kbom.json
Original file line number Diff line number Diff line change
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
8 changes: 7 additions & 1 deletion pkg/sbom/io/decode.go
Original file line number Diff line number Diff line change
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 @@ -107,11 +108,16 @@ func (m *Decoder) decodeRoot(s *types.SBOM) error {
}

func (m *Decoder) decodeComponents(sbom *types.SBOM) error {
onceMultiOSWarn := sync.OnceFunc(func() {
log.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 e47fd48

Please sign in to comment.