Skip to content

Commit 97d953e

Browse files
committed
handle querystring and subdir URLs when matching git material
Signed-off-by: Tonis Tiigi <[email protected]>
1 parent 57a72b0 commit 97d953e

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

solver/llbsolver/provenance/predicate.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
slsa "github.com/in-toto/in-toto-golang/in_toto/slsa_provenance/common"
99
slsa02 "github.com/in-toto/in-toto-golang/in_toto/slsa_provenance/v0.2"
1010
provenancetypes "github.com/moby/buildkit/solver/llbsolver/provenance/types"
11+
"github.com/moby/buildkit/util/gitutil"
1112
"github.com/moby/buildkit/util/purl"
1213
"github.com/moby/buildkit/util/urlutil"
1314
"github.com/package-url/packageurl-go"
@@ -69,6 +70,35 @@ func digestSetForCommit(commit string) slsa.DigestSet {
6970
}
7071

7172
func findMaterial(srcs provenancetypes.Sources, uri string) (*slsa.ProvenanceMaterial, bool) {
73+
// Git URLs in querystring format or subdir need to be converted to fragment format with only ref
74+
gitRef, err := gitutil.ParseURL(uri)
75+
if err == nil && gitRef != nil {
76+
u := gitRef.Remote
77+
var ref string
78+
if gitRef.Opts != nil {
79+
ref = gitRef.Opts.Ref
80+
}
81+
if len(gitRef.Query) > 0 {
82+
for k, v := range gitRef.Query {
83+
if len(v) == 0 {
84+
continue
85+
}
86+
switch k {
87+
case "ref":
88+
ref = v[0]
89+
case "branch":
90+
ref = "refs/heads/" + v[0]
91+
case "tag":
92+
ref = "refs/tags/" + v[0]
93+
}
94+
}
95+
}
96+
if ref != "" {
97+
u += "#" + ref
98+
}
99+
uri = u
100+
}
101+
72102
for _, s := range srcs.Git {
73103
if s.URL == uri {
74104
return &slsa.ProvenanceMaterial{

0 commit comments

Comments
 (0)