Skip to content

Commit

Permalink
Tests for new retrieve full uris in grafeas
Browse files Browse the repository at this point in the history
  • Loading branch information
renzodavid9 committed Jun 6, 2024
1 parent 945c0a4 commit 47c808b
Show file tree
Hide file tree
Showing 7 changed files with 293 additions and 10 deletions.
3 changes: 2 additions & 1 deletion pkg/chains/formats/simple/simple.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func (i *SimpleSigning) Type() config.PayloadType {
return formats.PayloadTypeSimpleSigning
}

func (i *SimpleSigning) RetrieveAllArtifactURIs(ctx context.Context, obj interface{}) ([]string, error) {
// RetrieveAllArtifactURIs returns always an error, feature not available for simplesigning formatter.
func (i *SimpleSigning) RetrieveAllArtifactURIs(_ context.Context, _ interface{}) ([]string, error) {
return nil, fmt.Errorf("RetrieveAllArtifactURIs not supported for simeplesining formatter")
}
1 change: 1 addition & 0 deletions pkg/chains/formats/slsa/v1/intotoite6.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ func (i *InTotoIte6) Type() config.PayloadType {
return formats.PayloadTypeSlsav1
}

// RetrieveAllArtifactURIs returns the full URI of all artifacts detected as subjects.
func (i *InTotoIte6) RetrieveAllArtifactURIs(ctx context.Context, obj interface{}) ([]string, error) {
tkObj, ok := obj.(objects.TektonObject)
if !ok {
Expand Down
1 change: 1 addition & 0 deletions pkg/chains/formats/slsa/v2alpha3/slsav2.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func (s *Slsa) Type() config.PayloadType {
return formats.PayloadTypeSlsav2alpha3
}

// RetrieveAllArtifactURIs returns the full URI of all artifacts detected as subjects.
func (s *Slsa) RetrieveAllArtifactURIs(ctx context.Context, obj interface{}) ([]string, error) {
tkObj, ok := obj.(objects.TektonObject)
if !ok {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func byproducts(pro *objects.PipelineRunObjectV1, slsaconfig *slsaconfig.SlsaCon
return byProd, nil
}

// SubjectDigests calculates the subjects associated with the given PipelineRun.
func SubjectDigests(ctx context.Context, pro *objects.PipelineRunObjectV1, slsaconfig *slsaconfig.SlsaConfig) []*intoto.ResourceDescriptor {
subjects := extract.SubjectsFromBuildArtifact(ctx, pro.GetResults())

Expand Down
1 change: 1 addition & 0 deletions pkg/chains/formats/slsa/v2alpha4/slsav2.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func (s *Slsa) Type() config.PayloadType {
return payloadTypeSlsav2alpha4
}

// RetrieveAllArtifactURIs returns the full URI of all artifacts detected as subjects.
func (s *Slsa) RetrieveAllArtifactURIs(ctx context.Context, obj interface{}) ([]string, error) {
var subjects []*intoto.ResourceDescriptor
var fullURIs []string
Expand Down
5 changes: 4 additions & 1 deletion pkg/chains/storage/grafeas/grafeas.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,15 +265,18 @@ func (b *Backend) createOccurrence(ctx context.Context, obj objects.TektonObject
}

func (b *Backend) getAllArtifactURIs(ctx context.Context, payloadFormat config.PayloadType, obj objects.TektonObject) []string {
logger := logging.FromContext(ctx)
payloader, err := formats.GetPayloader(payloadFormat, b.cfg)
if err != nil {
logger.Infof("couldn't get payloader for %v format, will use extract.RetrieveAllArtifactURIs method instead", payloadFormat)
return extract.RetrieveAllArtifactURIs(ctx, obj, b.cfg.Artifacts.PipelineRuns.DeepInspectionEnabled)
}

if uris, err := payloader.RetrieveAllArtifactURIs(ctx, obj); err == nil {
return uris
}

logger.Infof("couldn't get URIs from payloader %v, will use extract.RetrieveAllArtifactURIs method instead", payloadFormat)
return extract.RetrieveAllArtifactURIs(ctx, obj, b.cfg.Artifacts.PipelineRuns.DeepInspectionEnabled)
}

Expand Down Expand Up @@ -377,7 +380,7 @@ func (b *Backend) getBuildNotePath(obj objects.TektonObject) string {
func (b *Backend) getAllOccurrences(ctx context.Context, obj objects.TektonObject, opts config.StorageOpts) ([]*pb.Occurrence, error) {
result := []*pb.Occurrence{}
// step 1: get all resource URIs created under the taskrun
uriFilters := extract.RetrieveAllArtifactURIs(ctx, obj, b.cfg.Artifacts.PipelineRuns.DeepInspectionEnabled)
uriFilters := b.getAllArtifactURIs(ctx, opts.PayloadFormat, obj)

// step 2: find all build occurrences
if _, ok := formats.IntotoAttestationSet[opts.PayloadFormat]; ok {
Expand Down
Loading

0 comments on commit 47c808b

Please sign in to comment.