Prove every own-SHA rewrite and check reused composites' children (#215) · github/gh-actions-lock@a0a7edc · GitHub
Skip to content

Commit a0a7edc

Browse files
Prove every own-SHA rewrite and check reused composites' children (#215)
* Admit every own-SHA rewrite through one identity proof and check reused composites' children Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Point failed identity proofs at a real fix and check only reused composites' children Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 4cc8e2b commit a0a7edc

6 files changed

Lines changed: 289 additions & 29 deletions

File tree

‎cmd/gh-actions-lock/parity_test.go‎

Lines changed: 149 additions & 10 deletions

‎internal/lockfile/state.go‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,18 @@ func walkClosure(f parserlock.File, workflowKey string, live func(parserlock.Pin
527527
return out, faults
528528
}
529529

530+
// Descendants returns the recorded entries below the entry stored under key,
531+
// each with the entry whose `uses:` reached it as Parent. A write that keeps
532+
// the entry keeps them too.
533+
func (s *State) Descendants(key string) []LockedPin {
534+
s.mu.Lock()
535+
defer s.mu.Unlock()
536+
f := s.file
537+
f.Workflows = map[string][]string{"": {key}}
538+
closure, _ := walkClosure(f, "", func(parserlock.Pin, parserlock.Action) bool { return true })
539+
return slices.DeleteFunc(closure, func(lp LockedPin) bool { return lp.Parent == "" })
540+
}
541+
530542
// RecordsOwnSHA reports whether the lockfile's entry for owner/repo@sha
531543
// records that SHA as its ref (see the RecordsOwnSHA function).
532544
func (s *State) RecordsOwnSHA(owner, repo, sha string) bool {

‎internal/pin/plan.go‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,8 +421,17 @@ func preserveReRecorded(opts PlanOptions, deps []dep.Dependency, preservedDeps m
421421
return out
422422
}
423423
for i, d := range deps {
424+
if !parserlock.IsFullSha(d.Ref) {
425+
continue
426+
}
427+
// A redirect names the repository by its new name; the entry may
428+
// still be recorded under the name the workflow uses.
424429
owner, repo := d.OwnerRepo()
425-
if parserlock.IsFullSha(d.Ref) && opts.Store.RecordsOwnSHA(owner, repo, d.Ref) {
430+
recorded := opts.Store.RecordsOwnSHA(owner, repo, d.Ref)
431+
for _, orig := range d.OriginalRefs {
432+
recorded = recorded || opts.Store.RecordsOwnSHA(orig.Owner, orig.Repo, d.Ref)
433+
}
434+
if recorded {
426435
preservedDeps[i] = true
427436
out[d.Key()] = true
428437
}

‎internal/pin/repair.go‎

Lines changed: 52 additions & 5 deletions

0 commit comments

Comments
 (0)