@@ -16,46 +16,10 @@ import (
16
16
"google.golang.org/protobuf/types/known/structpb"
17
17
18
18
"github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/ghcontrol"
19
+ "github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/provenance"
19
20
"github.com/slsa-framework/slsa-source-poc/sourcetool/pkg/slsa"
20
21
)
21
22
22
- const (
23
- SourceProvPredicateType = "https://github.com/slsa-framework/slsa-source-poc/source-provenance/v1-draft"
24
- TagProvPredicateType = "https://github.com/slsa-framework/slsa-source-poc/tag-provenance/v1-draft"
25
- )
26
-
27
- // The predicate that encodes source provenance data.
28
- // The git commit this corresponds to is encoded in the surrounding statement.
29
- type SourceProvenancePred struct {
30
- // The commit preceding 'Commit' in the current context.
31
- PrevCommit string `json:"prev_commit"`
32
- RepoUri string `json:"repo_uri"`
33
- ActivityType string `json:"activity_type"`
34
- Actor string `json:"actor"`
35
- Branch string `json:"branch"`
36
- CreatedOn time.Time `json:"created_on"`
37
- // TODO: get the author of the PR (if this was from a PR).
38
-
39
- // The controls enabled at the time this commit was pushed.
40
- Controls slsa.Controls `json:"controls"`
41
- }
42
-
43
- // Summary of a summary
44
- type VsaSummary struct {
45
- SourceRefs []string `json:"source_refs"`
46
- VerifiedLevels []slsa.ControlName `json:"verifiedLevels"`
47
- }
48
-
49
- type TagProvenancePred struct {
50
- RepoUri string `json:"repo_uri"`
51
- Actor string `json:"actor"`
52
- Tag string `json:"tag"`
53
- CreatedOn time.Time `json:"created_on"`
54
- // The tag related controls enabled at the time this tag was created/updated.
55
- Controls slsa.Controls `json:"controls"`
56
- VsaSummaries []VsaSummary `json:"vsa_summaries"`
57
- }
58
-
59
23
type ProvenanceAttestor struct {
60
24
verifier Verifier
61
25
gh_connection * ghcontrol.GitHubConnection
@@ -65,11 +29,11 @@ func NewProvenanceAttestor(gh_connection *ghcontrol.GitHubConnection, verifier V
65
29
return & ProvenanceAttestor {verifier : verifier , gh_connection : gh_connection }
66
30
}
67
31
68
- func GetSourceProvPred (statement * spb.Statement ) (* SourceProvenancePred , error ) {
32
+ func GetSourceProvPred (statement * spb.Statement ) (* provenance. SourceProvenancePred , error ) {
69
33
if statement == nil {
70
34
return nil , errors .New ("nil statement" )
71
35
}
72
- if statement .GetPredicateType () != SourceProvPredicateType {
36
+ if statement .GetPredicateType () != provenance . SourceProvPredicateType {
73
37
return nil , fmt .Errorf ("unsupported predicate type: %s" , statement .GetPredicateType ())
74
38
}
75
39
if statement .GetPredicate () == nil {
@@ -80,7 +44,7 @@ func GetSourceProvPred(statement *spb.Statement) (*SourceProvenancePred, error)
80
44
return nil , fmt .Errorf ("cannot marshal predicate to JSON: %w" , err )
81
45
}
82
46
83
- var predStruct SourceProvenancePred
47
+ var predStruct provenance. SourceProvenancePred
84
48
// Using regular json.Unmarshal because this is just a regular struct.
85
49
err = json .Unmarshal (predJson , & predStruct )
86
50
if err != nil {
@@ -92,11 +56,11 @@ func GetSourceProvPred(statement *spb.Statement) (*SourceProvenancePred, error)
92
56
return & predStruct , nil
93
57
}
94
58
95
- func GetTagProvPred (statement * spb.Statement ) (* TagProvenancePred , error ) {
59
+ func GetTagProvPred (statement * spb.Statement ) (* provenance. TagProvenancePred , error ) {
96
60
if statement == nil {
97
61
return nil , errors .New ("nil statement" )
98
62
}
99
- if statement .GetPredicateType () != TagProvPredicateType {
63
+ if statement .GetPredicateType () != provenance . TagProvPredicateType {
100
64
return nil , fmt .Errorf ("unsupported predicate type: %s" , statement .GetPredicateType ())
101
65
}
102
66
if statement .GetPredicate () == nil {
@@ -107,7 +71,7 @@ func GetTagProvPred(statement *spb.Statement) (*TagProvenancePred, error) {
107
71
return nil , fmt .Errorf ("cannot marshal predicate to JSON: %w" , err )
108
72
}
109
73
110
- var predStruct TagProvenancePred
74
+ var predStruct provenance. TagProvenancePred
111
75
// Using regular json.Unmarshal because this is just a regular struct.
112
76
err = json .Unmarshal (predJson , & predStruct )
113
77
if err != nil {
@@ -155,7 +119,7 @@ func (pa ProvenanceAttestor) createCurrentProvenance(ctx context.Context, commit
155
119
156
120
curTime := time .Now ()
157
121
158
- var curProvPred SourceProvenancePred
122
+ var curProvPred provenance. SourceProvenancePred
159
123
curProvPred .PrevCommit = prevCommit
160
124
curProvPred .RepoUri = pa .gh_connection .GetRepoUri ()
161
125
curProvPred .Actor = controlStatus .ActorLogin
@@ -167,11 +131,11 @@ func (pa ProvenanceAttestor) createCurrentProvenance(ctx context.Context, commit
167
131
// At the very least provenance is available starting now. :)
168
132
curProvPred .Controls .AddControl (& slsa.Control {Name : slsa .ProvenanceAvailable , Since : curTime })
169
133
170
- return addPredToStatement (& curProvPred , SourceProvPredicateType , commit )
134
+ return addPredToStatement (& curProvPred , provenance . SourceProvPredicateType , commit )
171
135
}
172
136
173
137
// Gets provenance for the commit from git notes.
174
- func (pa ProvenanceAttestor ) GetProvenance (ctx context.Context , commit , ref string ) (* spb.Statement , * SourceProvenancePred , error ) {
138
+ func (pa ProvenanceAttestor ) GetProvenance (ctx context.Context , commit , ref string ) (* spb.Statement , * provenance. SourceProvenancePred , error ) {
175
139
notes , err := pa .gh_connection .GetNotesForCommit (ctx , commit )
176
140
if notes == "" {
177
141
Debugf ("didn't find notes for commit %s" , commit )
@@ -187,9 +151,9 @@ func (pa ProvenanceAttestor) GetProvenance(ctx context.Context, commit, ref stri
187
151
return pa .getProvFromReader (bundleReader , commit , ref )
188
152
}
189
153
190
- func (pa ProvenanceAttestor ) getProvFromReader (reader * BundleReader , commit , ref string ) (* spb.Statement , * SourceProvenancePred , error ) {
154
+ func (pa ProvenanceAttestor ) getProvFromReader (reader * BundleReader , commit , ref string ) (* spb.Statement , * provenance. SourceProvenancePred , error ) {
191
155
for {
192
- stmt , err := reader .ReadStatement (MatchesTypeAndCommit (SourceProvPredicateType , commit ))
156
+ stmt , err := reader .ReadStatement (MatchesTypeAndCommit (provenance . SourceProvPredicateType , commit ))
193
157
if err != nil {
194
158
// Ignore errors, we want to check all the lines.
195
159
Debugf ("error while processing line: %v" , err )
@@ -218,7 +182,7 @@ func (pa ProvenanceAttestor) getProvFromReader(reader *BundleReader, commit, ref
218
182
return nil , nil , nil
219
183
}
220
184
221
- func (pa ProvenanceAttestor ) getPrevProvenance (ctx context.Context , prevAttPath , prevCommit , ref string ) (* spb.Statement , * SourceProvenancePred , error ) {
185
+ func (pa ProvenanceAttestor ) getPrevProvenance (ctx context.Context , prevAttPath , prevCommit , ref string ) (* spb.Statement , * provenance. SourceProvenancePred , error ) {
222
186
if prevAttPath != "" {
223
187
f , err := os .Open (prevAttPath )
224
188
if err != nil {
@@ -270,7 +234,7 @@ func (pa ProvenanceAttestor) CreateSourceProvenance(ctx context.Context, prevAtt
270
234
curProvPred .Controls [i ] = curControl
271
235
}
272
236
273
- return addPredToStatement (curProvPred , SourceProvPredicateType , commit )
237
+ return addPredToStatement (curProvPred , provenance . SourceProvPredicateType , commit )
274
238
}
275
239
276
240
func (pa ProvenanceAttestor ) CreateTagProvenance (ctx context.Context , commit , ref , actor string ) (* spb.Statement , error ) {
@@ -302,19 +266,19 @@ func (pa ProvenanceAttestor) CreateTagProvenance(ctx context.Context, commit, re
302
266
return nil , fmt .Errorf ("error getting source refs from vsa %w" , err )
303
267
}
304
268
305
- curProvPred := TagProvenancePred {
269
+ curProvPred := provenance. TagProvenancePred {
306
270
RepoUri : pa .gh_connection .GetRepoUri (),
307
271
Actor : actor ,
308
272
Tag : ref ,
309
273
CreatedOn : curTime ,
310
274
Controls : controlStatus .Controls ,
311
- VsaSummaries : []VsaSummary {
275
+ VsaSummaries : []provenance. VsaSummary {
312
276
{
313
277
SourceRefs : vsaRefs ,
314
278
VerifiedLevels : slsa .StringsToControlNames (vsaPred .GetVerifiedLevels ()),
315
279
},
316
280
},
317
281
}
318
282
319
- return addPredToStatement (& curProvPred , TagProvPredicateType , commit )
283
+ return addPredToStatement (& curProvPred , provenance . TagProvPredicateType , commit )
320
284
}
0 commit comments