-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add SBOM in sync-request metadata #43
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package legacy | ||
|
||
import ( | ||
"github.com/atomist-skills/go-skill/policy/types" | ||
"olympos.io/encoding/edn" | ||
) | ||
|
||
func BuildLocalEvalMocks(sb *types.SBOM) map[edn.Keyword]edn.RawMessage { | ||
m := map[edn.Keyword]edn.RawMessage{} | ||
if sb == nil { | ||
return m | ||
} | ||
|
||
m[ImagePackagesByDigestQueryName], _ = edn.Marshal(MockImagePackagesByDigestForLocalEval(sb)) | ||
|
||
if sb.Source.Image != nil && sb.Source.Image.Config != nil { | ||
m[GetUserQueryName], _ = edn.Marshal(MockGetUserForLocalEval(sb.Source.Image.Config.Config.User)) | ||
} | ||
|
||
return m | ||
} | ||
|
||
func MockImagePackagesByDigestForLocalEval(sb *types.SBOM) ImagePackagesByDigestResponse { | ||
vulns := map[string][]Vulnerability{} | ||
for _, tuple := range sb.Vulnerabilities { | ||
vulnsForPurl := []Vulnerability{} | ||
for _, v := range tuple.Vulnerabilities { | ||
vulnsForPurl = append(vulnsForPurl, Vulnerability{ | ||
Cvss: Cvss{ | ||
Severity: &v.Cvss.Severity, | ||
Score: &v.Cvss.Score, | ||
}, | ||
FixedBy: &v.FixedBy, | ||
Source: v.Source, | ||
SourceID: v.SourceId, | ||
URL: &v.Url, | ||
VulnerableRange: v.VulnerableRange, | ||
}) | ||
} | ||
vulns[tuple.Purl] = vulnsForPurl | ||
} | ||
|
||
pkgs := []Packages{} | ||
for _, a := range sb.Artifacts { | ||
pkgs = append(pkgs, Packages{ | ||
Package: PackageWithLicenses{ | ||
Licenses: a.Licenses, | ||
Name: a.Name, | ||
Namespace: &a.Namespace, | ||
Version: a.Version, | ||
Purl: a.Purl, | ||
Type: a.Type, | ||
Vulnerabilities: vulns[a.Purl], | ||
}, | ||
}) | ||
} | ||
|
||
return ImagePackagesByDigestResponse{ | ||
ImagePackagesByDigest: &ImagePackagesByDigest{ | ||
ImagePackages: ImagePackages{ | ||
Packages: pkgs, | ||
}, | ||
}, | ||
} | ||
} |
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,99 @@ | ||
package legacy | ||
|
||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
"github.com/atomist-skills/go-skill/policy/types" | ||
v1 "github.com/google/go-containerregistry/pkg/v1" | ||
"olympos.io/encoding/edn" | ||
) | ||
|
||
func Test_BuildLocalEvalMocks(t *testing.T) { | ||
type args struct { | ||
sb *types.SBOM | ||
} | ||
tests := []struct { | ||
name string | ||
args args | ||
want map[edn.Keyword]edn.RawMessage | ||
}{ | ||
{ | ||
name: "Without SBOM", | ||
args: args{ | ||
sb: nil, | ||
}, | ||
want: map[edn.Keyword]edn.RawMessage{}, | ||
}, | ||
{ | ||
name: "With SBOM", | ||
args: args{ | ||
sb: &types.SBOM{ | ||
Source: types.Source{ | ||
Image: &types.ImageSource{ | ||
Config: &v1.ConfigFile{ | ||
Config: v1.Config{ | ||
User: "root", | ||
}, | ||
}, | ||
}, | ||
}, | ||
Artifacts: []types.Package{ | ||
{ | ||
Name: "pkg1", | ||
}, | ||
}, | ||
}, | ||
}, | ||
want: map[edn.Keyword]edn.RawMessage{ | ||
"image-packages-by-digest": []byte(`{:imagePackagesByDigest{:imagePackages{:packages[{:package{:licenses nil :name"pkg1":namespace"":version"":purl"":type"":vulnerabilities nil}}]}}}`), | ||
"get-user": []byte(`{:docker.image/user"root"}`), | ||
}, | ||
}, | ||
{ | ||
name: "SBOM without image source", | ||
args: args{ | ||
sb: &types.SBOM{ | ||
Source: types.Source{ | ||
Image: nil, | ||
}, | ||
Artifacts: []types.Package{ | ||
{ | ||
Name: "pkg1", | ||
}, | ||
}, | ||
}, | ||
}, | ||
want: map[edn.Keyword]edn.RawMessage{ | ||
"image-packages-by-digest": []byte(`{:imagePackagesByDigest{:imagePackages{:packages[{:package{:licenses nil :name"pkg1":namespace"":version"":purl"":type"":vulnerabilities nil}}]}}}`), | ||
}, | ||
}, | ||
{ | ||
name: "SBOM without image config file", | ||
args: args{ | ||
sb: &types.SBOM{ | ||
Source: types.Source{ | ||
Image: &types.ImageSource{ | ||
Config: nil, | ||
}, | ||
}, | ||
Artifacts: []types.Package{ | ||
{ | ||
Name: "pkg1", | ||
}, | ||
}, | ||
}, | ||
}, | ||
want: map[edn.Keyword]edn.RawMessage{ | ||
"image-packages-by-digest": []byte(`{:imagePackagesByDigest{:imagePackages{:packages[{:package{:licenses nil :name"pkg1":namespace"":version"":purl"":type"":vulnerabilities nil}}]}}}`), | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if got := BuildLocalEvalMocks(tt.args.sb); !reflect.DeepEqual(got, tt.want) { | ||
t.Errorf("BuildLocalEvalMocks() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
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,15 @@ | ||
package legacy | ||
|
||
const ( | ||
GetUserQueryName = "get-user" | ||
) | ||
|
||
type DockerImageUser struct { | ||
ImageUser string `edn:"docker.image/user,omitempty"` | ||
} | ||
|
||
func MockGetUserForLocalEval(user string) DockerImageUser { | ||
return DockerImageUser{ | ||
ImageUser: user, | ||
} | ||
} |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is already handled in this package here, do we specifically need to pass the sbom from the cli tool to the evaluator?
Fwiw, scout-cli-plugin also already does this mock, which takes precedence in go-skill if passed (so if the fields need to be expanded we can update scout-cli-plugin once instead of updating this repo and all policy repos).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we would like to use the existing
SBOM
struct as a standardised API for synchronous policy evaluation.That struct encapsulates basically all the useful information that we have about a given image, so we can make changes to policies and introduce new policies without needing to rely on any CLI changes to pass new data.
It also gives us a way of getting local attestations (with the help of containerd) into policy evaluation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I see the idea now. And now that I think about it, I agree it's the right move as well.
Two follow-up thoughts then:
scout-cli-plugin
as we are given opportunities to, so that we don't end up holding onto them for some cross-project version combinations.non-root-user-skill
, so we'll need to hold onto it for a while as well.scout-cli-plugin
that I linked above is not used by any released skills, to my knowledge. Once this PR is merged, I'll make surepolicy-vulnerabilities
is updated to use the SBOM version, and the mock is removed.