-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
406 additions
and
503 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed | ||
// under the Apache License Version 2.0. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
// Copyright 2016-present Datadog, Inc. | ||
|
||
//go:build trivy | ||
|
||
// Package trivy holds the scan components | ||
package trivy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed | ||
// under the Apache License Version 2.0. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
// Copyright 2016-present Datadog, Inc. | ||
|
||
//go:build trivy | ||
|
||
// Package trivy holds the scan components | ||
package trivy | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"path/filepath" | ||
|
||
workloadmeta "github.com/DataDog/datadog-agent/comp/core/workloadmeta/def" | ||
"github.com/DataDog/datadog-agent/pkg/sbom" | ||
"github.com/DataDog/datadog-agent/pkg/util/crio" | ||
ftypes "github.com/aquasecurity/trivy/pkg/fanal/types" | ||
v1 "github.com/google/go-containerregistry/pkg/v1" | ||
) | ||
|
||
type fakeCRIOContainer struct { | ||
*fakeContainer | ||
} | ||
|
||
func (c *fakeCRIOContainer) ID() (string, error) { | ||
return c.imgMeta.ID, nil | ||
} | ||
|
||
func (c *fakeCRIOContainer) ConfigFile() (*v1.ConfigFile, error) { | ||
configFile := &v1.ConfigFile{} | ||
for _, layer := range c.imgMeta.Layers { | ||
configFile.History = append(configFile.History, v1.History{ | ||
Author: layer.History.Author, | ||
Created: v1.Time{Time: *layer.History.Created}, | ||
CreatedBy: layer.History.CreatedBy, | ||
Comment: layer.History.Comment, | ||
EmptyLayer: layer.History.EmptyLayer, | ||
}) | ||
|
||
} | ||
return configFile, nil | ||
} | ||
|
||
func (c *fakeCRIOContainer) LayerByDiffID(hash string) (ftypes.LayerPath, error) { | ||
return c.fakeContainer.LayerByDiffID(hash) | ||
} | ||
|
||
func (c *fakeCRIOContainer) LayerByDigest(hash string) (ftypes.LayerPath, error) { | ||
return c.fakeContainer.LayerByDigest(hash) | ||
} | ||
|
||
func (c *fakeCRIOContainer) Layers() (layers []ftypes.LayerPath) { | ||
return c.fakeContainer.Layers() | ||
} | ||
|
||
func (c *fakeCRIOContainer) Name() string { | ||
return c.imgMeta.Name | ||
} | ||
|
||
func (c *fakeCRIOContainer) RepoTags() []string { | ||
return c.imgMeta.RepoTags | ||
} | ||
|
||
func (c *fakeCRIOContainer) RepoDigests() []string { | ||
return c.imgMeta.RepoDigests | ||
} | ||
|
||
// ScanCRIOImageFromOverlayFS scans the CRI-O image layers using OverlayFS. | ||
func (c *Collector) ScanCRIOImageFromOverlayFS(ctx context.Context, imgMeta *workloadmeta.ContainerImageMetadata, client crio.Client, scanOptions sbom.ScanOptions) (sbom.Report, error) { | ||
lowerDirs, err := client.GetCRIOImageLayers(imgMeta) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to retrieve layer directories: %w", err) | ||
} | ||
|
||
var diffIDs []string | ||
for _, dir := range lowerDirs { | ||
diffIDs = append(diffIDs, filepath.Base(filepath.Dir(dir))) | ||
} | ||
|
||
report, err := c.scanOverlayFS(ctx, lowerDirs, &fakeCRIOContainer{ | ||
fakeContainer: &fakeContainer{ | ||
imgMeta: imgMeta, | ||
layerPaths: lowerDirs, | ||
layerIDs: diffIDs, | ||
}, | ||
}, imgMeta, scanOptions) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return report, nil | ||
} |
Oops, something went wrong.