Skip to content

✨ feat(ci): approve gated workflows for trusted PR heads - #16615

Closed
thatguywob wants to merge 7 commits into
hivecommons:v5from
thatguywob:scanner/16603-auto-approve-workflows
Closed

thatguywob wants to merge 7 commits into
hivecommons:v5from
thatguywob:scanner/16603-auto-approve-workflows

Conversation

@thatguywob

Copy link
Copy Markdown
Contributor

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 (lgtm by 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 -l is 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 v5 base 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

@kubestellar-prow kubestellar-prow Bot added dco-signoff: yes Indicates the PR's author has signed the DCO. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Nov 4, 2026
@thatguywob

Copy link
Copy Markdown
Contributor Author

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: contributor | SHA: cd7c9c2be

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.Get before 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_workflows defaulting to false until a maintainer turns it on.
  • TestStatusWorkflowApprovals (workflow_approvals_test.go:60-102) asserts PermissionErrors == 1 for an unlabeled org/repo PR via github.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

@hivecommons-hive

hivecommons-hive Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Needs a decision, not a merge:

Head: verdict requires_human @3e0f616, 62/62 checks green, DCO yes, soak 10m0s elapsed.

How to release it:

  • After reading the verdict, a trusted merger can submit a GitHub Approve review for the current head and the lane clears the hold on its next pass; /hive approve replies on a PR are acknowledged but not consumed.

Clear the cause and the hive re-evaluates on its next pass; the stage moves to stage/090-ready-for-human-merge, stage/095-pre-merge-soak or the merge queue on its own. Approval does not bypass CI, hold labels or other merge gates.

Updated 2026-11-04 20:10 UTC.

@hivecommons-hive

Copy link
Copy Markdown
Contributor

/lgtm

Posted by @clubanderson from the Hive dashboard; the merge gate decides from here.

@kubestellar-prow

Copy link
Copy Markdown
Contributor

@hivecommons-hive[bot]: changing LGTM is restricted to collaborators

Details

In response to this:

/lgtm

Posted by @clubanderson from the Hive dashboard; the merge gate decides from here.

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.

@hivecommons-hive

Copy link
Copy Markdown
Contributor

/approve

Posted by @clubanderson from the Hive dashboard; the merge gate decides from here.

@kubestellar-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: hivecommons-hive[bot]
Once this PR has been reviewed and has the lgtm label, please assign danathar for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@hivecommons-hive

Copy link
Copy Markdown
Contributor

coverage at cd7c9c2 is PR-local: TestSettingsDialogReferencesEveryHiveYAMLLeaf fails in the test (dashboard 2/4) shard, and coverage refuses to report without green shards (job 126689218694, v5 is green on the same shard).

settings_parity_test.go:33: hive.yaml settings are not referenced by the Settings UI and are not allowlisted:
        governor.ci.auto_approve_workflow_actors[]
        governor.ci.auto_approve_workflows
--- FAIL: TestSettingsDialogReferencesEveryHiveYAMLLeaf (7.13s)

The two new hive.yaml leaves this PR adds in src/pkg/config/governor_ci.go have no Settings-dialog control and no allowlist entry. Smallest fix, matching the existing governor.ci_failure_* entries in src/pkg/dashboard/settings_parity_allowlist.txt:

governor.ci.auto_approve_workflows # auto-approve gated workflow runs for trusted heads (#16603); yaml-only
governor.ci.auto_approve_workflow_actors[] # extra actors whose heads may be auto-approved (#16603); yaml-only

(or reference both keys from the Settings UI instead). The head lives in the thatguywob/hive fork, so the hive cannot push this; once it lands, coverage will re-evaluate on the new head.


🐝 Hive Agent: scanner | Instance: hosted-available-oke-11-placeholder-r05x | SHA: unknown

— hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive

Copy link
Copy Markdown
Contributor

@thatguywob this PR is back in your court (stage/072-returned-to-contributor). The hive will not merge it until the head changes.

Failing checks:

  • coverage

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 fix-pr task and launched a parallel fix session; your current work continues.

@github-actions

github-actions Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Open PR overlap check

Base branch: v5

Conflicts are checked with every PR merged onto the current tip of v5, so a PR that only needs a rebase is not reported as conflicting with its siblings.

PR Title Relation Files
#16607 ✨ feat(github): enforce pin-only exception in merge-request relay same files src/pkg/config/config.go
src/pkg/github/client.go

@hivecommons-hive

Copy link
Copy Markdown
Contributor

@thatguywob this PR is back in your court (stage/072-returned-to-contributor). The hive will not merge it until the head changes.

Review asks:

  • the branch conflicts with the base and needs a rebase

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
thatguywob force-pushed the scanner/16603-auto-approve-workflows branch from 9dbb163 to e48a63b Compare November 4, 2026 16:45
@hivecommons-hive

Copy link
Copy Markdown
Contributor

@thatguywob this PR is back in your court (stage/072-returned-to-contributor). The hive will not merge it until the head changes.

Failing checks:

  • golangci-lint
  • mobile-shots

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.

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@hivecommons-hive

Copy link
Copy Markdown
Contributor

@thatguywob this PR is back in your court (stage/072-returned-to-contributor). The hive will not merge it until the head changes.

Failing checks:

  • mobile-shots

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.

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:32 all declare pull_request: types: [..., labeled, unlabeled].
  • When the hive App puts a stage/* (or any) label on a fork PR from a first-time contributor, GitHub creates pull_request runs for those workflows with triggering_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 /approve for them. The table test encodes this on purpose: workflow_auto_approval_test.go row {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.Get before 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), so pull_request_target/workflow_run runs 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: true when unset (governor_ci.go:10-12) matches #16603's "default true".

I have not approved or closed anything.

— hive: agent=reviewer backend=copilot model=claude-fable-5.1 copilot=1.0.88

@hivecommons-hive

hivecommons-hive Bot commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Hive status — updated in place; edits do not notify. Full history is in the Activity Monitor.

Review findings from reviewer-2 (folded here because this head already carries its hive review):

Two things, in order of urgency.

1. The head does not compile. src/pkg/dashboard/stage_tracker_activity.go:447 (stageTrackerUnreportedChecksSentence) still calls pluralVerb, but this PR deletes the helper (diff hunk at old line ~316). go build ./... at 6a269be: pkg/dashboard/stage_tracker_activity.go:447:74: undefined: pluralVerb. That is the single cause of the red build-go, golangci-lint, every test (dashboard …) shard and the docker (hive|hub) jobs. The caller existed at the merge-base (dcc92db), so this is not a rebase race — restoring the helper (or switching that call to the new plural helper) fixes all of them.

2. This is a trust-surface change a maintainer must own, not a reviewer. SweepWorkflowApprovals (src/pkg/github/workflow_auto_approval.go:41-162) POSTs actions/runs/{id}/approve, which is exactly the gate GitHub puts between untrusted PR code and the repository's CI rights. Facts for whoever decides:

  • Default-on. src/pkg/config/governor_ci.go:11 — AutoApproveWorkflows == nil means enabled. hive.yaml.example:416-420 presents the keys as a commented-out opt-in, so every hive that upgrades starts approving gated runs for dependabot[bot], renovate[bot], the App itself, and any PR carrying the automerge label (lgtm by default) without having configured anything. If opt-in is the intent, the nil case should be false.
  • Trust is per author or per triggering actor, not per run as the body states. workflow_auto_approval.go:21-34 returns true if either fresh.GetUser().GetLogin() or workflowTriggeringActor(run) matches. So on a trusted author's head every run is admitted regardless of who triggered it, and on an untrusted author's head a run whose triggering actor is the hive App is admitted. I could not verify from the tree whether any hive writeback (writeback.KindCIRerun is reused here as the permission class, line 131) can become the triggering actor of an action_required run on a fork PR — stating it as an open question, not a defect.
  • Author is a fork (thatguywob/hive); the body says the PR was authored by the scanner agent and overlaps ✨ Activity Monitor chevrons: active-with-text / icon-only spec, ring glyph, workflow-approval stall caption #16600. Author holds no OWNERS role.

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 adjudicator-2 (folded here because this head already carries its hive review):

HUMAN DECISION NEEDED — thatguywob / clubanderson: should a bare lgtm label (not bound to the current head SHA) be enough for the hive to approve gated workflow runs on fork PRs?

Security delta re-review 6384f9b..95f9fdc: the PR's own files are byte-identical between heads (workflow_auto_approval.go, workflow_approval.go, governor_ci.go, client.go, webhook_ci_evidence.go, main_eval_cycle.go, hive.yaml.example); the 57-file delta is the v5 rebase plus two fixup commits (9868124, 95f9fdc) that only touch the dashboard caption. No new security surface.

Prior finding — still present (in-scope): src/pkg/github/workflow_auto_approval.go:86-93 sets admitted from the current label list of the fresh PR read, and :17-19 short-circuits trust on it. The fresh read at :82-83 pins the head SHA, but not when the label was applied: a fork contributor whose earlier head earned lgtm can push a new commit and the hive approves its gated runs. The repo's own queue path treats lgtm as commit-bound (client.go:3355-3363 records prow/lgtm success on headSHA; :3346-3348 notes Prow strips the label otherwise), so this sweep is looser than the merge gate it sits beside. #16603 names "the owner's lgtm admission" as a trust source but does not say whether it is label-only or commit-bound.

Concrete fix if commit-bound is intended: require the prow/lgtm success status on fresh.GetHead().GetSHA() alongside the label, e.g.

 			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.yaml.example comment and this is approve.)

hive/awaiting-ci: pushed 94610bc restoring pluralVerb, which the v5 merge dropped after the base began using it (build-go: undefined: pluralVerb; every other red lane cascaded from that compile failure). CI pending — sweep will merge when green.


🐝 Hive Agent: scanner | Instance: hosted-available-oke-11-placeholder-r05x | SHA: unknown

— hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88

Review findings from reviewer (folded here because this head already carries its hive review):

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 95f9fdc (fork thatguywob/hive):

1. It is on by default. config/governor_ci.go:10-12: AutoApproveWorkflowsEnabled() returns true when auto_approve_workflows is unset. Every hive that upgrades starts approving gated runs with no config change; hive.yaml.example:418-421 only shows the opt-in form.

2. The hive's own label events make it the trusted actor on fork PRs. workflow_auto_approval.go:17-33 trusts a run when either the PR author or the run's triggering actor equals the App login (:26), and the sweep passes workflowTriggeringActor(run) (:109), i.e. run.triggering_actor (workflow_approval.go:168-173). Two of this repo's pull_request workflows fire on labeled/unlabeled — .github/workflows/changelog-fragment-guard.yml:52 and dco-squash-attribution.yml:22 — and the hive labels every PR it tracks (stage/*, role/*, author/*). For a first-time fork contributor, GitHub creates those runs behind the approval gate with triggering_actor = hivecommons-hive[bot], so the sweep classifies them trusted and POSTs /actions/runs/{id}/approve (:149). A pull_request run executes the workflow file from the PR head, so a fork that edits one of those two workflows gets its code run on the repo's runners (vars.HIVE_RUNNER_LABELS, which may be self-hosted — ci.yml:32, :91) the moment the hive applies a label. The headRepo check at :94 does not prevent this; it only confirms the run belongs to this PR's head.

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; TestWorkflowApprovalTrusted (workflow_auto_approval_test.go:19) covers author/actor matches but not this combination.

If the decision is to keep the feature, two narrowings would close what I found without changing the dependabot/renovate case: default auto_approve_workflows to off (governor_ci.go:11), and drop the App login from the actor match (keep it for author) so a hive label event cannot admit a fork head. The rest of the diff (per-client cache replacing the package-global sync.Map, pagination on the run listing, one-attempt-per-head, 403/404 → PermissionDenied surfacing in the tracker caption) reads correctly to me.

I have not approved, closed, or labelled anything; this is a comment-only review on a fork PR.

@kubestellar-prow kubestellar-prow Bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Nov 4, 2026
@github-actions github-actions Bot added conflicts-with-open-pr Open PR has a merge conflict with another open PR and removed conflicts-with-open-pr Open PR has a merge conflict with another open PR labels Nov 4, 2026
@hivecommons-hive

Copy link
Copy Markdown
Contributor

@thatguywob this PR is back in your court (stage/072-returned-to-contributor). The hive will not merge it until the head changes.

Review asks:

  • the branch conflicts with the base and needs a rebase

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.

@hivecommons-hive

Copy link
Copy Markdown
Contributor

@thatguywob the hive has adopted this PR (stage/074-adopted-by-hive): your hive has been offline since the nudge. The hive will rebase this branch on v5 and fix CI here; your commits and sign-off stay. Push a new head yourself at any time and the hive yields it back to you.

thatguywob and others added 4 commits November 4, 2026 13:18
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>

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 carries AutoMergeLabel() (lgtm, client.go:1485). Default-on, the actor list and lgtm admission 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_repository equal 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 records permission_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–287 keeps the base snapshot's WorkflowApproval when 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.
  • lgtm is 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

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 — admitted is derived from the labels on the freshly fetched PR, and workflowApprovalTrusted(...) (line 110) then approves every held run for pr.HeadSHA. The label is not bound to the SHA it was granted on, so if lgtm survives a new push (e.g. prow lgtm configured 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

@hivecommons-hive

Copy link
Copy Markdown
Contributor

The hive adopted this PR (stage/074-adopted-by-hive) but its head 3e0f6165e66a has not moved for 3h1m and the hive has nothing it can push: adoption-stalled:contributor-lane:decision-requested.

Blocker: the review swarm asked for a human decision: @clubanderson should decide whether the hive may auto-approve gated workflow runs with no governor.ci.auto_approve_workflows key present (the PR enables it by default at src/pkg/config/governor_ci.go:11); #16603 specifies the trust set but not the default..

Moving to stage/085-needs-decision so a person sees it. This is not a merge-approval wait: the lane has not admitted this head.

@hivecommons-hive hivecommons-hive Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 removes pluralVerb, base :316-321) while stageTrackerUnreportedChecksSentence at base :448 still 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 into golangci-lint, docker (hive|hub), every test (dashboard …) shard, overlayfs-exec-guard, govulncheck and build-and-test (run 41941206516). Severity high; consequence: the hive and hub binaries do not build. Fix is to keep pluralVerb (the new deferred block at :92-96 re-implements it inline as verb).

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:

  1. On by default. src/pkg/config/governor_ci.go:10-12 — AutoApproveWorkflowsEnabled() returns true when auto_approve_workflows is unset. Every existing hive installation starts approving gated runs on upgrade.
  2. lgtm admits fork heads. workflow_auto_approval.go:95-98 sets admitted when the PR carries c.AutoMergeLabel(), and :103 requires 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, and workflowApprovalTrusted (: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 apply lgtm here 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>
@hivecommons-hive

Copy link
Copy Markdown
Contributor

Superseded by hive: re-authored as #16681 with the same commits and sign-off because its commits needed a sign-off only a hive-owned branch can carry. This PR is closed; if #16681 fails, hive reopens it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dco-signoff: yes Indicates the PR's author has signed the DCO. hive/superseded Closed by Hive: a different merged PR already landed this change size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

✨ Auto-approve workflow runs gated on GitHub's approve-workflows for trusted bots and admitted PRs

1 participant