From 9b049aee488f38a049ed04e454ba2197001f07d4 Mon Sep 17 00:00:00 2001 From: mendezr Date: Fri, 30 Oct 2026 10:15:16 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20reject=20carried=20approv?= =?UTF-8?q?als=20in=20the=20hold=20guard?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Keep copied operator admission from standing in for review of a drifted head. Add regression coverage that requires a re-hold despite a carried approval by a trusted merger. Hive-Run: hivecommons/hive#15698 Hive-Plan: carried-approval-hardening Hive-Spec: hivecommons/hive#15698#exclude-carried-approvals Signed-off-by: mendezr --- .../security-15698-carried-hold-approval.md | 1 + src/cmd/hive/hold_guard_test.go | 17 ++++++++++++++--- src/cmd/hive/main_helpers.go | 9 +++++++-- 3 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 changelog.d/security-15698-carried-hold-approval.md diff --git a/changelog.d/security-15698-carried-hold-approval.md b/changelog.d/security-15698-carried-hold-approval.md new file mode 100644 index 0000000000..414b5445cc --- /dev/null +++ b/changelog.d/security-15698-carried-hold-approval.md @@ -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)). diff --git a/src/cmd/hive/hold_guard_test.go b/src/cmd/hive/hold_guard_test.go index e982885bff..cd8753e41c 100644 --- a/src/cmd/hive/hold_guard_test.go +++ b/src/cmd/hive/hold_guard_test.go @@ -1178,14 +1178,16 @@ 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"}}, } @@ -1193,7 +1195,16 @@ func TestEnforceHoldGuardOperatorApprovalMustCoverCurrentHeadByTrustedMerger(t * 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")}, }} diff --git a/src/cmd/hive/main_helpers.go b/src/cmd/hive/main_helpers.go index 68886762f0..d3d8c50181 100644 --- a/src/cmd/hive/main_helpers.go +++ b/src/cmd/hive/main_helpers.go @@ -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). @@ -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