Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/security-15698-carried-hold-approval.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- The hold guard no longer treats an approval carried from an adopted PR as proof that a trusted merger reviewed the copy's current head ([#15698](https://github.com/hivecommons/hive/issues/15698)).
17 changes: 14 additions & 3 deletions src/cmd/hive/hold_guard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1178,22 +1178,33 @@ func TestEnforceHoldGuardOperatorApprovalCarriesOverHiveBaseRefresh(t *testing.T
}

// The approval must name the head on the branch now: one recorded on the
// pre-push head, or by someone outside the merger tier, is not a review of
// the current tree and the drift path stands.
// pre-push head, carried from an adopted PR, or by someone outside the merger
// tier is not a review of the current tree and the drift path stands.
func TestEnforceHoldGuardOperatorApprovalMustCoverCurrentHeadByTrustedMerger(t *testing.T) {
cases := []struct {
name, head, actor string
body string
users []string
}{
{name: "approval on the old head", head: "c1", actor: "clubanderson", users: []string{"clubanderson:owner"}},
{name: "carried approval on the current head", head: "p1", actor: "clubanderson", body: "approve (carried from #6 head original)", users: []string{"clubanderson:owner"}},
{name: "approver below merger tier", head: "p1", actor: "visitor", users: []string{"visitor:read-write"}},
{name: "approver not authorized", head: "p1", actor: "stranger", users: []string{"clubanderson:owner"}},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
store := newTestHoldGuardStore(t)
decisions := swapHoldGuardHumanChangeRequests(t)
recordHoldGuardDecision(t, decisions, tc.head, tc.actor, review.HumanChangeRequestKindApprove)
body := tc.body
if body == "" {
body = review.HumanChangeRequestKindApprove
}
if err := decisions.Record(review.HumanChangeRequest{
Repo: "acme/widgets", Number: 7, HeadSHA: tc.head, Source: review.HumanChangeRequestSourceDecision,
SourceID: 1, Actor: tc.actor, Body: body, Kind: review.HumanChangeRequestKindApprove,
}); err != nil {
t.Fatal(err)
}
fake := &holdGuardServer{commits: map[int][]map[string]any{
7: {ghCommit("c1", "odttlnt", "deploy: monitoring"), ghCommit("p1", "odttlnt", "deploy: patch secret")},
}}
Expand Down
9 changes: 7 additions & 2 deletions src/cmd/hive/main_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ var holdGuardHumanChangeRequests = func() review.HumanChangeRequestStore {
// The record is head-scoped — a newer head supersedes it — so it is proof
// the person reviewed the tree on the branch now, which the gate-lift
// timeline cannot show when the hive removed the label for them. Fails
// closed: no record, a change request, an unknown or untrusted actor, or an
// empty head never cover the head. The one head change that does not
// closed: no record, a change request, a carried approval, an unknown or
// untrusted actor, or an empty head never cover the head. The one head change that does not
// supersede the record is the hive's own base refresh — a merge of the base
// branch by the App that leaves the PR's diff as the person saw it — which
// carries the approval onto the new head first (hivecommons/hive#15649).
Expand All @@ -69,6 +69,11 @@ func holdGuardOperatorApproval(ctx context.Context, cfg *config.Config, ghClient
if !ok || !req.IsApproval() || !strings.EqualFold(strings.TrimSpace(req.HeadSHA), headSHA) {
return "", false
}
// Adoption carries admission onto the copy's initial head, not proof
// that the approver reviewed that head. It cannot lift a drifted hold.
if strings.HasPrefix(req.Body, "approve (carried") {
return "", false
}
login := strings.TrimSpace(req.Actor)
if !trustedMergerFunc(cfg)(login) {
return "", false
Expand Down
Loading