Skip to content

Commit

Permalink
Use FROM_RUNTIME instruction to check for max mode provenance instead
Browse files Browse the repository at this point in the history
  • Loading branch information
felipecruz91 committed Jan 31, 2024
1 parent 525e535 commit 7bb9708
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 19 deletions.
24 changes: 5 additions & 19 deletions policy/policy_handler/legacy/ssc_metadata.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,11 @@ func MockGetInTotoAttestationsForLocalEval(sb *types.SBOM, log skill.Logger) Ima
PredicateType: &statement.PredicateType,
}

if statement.PredicateType == ProvenancePredicateType {
pr, err := decodeProvenance(statement.Predicate)
if err != nil {
log.Errorf("Failed to decode provenance predicate: %+v", err)
continue
}

if step0, found := pr.Metadata.Buildkit.Source.Locations["step0"]; found && len(step0.Locations) > 0 {
ranges := step0.Locations[0].Ranges
if len(ranges) > 0 {
subject.Predicates = []Predicate{{StartLine: &ranges[0].Start.Line}}
if statement.PredicateType == ProvenancePredicateType && sb.Source.Provenance != nil && sb.Source.Provenance.SourceMap != nil {
for _, i := range sb.Source.Provenance.SourceMap.Instructions {
if i.Instruction == "FROM_RUNTIME" {
subject.Predicates = []Predicate{{StartLine: &i.StartLine}}
break
}
}
}
Expand Down Expand Up @@ -174,11 +168,3 @@ type llbDefinition struct {
}
} `json:"op"`
}

func decodeProvenance(dt []byte) (s *provenanceDocument, err error) {
var stmt provenanceDocument
if err = json.Unmarshal(dt, &stmt); err != nil {
return nil, err
}
return &stmt, nil
}
10 changes: 10 additions & 0 deletions policy/policy_handler/legacy/ssc_metadata_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ func TestMockGetInTotoAttestationsForLocalEval(t *testing.T) {
Image: &types.ImageSource{
Digest: *digest,
},
Provenance: &types.Provenance{
SourceMap: &types.SourceMap{
Instructions: []types.InstructionSourceMap{ // this instruction indicates max-mode provenance
{
Instruction: "FROM_RUNTIME",
StartLine: 1,
},
},
},
},
},
Attestations: []dsse.Envelope{
{
Expand Down

0 comments on commit 7bb9708

Please sign in to comment.