Skip to content

Commit d379c6e

Browse files
committed
Create policy from controls, not att
This commit modifies the sourcetool module to create the policuy from the enabked controls instead of basing it on the last provenance attestation. Signed-off-by: Adolfo Garcia Veytia (puerco) <puerco@carabiner.dev>
1 parent bd44611 commit d379c6e

1 file changed

Lines changed: 5 additions & 24 deletions

File tree

‎sourcetool/pkg/sourcetool/tool.go‎

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -187,46 +187,27 @@ func (t *Tool) CreateBranchPolicy(ctx context.Context, r *models.Repository, bra
187187
return nil, fmt.Errorf("getting backend: %w", err)
188188
}
189189

190-
// Get the branch latest commit from the backend
191-
latestCommit, err := backend.GetLatestCommit(ctx, r, branches[0])
190+
controls, err := t.impl.GetBranchControls(ctx, backend, r, branches[0])
192191
if err != nil {
193-
return nil, fmt.Errorf("could not get latest commit: %w", err)
194-
}
195-
196-
reader, err := t.impl.GetAttestationReader(nil)
197-
if err != nil {
198-
return nil, fmt.Errorf("getting attestation reader")
199-
}
200-
201-
// Get the latest commit provenance attestation
202-
_, predicate, err := reader.GetCommitProvenance(ctx, branches[0], latestCommit)
203-
if err != nil {
204-
return nil, fmt.Errorf("could not get provenance for latest commit: %w", err)
192+
return nil, fmt.Errorf("getting branch controls: %w", err)
205193
}
206194

207-
controls := &slsa.Controls{}
208-
if predicate != nil {
209-
for _, c := range predicate.GetControls() {
210-
controls.AddControl(c)
211-
}
212-
}
213195
return t.createPolicy(r, branches[0], controls)
214196
}
215197

216198
// This function will be moved to the policy package once we start integrating
217199
// it with the global data models (if we do).
218-
func (t *Tool) createPolicy(r *models.Repository, branch *models.Branch, controls *slsa.Controls) (*policy.RepoPolicy, error) {
200+
func (t *Tool) createPolicy(r *models.Repository, branch *models.Branch, controls *slsa.ControlSetStatus) (*policy.RepoPolicy, error) {
219201
// Default to SLSA1 since unset date
220202
eligibleSince := &time.Time{}
221203
eligibleLevel := slsa.SlsaSourceLevel1
222204

223205
var err error
224206
// Unless there is previous provenance metadata, then we can compute
225207
// a higher level
226-
227208
if controls != nil {
228-
eligibleLevel = policy.ComputeEligibleSlsaLevel(*controls)
229-
eligibleSince, err = policy.ComputeEligibleSince(*controls, eligibleLevel)
209+
eligibleLevel = policy.ComputeEligibleSlsaLevel(*controls.GetActiveControls())
210+
eligibleSince, err = policy.ComputeEligibleSince(*controls.GetActiveControls(), eligibleLevel)
230211
if err != nil {
231212
return nil, fmt.Errorf("could not compute eligible_since: %w", err)
232213
}

0 commit comments

Comments
 (0)