@@ -64,7 +64,7 @@ func (b *goProvenanceBuild) BuildConfig(context.Context) (interface{}, error) {
64
64
// GenerateProvenance translates github context into a SLSA provenance
65
65
// attestation.
66
66
// Spec: https://slsa.dev/provenance/v0.2
67
- func GenerateProvenance (name , digest , command , envs , workingDir string , s signing.Signer , r signing.TransparencyLog ) ([]byte , error ) {
67
+ func GenerateProvenance (name , digest , command , envs , workingDir string , s signing.Signer , r signing.TransparencyLog , provider slsa. ClientProvider ) ([]byte , error ) {
68
68
gh , err := github .GetWorkflowContext ()
69
69
if err != nil {
70
70
return nil , err
@@ -84,6 +84,11 @@ func GenerateProvenance(name, digest, command, envs, workingDir string, s signin
84
84
return nil , err
85
85
}
86
86
87
+ var cmd []string
88
+ if len (com ) > 0 {
89
+ cmd = []string {com [0 ], "mod" , "vendor" }
90
+ }
91
+
87
92
b := goProvenanceBuild {
88
93
GithubActionsBuild : slsa .NewGithubActionsBuild ([]intoto.Subject {
89
94
{
@@ -101,7 +106,7 @@ func GenerateProvenance(name, digest, command, envs, workingDir string, s signin
101
106
// Note: vendoring and compilation are
102
107
// performed in the same VM, so the compiler is
103
108
// the same.
104
- Command : [] string { com [ 0 ], "mod" , "vendor" } ,
109
+ Command : cmd ,
105
110
WorkingDir : workingDir ,
106
111
// Note: No user-defined env set for this step.
107
112
},
@@ -116,15 +121,25 @@ func GenerateProvenance(name, digest, command, envs, workingDir string, s signin
116
121
}
117
122
118
123
// Pre-submit tests don't have access to write OIDC token.
119
- if utils .IsPresubmitTests () {
120
- b .GithubActionsBuild .WithClients (& slsa.NilClientProvider {})
124
+ if provider != nil {
125
+ b .WithClients (provider )
126
+ } else {
127
+ // TODO(github.com/slsa-framework/slsa-github-generator/issues/124): Remove
128
+ if utils .IsPresubmitTests () {
129
+ b .GithubActionsBuild .WithClients (& slsa.NilClientProvider {})
130
+ }
121
131
}
122
132
123
133
ctx := context .Background ()
124
134
g := slsa .NewHostedActionsGenerator (& b )
125
135
// Pre-submit tests don't have access to write OIDC token.
126
- if utils .IsPresubmitTests () {
127
- g .WithClients (& slsa.NilClientProvider {})
136
+ if provider != nil {
137
+ g .WithClients (provider )
138
+ } else {
139
+ // TODO(github.com/slsa-framework/slsa-github-generator/issues/124): Remove
140
+ if utils .IsPresubmitTests () {
141
+ g .WithClients (& slsa.NilClientProvider {})
142
+ }
128
143
}
129
144
p , err := g .Generate (ctx )
130
145
if err != nil {
@@ -163,10 +178,12 @@ func GenerateProvenance(name, digest, command, envs, workingDir string, s signin
163
178
}
164
179
165
180
// Upload the signed attestation to rekor.
166
- if logEntry , err := r .Upload (ctx , att ); err != nil {
167
- fmt . Printf ( "Uploaded signed attestation to rekor with UUID %s. \n " , logEntry . UUID ())
181
+ logEntry , err := r .Upload (ctx , att )
182
+ if err != nil {
168
183
return nil , err
169
184
}
170
185
186
+ fmt .Printf ("Uploaded signed attestation to rekor with UUID %s.\n " , logEntry .UUID ())
187
+
171
188
return att .Bytes (), nil
172
189
}
0 commit comments