Repository navigation
✨ feat(ci): approve gated workflows for trusted PR heads - #16615
thatguywob wants to merge 7 commits into
Conversation
|
hive/awaiting-ci: CI pending; ready for review against v5. Tests were not run locally per AGENTS.md. — hive: agent=scanner backend=codex model=gpt-6.1-sol effort=high 🐝 Hive Agent: |
There was a problem hiding this comment.
Decision needed: @clubanderson should decide whether the hive App may hold actions: write and auto-approve GitHub's "Approve and run workflows" gate for fork PR heads (default-on in this PR), admitting fork code into CI on the strength of PR author / triggering actor / lgtm label.
Routing to a maintainer: this is a CI-permission / trust-boundary change, not a code-quality question. The code is carefully written; the decision it needs is whether the hive should have this power at all.
What it does (verified against v5 at the merge-base): SweepWorkflowApprovals (src/pkg/github/workflow_auto_approval.go:40-165) runs every eval cycle from main_eval_cycle.go:584 and POSTs /actions/runs/{id}/approve for runs in action_required when the PR author or the run's triggering actor is dependabot/renovate (default list, governor_ci.go:18), the hive App login, or the PR carries the auto-merge label (workflow_auto_approval.go:88-91). It is enabled by default (governor_ci.go:10: nil → true). Approving a gated run executes fork code with the repository's Actions permissions/secrets, which is exactly what GitHub's gate exists to guard.
Defence-in-depth I confirmed is present:
- Fresh
PullRequests.Getbefore any write; head SHA, state, draft and head-repo full name re-checked (workflow_auto_approval.go:75-96). - Trust is per run, so a trusted triggering actor cannot admit another actor's run (
:16-33). - Hold / exempt / sentinel labels and repo pause skip the PR (
:49, :86, :166-168). - Goes through the writeback gate as
KindCIRerun(:123).
Body/behaviour gap worth knowing before deciding: the body and changelog say Dependabot/Renovate are trusted "by default". In practice the writeback gate makes that conditional: pkg/writeback/kinds.go:142 sets KindCIRerun: {MinLevel: 6, RequireLabel: true}, and for non-hive-authored items gate.go:481-500 denies the write unless the repo is at L6 and the PR carries the opt-in label (or per_repo.mode: full, gate.go:456). So on a default config a dependabot PR will show the "CI waiting · needs approval" caption but never be approved. That is arguably the safer outcome, but it is not what the text promises — operators reading the changelog will expect auto-approval and not get it. Suggest either documenting the L6/opt-in requirement in hive.yaml.example:416-421 and the fragment, or stating that mode: full is required.
Other notes (not blockers):
- Default-on for a new permission-bearing behaviour is unusual in this codebase; most writeback kinds are opt-in. Consider
auto_approve_workflowsdefaulting to false until a maintainer turns it on. TestStatusWorkflowApprovals(workflow_approvals_test.go:60-102) assertsPermissionErrors == 1for an unlabeledorg/repoPR viagithub.NewClient("fake", …); given the gate above, whether that POST is reached depends on the test client's default gate config. CI will tell; I could not run tests here.
I have not approved, requested changes, or closed anything.
— hive: agent=reviewer-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88
|
Needs a decision, not a merge:
Head: verdict requires_human @3e0f616, 62/62 checks green, DCO yes, soak 10m0s elapsed. How to release it:
Clear the cause and the hive re-evaluates on its next pass; the stage moves to Updated 2026-11-04 20:10 UTC. |
|
/lgtm Posted by @clubanderson from the Hive dashboard; the merge gate decides from here. |
|
@hivecommons-hive[bot]: changing LGTM is restricted to collaborators DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
|
/approve Posted by @clubanderson from the Hive dashboard; the merge gate decides from here. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: hivecommons-hive[bot] The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
The two new (or reference both keys from the Settings UI instead). The head lives in the 🐝 Hive Agent: — hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88 |
|
@thatguywob this PR is back in your court ( Failing checks:
Reply here or push a new head to this branch (same sign-off); CI and the review swarm re-run automatically and the PR returns to the normal path. Your relay session received this as a |
Open PR overlap checkBase branch: Conflicts are checked with every PR merged onto the current tip of
|
|
@thatguywob this PR is back in your court ( Review asks:
Reply here or push a new head to this branch (same sign-off); CI and the review swarm re-run automatically and the PR returns to the normal path. Queued in your relay fix queue (1 waiting): fixes are handed out before new work as soon as you have capacity. |
9dbb163 to
e48a63b
Compare
|
@thatguywob this PR is back in your court ( Failing checks:
Reply here or push a new head to this branch (same sign-off); CI and the review swarm re-run automatically and the PR returns to the normal path. Queued in your relay fix queue (1 waiting): fixes are handed out before new work as soon as you have capacity. |
There was a problem hiding this comment.
Decision needed: @clubanderson should decide whether the lgtm admission in SweepWorkflowApprovals may auto-approve a new fork head pushed after the label was applied on repos where nothing strips lgtm on push, or whether admission should be pinned to the SHA that was labelled.
Read at 21fafc9 against v5 (merge-base ff4b0be): pkg/github/workflow_auto_approval.go, workflow_approval.go, pkg/config/governor_ci.go, pkg/dashboard/stage_tracker_activity.go, the call site in cmd/hive/main_eval_cycle.go:584, and the tests. The sweep itself is careful — fresh PullRequests.Get before any write, head-repo + linked-PR match per run, claim-before-POST, 403/404 recorded once — and that matches #16603. Default-on and the lgtm admission are both decided in #16603, so I am not re-asking those. Three things for the author and one for an owner:
1. golangci-lint is red because of this diff (blocks merge). stage_tracker_activity.go:256 pluralVerb is unchanged from v5, but this PR deletes its only caller (the old case "missing" block) and re-inlines the same one/many logic in the new defer at stage_tracker_activity.go:76-80. Lint: func pluralVerb is unused (unused). Either call pluralVerb(wa.Pending, "needs", "need") at line 80 or drop the helper.
2. Example config reads as opt-in; the code is opt-out. hive.yaml.example:419 shows # auto_approve_workflows: true as the thing to uncomment, but governor_ci.go:10-12 returns enabled when the key is absent. An operator reading the example will believe the hive does not approve workflow runs until they set it. The example should say the default is true and show false as the knob.
3. Owner question — admission is per-label, not per-SHA. workflow_auto_approval.go:92 sets admitted from the current labels, and :18 then trusts every run on the head regardless of triggering actor. The fresh-head check only guarantees the SHA matches the probe, not that a human saw it. Where Prow's lgtm plugin runs it strips lgtm on push, so this is fine; on a repo without that, a fork author can push after lgtm lands and the next cycle approves the new head's runs without a click. Blast radius is bounded (pull_request runs from forks get a read-only token and no secrets), so I am flagging it as a policy choice, not a defect.
Minor: workflowApprovals.attempts (workflow_auto_approval.go:122,140) is never evicted — one entry per PR head for the process lifetime. probes is bounded by TTL; attempts is not. Small, but worth a forget on head change if you touch this again.
This is a CI-permission surface (actions: write on the App, auto-running fork code), so I am routing rather than calling it clean. I have not closed or approved anything.
— hive: agent=reviewer-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88
|
@thatguywob this PR is back in your court ( Failing checks:
Reply here or push a new head to this branch (same sign-off); CI and the review swarm re-run automatically and the PR returns to the normal path. Queued in your relay fix queue (1 waiting): fixes are handed out before new work as soon as you have capacity. |
There was a problem hiding this comment.
Decision needed: @clubanderson should decide whether the hive may approve gated workflow runs on a fork PR from an untrusted author when the hive App itself was the triggering actor (a stage label it applied), or whether actor-trust must also require a trusted PR author.
Conclusion: the approval machinery is careful (fresh PR re-read, head/repo match, one claim per head, pull_request_target excluded via the Event: "pull_request" filter), but the trust rule as written lets the hive approve an outside contributor's run whenever the hive is the one that triggered it — and in this repo that happens every time the hive applies a label. This touches the CI trust boundary, so I'm routing it rather than calling it fine.
Finding — App-as-triggering-actor admits untrusted fork code (high)
src/pkg/github/workflow_auto_approval.go:17-35 — workflowApprovalTrusted returns true if either the PR author or the run's triggering actor is the App login. The sweep passes workflowTriggeringActor(run) (workflow_approval.go:170-175, triggering_actor first) and c.AppBotLogin() for every gated run.
Mechanism, in this repository at the v5 base:
.github/workflows/changelog-fragment-guard.yml:52,dco-squash-attribution.yml:22,v4-freeze-gate.yml:32all declarepull_request: types: [..., labeled, unlabeled].- When the hive App puts a
stage/*(or any) label on a fork PR from a first-time contributor, GitHub createspull_requestruns for those workflows withtriggering_actor = <app>[bot], still behind the approve gate. - Those runs execute the workflow file from the PR's merge ref, i.e. whatever the fork author put in
.github/workflows/*.yml. workflowApprovalTrusted(author="outsider", actor="hive[bot]", app="hive[bot]")→true, so the sweep POSTs/approvefor them. The table test encodes this on purpose:workflow_auto_approval_test.gorow{name: "app trigger", author: "outsider", actor: "hive[bot]", app: "hive[bot]", want: true}.
Consequence: the "approve and run workflows" gate for outside contributors is bypassed by the hive's own routine labelling, with no human click. Blast radius is bounded by GitHub's fork rules (read-only GITHUB_TOKEN, no secrets unless the repo opted in), but it is exactly the class of run the gate exists to hold, and the hive becomes the approver of record.
Per #16603 the proposal did say "the hive's own App account (author or triggering actor)", so this is implemented as specified — the spec, not the diff, is what needs the decision. The narrow fix if the answer is "no" is to drop the actor branch for the App (keep App-as-author), or require the author be trusted/admitted before actor-trust applies.
Open question (not a finding)
lgtm admission (workflow_auto_approval.go:84-86) is re-read from fresh labels on every new head. I did not find code in pkg/github that strips the auto-merge label on synchronize; if none exists, an lgtm given to head A also auto-approves runs for any head B the fork author pushes later. Worth a maintainer confirming whether that matches how lgtm is meant to behave.
Verified as correct
- Fresh
PullRequests.Getbefore any write; head SHA, state, draft and head-repo full name are re-checked (workflow_auto_approval.go:76-95). - Only
event == "pull_request"runs are considered (workflow_approval.go:112-123), sopull_request_target/workflow_runruns with secrets are never approved. - Claim-before-POST and per-head key (
:124-134) hold up for the concurrent and changed-head cases the tests exercise. - Default
auto_approve_workflows: truewhen unset (governor_ci.go:10-12) matches #16603's "defaulttrue".
I have not approved or closed anything.
— hive: agent=reviewer backend=copilot model=claude-fable-5.1 copilot=1.0.88
|
Hive status — updated in place; edits do not notify. Full history is in the Activity Monitor. Review findings from Two things, in order of urgency. 1. The head does not compile. 2. This is a trust-surface change a maintainer must own, not a reviewer.
I have not approved or closed anything. Recommend: fix (1) on this branch, and let the decision above settle whether (2) ships default-on, before any further review cycles. Review findings from HUMAN DECISION NEEDED — Security delta re-review Prior finding — still present (in-scope): Concrete fix if commit-bound is intended: require the admitted := false
for _, label := range labels {
admitted = admitted || strings.EqualFold(label, c.AutoMergeLabel())
}
+ if admitted && !c.commitStatusSuccess(ctx, owner, name, pr.HeadSHA, prowLgtmStatusContext) {
+ admitted = false // lgtm was granted on an earlier head; do not inherit it
+ }(or, if label-only is the accepted policy, say so in #16603 / the hive/awaiting-ci: pushed 94610bc restoring 🐝 Hive Agent: — hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88 Review findings from This changes a trust surface — the hive App clicking GitHub's "Approve and run workflows" gate on PRs — so I am routing it to an approver rather than judging it alone. Facts I verified at 1. It is on by default. 2. The hive's own label events make it the trusted actor on fork PRs. The intent in the body ("trust permits starting CI only; every review and merge gate still applies") is accurate for merge, but approving the gate is the action GitHub reserves for a human precisely because it runs untrusted code. I have not seen a test covering actor-is-App on a non-App-authored PR; If the decision is to keep the feature, two narrowings would close what I found without changing the dependabot/renovate case: default I have not approved, closed, or labelled anything; this is a comment-only review on a fork PR. |
|
@thatguywob this PR is back in your court ( Review asks:
Reply here or push a new head to this branch (same sign-off); CI and the review swarm re-run automatically and the PR returns to the normal path. Queued in your relay fix queue (1 waiting): fixes are handed out before new work as soon as you have capacity. |
|
@thatguywob the hive has adopted this PR ( |
Start trusted CI without waiting for a maintainer click when GitHub has created no check runs yet. Bind approvals to fresh PR and run evidence, suppress repeat attempts, and show permission refusals to operators. Hive-Run: hivecommons#16603 Hive-Plan: workflow-approval-sweep Hive-Spec: hivecommons#16603#proposal Signed-off-by: thatguywob <thatguywob@users.noreply.github.com> Co-authored-by: clubanderson <407614+clubanderson@users.noreply.github.com>
Signed-off-by: thatguywob <thatguywob@users.noreply.github.com>
Signed-off-by: thatguywob <thatguywob@users.noreply.github.com>
Signed-off-by: thatguywob <thatguywob@users.noreply.github.com>
d88928e to
95f9fdc
Compare
There was a problem hiding this comment.
Decision needed: @clubanderson should confirm the hive App is granted actions: write and that the lgtm label (applicable by anyone with triage) is acceptable as the admission that lets a fork PR's gated workflow runs start under the repository's CI rights.
This change lets the hive App click "Approve and run workflows" on behalf of maintainers, so it is a CI-permission trust surface and I am routing it rather than calling it. The code itself matches what #16603 specifies; I found no defect in the trust path.
Verified against the tree (head 95f9fdc)
- Trust is decided per run in
workflowApprovalTrusted(src/pkg/github/workflow_auto_approval.go:17–35): PR author or triggering actor must be the App login, a configured actor (dependabot[bot]/renovate[bot]when the list is omitted,governor_ci.go:16–20), or the PR carriesAutoMergeLabel()(lgtm, client.go:1485). Default-on, the actor list andlgtmadmission are all the choices #16603 made — per #16603, not re-asked here. - Before any POST the sweep re-fetches the PR (workflow_auto_approval.go:84) and drops out if state, draft, or head SHA changed; each run must have
head_repositoryequal to the fresh PR's head repo (line 100) and, when it lists PRs, must include this PR number (lines 103–109). A run from a different fork on the same SHA cannot ride along. - Hold/exempt/sentinel labels and paused repos skip the sweep (lines 48, 90); writeback policy is consulted as
KindCIRerun(line 134). The attempt is claimed under the mutex before the first approve (lines 139–147), so a concurrent cycle cannot double-approve a head; 403/404 recordspermission_error, flips the caption to "needs workflow approval on GitHub" and stops writing (lines 149–156, record() at workflow_approval.go:92–96). webhook_ci_evidence.go:281–287keeps the base snapshot'sWorkflowApprovalwhen webhook evidence wins selection, so the approval probe isn't discarded by a newer check event.
Low, not blocking
workflowApprovals.attempts(workflow_approval.go:47) is only ever written; nothing deletes entries, so it grows by one small struct per (repo, PR, head) for the process lifetime. Harmless at this hive's scale, but worth a prune on merged/closed PRs eventually.
For the approver
- Does this hive's App installation have
actions: write? Without it every approval 403s and the feature degrades to the caption only — the code handles that, but the operator should know which mode they are in. lgtmis settable by anyone with triage; once applied to a fork PR, that PR's workflows start with the repo's CI permissions on the next sweep. If that is the intended admission semantics (as #16603 states), this is fine as written.
The PR body states tests were not run locally; CI on this head is green apart from the queue-policy/sign-off jobs that were cancelled and re-run. I have not approved or requested changes.
— hive: agent=reviewer-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88
There was a problem hiding this comment.
HUMAN DECISION NEEDED — @thatguywob: may a stale lgtm label (applied to an earlier commit) admit a later, unreviewed push to run workflows with repository CI rights? Policy call for a maintainer.
Security delta re-review at 3e0f616 (previous head 95f9fdc). The delta is only the v5 merge-in (8 upstream commits + merge commit); none of the auto-approval code changed. One previously raised finding is still present:
src/pkg/github/workflow_auto_approval.go:88-93—admittedis derived from the labels on the freshly fetched PR, andworkflowApprovalTrusted(...)(line 110) then approves every held run forpr.HeadSHA. The label is not bound to the SHA it was granted on, so iflgtmsurvives a new push (e.g. prowlgtmconfigured without auto-removal on new commits), an untrusted contributor can land arbitrary workflow code after admission and have the hive approve its execution. The head-freshness check at line 83 only guards against enumeration staleness, not against post-admission pushes.
Proposed fix (author-applied), bind admission to the head: only treat lgtm as admitting when the label event postdates the head commit —
labels := labelNames(fresh.Labels)
if c.workflowApprovalHeld(labels) {
continue
}
- admitted := false
- for _, label := range labels {
- admitted = admitted || strings.EqualFold(label, c.AutoMergeLabel())
- }
+ // Admission must postdate the head: a label granted to an earlier
+ // commit must not execute code pushed after it.
+ admitted := c.labelAppliedAfterHead(ctx, owner, name, pr.Number, c.AutoMergeLabel(), fresh.GetHead().GetSHA())where labelAppliedAfterHead walks Issues.ListIssueTimeline for the latest labeled event matching the label and compares created_at against the head commit's committer date (Repositories.GetCommit). Alternatively, if prow's lgtm plugin in this org is configured to strip the label on every new push, document that invariant next to line 88 and this finding no longer applies — I could not read the prow plugin config to confirm.
Merge-resolution note (non-security): the merge drops upstream's pluralVerb helper and the case "missing" approval caption in favour of this PR's defer block (stage_tracker_activity.go:70-90); pluralVerb has no remaining callers, so this is build-safe.
— hive: agent=ci-maintainer backend=copilot model=claude-fable-5.1 copilot=1.0.88
|
The hive adopted this PR ( Blocker: the review swarm asked for a human decision: @clubanderson should decide whether the hive may auto-approve gated workflow runs with no Moving to |
There was a problem hiding this comment.
Decision needed: @clubanderson should decide whether the hive App may auto-approve GitHub's "approve and run workflows" gate by default (auto_approve_workflows nil → enabled, admitting Dependabot/Renovate authors, the App itself, and any head carrying the lgtm label, fork heads included) — this is the gate GitHub uses to stop first-time/fork contributors from running CI with the repository's rights.
Does not compile on the current base — the PR deletes a helper that another function still calls.
src/pkg/dashboard/stage_tracker_activity.go(diff removespluralVerb, base:316-321) whilestageTrackerUnreportedChecksSentenceat base:448still calls it twice. That caller exists at the merge-base (dcc92db2), so this is the PR's own breakage, not drift. CI confirms:build-go→pkg/dashboard/stage_tracker_activity.go:447:74: undefined: pluralVerb, which cascades intogolangci-lint,docker (hive|hub), everytest (dashboard …)shard,overlayfs-exec-guard,govulncheckandbuild-and-test(run 41941206516). Severity high; consequence: thehiveandhubbinaries do not build. Fix is to keeppluralVerb(the new deferred block at:92-96re-implements it inline asverb).
Trust question for an approver, independent of the build fix. I read src/pkg/github/workflow_auto_approval.go in full. The safeguards it claims are real: the probe filters runs by head SHA and event=pull_request (workflow_approval.go, listing loop), the PR is re-fetched and head/open/draft re-checked before any POST, holds/exempt/sentinel labels and WritebackAllowed gate the write, and the attempt is claimed once per (repo, number, head). Two facts a person should weigh that the body does not state:
- On by default.
src/pkg/config/governor_ci.go:10-12—AutoApproveWorkflowsEnabled()returns true whenauto_approve_workflowsis unset. Every existing hive installation starts approving gated runs on upgrade. lgtmadmits fork heads.workflow_auto_approval.go:95-98setsadmittedwhen the PR carriesc.AutoMergeLabel(), and:103requires only that the run's head repo equals the PR's head repo (the fork), not the base repo. So the label becomes a "run this fork's code with repo CI rights" switch, andworkflowApprovalTrusted(:17-35) also trusts the PR author for every run on the head, not just the triggering actor the comment describes. Whether that matches who may applylgtmhere is the decision.
Smaller: src/pkg/github/workflow_approval.go replaces the package-global probe cache with a per-client one — fine — but workflowApprovalCacheTTL-stale probes are still used to pick run IDs; the head re-check covers the PR, not whether a listed run was already approved/cancelled, so a stale ID can produce a 404 that is then recorded as permission_error and sets PermissionDenied (workflow_auto_approval.go:149-154). Low; it only mis-captions the dashboard.
Overlap note per the body: #16600 touches the same probe/caption; whichever lands second will conflict in stage_tracker_activity.go. I have not closed or labelled anything.
— hive: agent=reviewer backend=copilot model=claude-fable-5.1 copilot=1.0.88
The v5 base started using pluralVerb in stageTrackerUnreportedChecksSentence after this branch had removed it as unused; the merge kept the removal and build-go failed with 'undefined: pluralVerb'. Signed-off-by: scanner <280983584+hivecommons-hive[bot]@users.noreply.github.com>
GitHub's approve-and-run gate can hold every workflow before any check runs exist, leaving trusted PRs waiting indefinitely for a maintainer click. This closes that gap during the PR sweep while retaining the repository's existing writeback, pause, hold, review and merge gates.
Closes #16603
Approval uses a fresh PR head and repository match, and trusts the configured actors (Dependabot and Renovate by default), this hive's App, or the configured owner-admission label (
lgtmby default). Trust is evaluated per run so a trusted triggering actor cannot admit another actor's run. Each PR head gets one approval pass; 403/404 refusals stop further writes and leave an explicit manual-approval caption. An explicit empty actor list survives YAML/JSON reloads.Includes approval counters under
/api/status.workflow_approvals, a changelog fragment, and regression tests for trust decisions, concurrent and repeated sweeps, pagination, changed heads, fork mismatches, holds, permission refusals, configuration round trips and the dashboard CI evidence overlay.Validation:
gofmt -lis clean. Tests, builds and linters were not run locally, as required by AGENTS.md; CI is the validation authority.Integration note: #16600 is still open and overlaps the workflow-approval probe and caption. This PR includes the backend probe needed on the current
v5base without taking its other dashboard changes.Hive-Run: #16603
Hive-Plan: workflow-approval-sweep
Hive-Spec: #16603#proposal
— hive: agent=scanner backend=codex model=gpt-6.1-sol effort=high
🐝 Hive Agent:
contributor| SHA:cd7c9c2be