Skip to content

Commit 8f12ba8

Browse files
committed
provenance: avoid missing args in history provenance
Signed-off-by: Tonis Tiigi <[email protected]>
1 parent 0ca6aba commit 8f12ba8

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

solver/llbsolver/provenance/predicate.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package provenance
22

33
import (
4+
"maps"
45
"strings"
56

67
"github.com/containerd/platforms"
@@ -96,34 +97,36 @@ func NewPredicate(c *Capture) (*provenancetypes.ProvenancePredicateSLSA02, error
9697
}
9798
inv := provenancetypes.ProvenanceInvocationSLSA02{}
9899

100+
args := maps.Clone(c.Args)
101+
99102
contextKey := "context"
100-
if v, ok := c.Args["contextkey"]; ok && v != "" {
103+
if v, ok := args["contextkey"]; ok && v != "" {
101104
contextKey = v
102105
}
103106

104-
if v, ok := c.Args[contextKey]; ok && v != "" {
107+
if v, ok := args[contextKey]; ok && v != "" {
105108
if m, ok := findMaterial(c.Sources, v); ok {
106109
inv.ConfigSource.URI = m.URI
107110
inv.ConfigSource.Digest = m.Digest
108111
} else {
109112
inv.ConfigSource.URI = v
110113
}
111114
inv.ConfigSource.URI = urlutil.RedactCredentials(inv.ConfigSource.URI)
112-
delete(c.Args, contextKey)
115+
delete(args, contextKey)
113116
}
114117

115-
if v, ok := c.Args["filename"]; ok && v != "" {
118+
if v, ok := args["filename"]; ok && v != "" {
116119
inv.ConfigSource.EntryPoint = v
117-
delete(c.Args, "filename")
120+
delete(args, "filename")
118121
}
119122

120123
vcs := make(map[string]string)
121-
for k, v := range c.Args {
124+
for k, v := range args {
122125
if strings.HasPrefix(k, "vcs:") {
123126
if k == "vcs:source" {
124127
v = urlutil.RedactCredentials(v)
125128
}
126-
delete(c.Args, k)
129+
delete(args, k)
127130
if v != "" {
128131
vcs[strings.TrimPrefix(k, "vcs:")] = v
129132
}
@@ -133,7 +136,7 @@ func NewPredicate(c *Capture) (*provenancetypes.ProvenancePredicateSLSA02, error
133136
inv.Environment.Platform = platforms.Format(platforms.Normalize(platforms.DefaultSpec()))
134137

135138
inv.Parameters.Frontend = c.Frontend
136-
inv.Parameters.Args = c.Args
139+
inv.Parameters.Args = args
137140

138141
for _, s := range c.Secrets {
139142
inv.Parameters.Secrets = append(inv.Parameters.Secrets, &provenancetypes.Secret{

0 commit comments

Comments
 (0)