Repository navigation
✨ feat(ci): approve gated workflows for trusted PR heads - #16681
hivecommons-hive[bot] wants to merge 10 commits into
Conversation
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: #16603 Hive-Plan: workflow-approval-sweep Hive-Spec: #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>
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>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 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 |
Open PR overlap checkBase branch: Conflicts are checked with every PR merged onto the current tip of
|
|
Hive status — updated in place; edits do not notify. Full history is in the Activity Monitor. Hive filed review findings that do not block this PR as backlog items:
Cap: 10 backlog item(s) per PR per day. Review findings from Correctness review (head 94610bc, read against the diff plus The decision path is well guarded (fresh PR re-read, per-run head-repo/SHA/PR match, claim-before-POST ledger, writeback gate) and the tests exercise once-per-head, concurrency, pagination and the 403/404 refusal. Two small gaps and one process note:
hive/awaiting-ci: the red 🐝 Hive Agent: — hive: agent=scanner backend=copilot model=claude-fable-5.1 copilot=1.0.88 |
There was a problem hiding this comment.
Decision needed: @clubanderson should confirm that governor.ci.auto_approve_workflows ships default-on (per #16603), so every hive that upgrades starts approving GitHub-gated workflow runs for dependabot/renovate/App/lgtm heads without an explicit opt-in.
I read the tree at v5 plus the diff, not just the diff. No defect found; routing because this is a new CI-rights write that is on by default, and that sign-off belongs to a person.
What I verified
- Trust decision
src/pkg/github/workflow_auto_approval.go:17-36matches #16603 exactly: PR author or triggering actor in the allowlist (defaultdependabot[bot],renovate[bot]atsrc/pkg/config/governor_ci.go:16-19), the App login, or the owner-admittedlgtmlabel.lgtmisAutoMergeQueuedLabel(src/pkg/github/client.go:1484) and the hive only applies it through the owner decision path (pkg/dashboard/api_repo_item_decision.go:625-627→QueuePRAutoMerge…atclient.go:3237), soadmittedis not self-granting. - Before any POST the sweep re-fetches the PR (
workflow_auto_approval.go:84-86) and bails if state/draft/head changed, then requires each run's head repo to equal the PR's head repo and the run to be linked to this PR number (:98-110). Hold/exempt/sentinel labels and repo pause short-circuit at:51and:89. Writeback is gated asKindCIRerun(:138). - Once-per-head:
attemptedis claimed under the mutex before the first POST (:142-151), so a concurrent cycle cannot double-approve. 403/404 persistspermissionDeniedviarecord()(workflow_approval.godiff hunk,attempt.permissionDenied = true) and later cycles re-surface it at:76without further writes — matches the issue's "record the refusal once". - Wiring:
src/cmd/hive/main_eval_cycle.gocallsSweepWorkflowApprovalsafter CI enrichment and skips it underSkipOptionalbudget.
One nit (info, not blocking)
workflow_auto_approval.go:15-16 says the check is "deliberately per run: one trusted triggering actor must not authorize other actors' runs on the same PR head", but the author branch of the same function authorizes every actor's run on a head whenever the PR author is trusted. The behaviour is what #16603 asked for; the comment just overstates the guarantee. Worth a one-line fix so the next reader does not rely on it.
Why a human, not the hive: this grants the App a new write (POST /actions/runs/{id}/approve) that lets fork-origin code run with the repository's CI rights, and AutoApproveWorkflowsEnabled() is true when the key is absent (governor_ci.go:10-12). #16603 chose that default; I am asking only that the owner knowingly accept it at merge time rather than discover it on the next upgrade. Checks: one early Sign-off survives the squash run failed, the later ones on this head pass — tide will settle that.
— hive: agent=reviewer backend=copilot model=claude-fable-5.1 copilot=1.0.88
Review follow-ups for #16681: - The attempts ledger is now evicted: a sweep drops superseded heads of the same PR immediately and ages out entries no sweep has observed for 24h, instead of retaining every gated head for the process lifetime. - CI enrichment applies the ledger's permission-refusal flag itself, so budget-mode cycles that skip SweepWorkflowApprovals keep the "needs workflow approval on GitHub" caption instead of regressing to the count. - The workflowApprovalTrusted doc comment now states the #16603 rule: a trusted author authorizes every run on the head; otherwise trust is per triggering actor. Hive-Fix-Attempt: 1/6 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: ci-maintainer <280983584+hivecommons-hive[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Decision needed: @clubanderson should confirm that hive may start approving GitHub's "Approve and run workflows" gate by default (governor.ci.auto_approve_workflows unset → on) for dependabot[bot]/renovate[bot], App-authored and lgtm-admitted PR heads, given CI runs on self-hosted runners.
Read against v5 at head e06da93. The code does what #16603 specifies and I found no correctness defect; this is routed to a person only because it hands the hive a new CI-execution permission, and that is an owner's call, not mine.
What I verified
- Trust decision (
src/pkg/github/workflow_auto_approval.go:21-39) is exactly the #16603 rule set: owner admission label, App login, or author/triggering-actor in the allowlist. Admission isc.AutoMergeLabel()(lgtmby default), which is applied by the owner/merger queue action atsrc/pkg/github/client.go:3237, so "admitted" really is an owner's act. - Freshness: before any POST it re-fetches the PR (
workflow_auto_approval.go:83-85) and requires open, non-draft, and head SHA unchanged; runs are filtered tohead_sha == PR head,event == pull_request(workflow_approval.go,workflowRunsAwaitingApproval), andhead_repository == PR head repo(workflow_auto_approval.go:97). A run from a different fork or a superseded push cannot be approved against this PR. - Bounded:
attemptedis claimed under the mutex before the first POST (workflow_auto_approval.go:137-145), so a concurrent cycle or an unchanged head cannot repeat the pass; per-PR superseded heads and >24h entries are evicted intouchAttempt. - Gated by the existing writeback policy (
WritebackAllowed(... KindCIRerun ...), line 131), hold/exempt/sentinel labels (workflowApprovalHeld), paused repos, and the governor budget (main_eval_cycle.go:584skips it underSkipOptional). - 403/404 is recorded once as
permission_error, surfacesPermissionDeniedin the CI caption, and the loop breaks rather than hammering the API. - Defaults (
src/pkg/config/governor_ci.go:10-20): enabled when unset; actors default todependabot[bot],renovate[bot]; an explicit[]trusts only App + admission. All three are stated in #16603, so I am not re-asking them — only asking the owner to confirm the trust surface as a whole.
Facts for the decision
- Author of record is the hive App (adoption of #16615 by @thatguywob, head preserved unchanged). The issue was filed by @clubanderson.
- Behaviour change on upgrade: any hive without
governor.ciconfigured starts approving gated runs for the default trust set on its next cycle.pull_requestruns from forks get a read-onlyGITHUB_TOKENand no secrets, but on self-hosted runners the approved job still executes the head's workflow files on hive infrastructure. For dependabot/renovate/App heads that is the intended trade; the owner should be the one to accept it. - Note that a trusted author authorizes every gated run on the head, including runs triggered by a later pusher to that branch (
workflow_auto_approval.go:25-27). That is per #16603 ("the code under test is theirs"), just stating it plainly.
One low finding (docs-currency)
src/docs/operator-reference/runtime-and-quota.mdandsrc/docs/webhooks.md:116document the sibling yaml-only keygovernor.ci_failure_webhook_kick; the two newgovernor.ci.*keys appear only inhive.yaml.exampleand the parity allowlist. Suggest a row in the operator reference so the default-on behaviour is discoverable before an operator notices CI starting itself.
Not approving or requesting changes; the decision above is the only thing standing between this and a maintainer merge.
— hive: agent=reviewer-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88
…eference Review finding (docs-currency): the new governor.ci.auto_approve_workflows and governor.ci.auto_approve_workflow_actors keys were only in hive.yaml.example and the settings parity allowlist. Add them beside the sibling governor.ci_failure_webhook_kick entries in docs/operator-reference/runtime-and-quota.md (behaviour, trust set, guards, default-on note, status counts, log lines) and the configuration table in docs/webhooks.md. Hive-Fix-Attempt: 2/6 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: ci-maintainer <280983584+hivecommons-hive[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Decision needed: @clubanderson should confirm that the hive App may auto-approve GitHub's "Approve and run workflows" gate (default on when governor.ci.auto_approve_workflows is unset) for dependabot/renovate, App-triggered and owner-admitted heads on this org's runners — this is a CI-trust decision, not a code defect.
Routing to an approver because this grants the hive a new CI-trust capability (approving fork/bot workflow runs that then execute on the repository's runners). I read the full diff against v5, pkg/github/workflow_approval.go, the callers in main_eval_cycle.go:584 and client.go:2568, and the admission path. I found no defect; the guards are real and tested. The facts an approver needs:
What it does. SweepWorkflowApprovals (workflow_auto_approval.go:46) runs after EnrichCIStatus for open, non-draft, non-green PRs. For a head with action_required runs it re-reads GET /pulls/N (head SHA, state, draft, author, labels) before any write, then approves via POST /actions/runs/{id}/approve when workflowApprovalTrusted (:21) says yes.
Who gets trusted. Per #16603, exactly: PR author or run's triggering actor in governor.ci.auto_approve_workflow_actors (default dependabot[bot], renovate[bot]), or equal to AppBotLogin(), or the PR carries the automerge label. I checked the label path: it is only applied through an owner's dashboard decision (api_repo_item_decision.go:627 → QueuePRAutoMergeWithNoteResultAtHead, client.go:3237), so "admitted" really is owner-gated.
Guards I verified in code. Held / exempt / sentinel labels and repo pause skip the PR (:58, :166); runs are listed with event=pull_request and filtered again on exact head SHA (workflow_approval.go:159-174), so pull_request_target and foreign heads never reach the approve call; every run must have head_repository == fresh.head.repo (:101) and, when GitHub populates run.pull_requests, must link this PR; the writeback gate ci_rerun must allow it (:128); and the attempt is claimed before the first POST so a concurrent cycle cannot double-approve (:134-142, TestSweepWorkflowApprovalsConcurrentPasses). 403/404 is recorded once and surfaces as a caption instead of retrying (TestSweepWorkflowApprovalsPermissionRefusalOnce).
Defaults. Unset = on (governor_ci.go:11). That is what #16603 asked for and runtime-and-quota.md says so plainly, including the self-hosted-runner opt-out — so I am not re-asking the default, only whether the capability itself is wanted.
Two open questions, neither verified as a defect:
- Trust follows the triggering actor. A run on an untrusted fork head that the App itself re-triggers would have
triggering_actor = Appand be approved (:21-37, "trust is per run"). I could not find a path in this tree where the hive re-runs anaction_requiredrun (they have no check runs, so the CI-rerun writeback never sees them as failing), so I believe this is unreachable today; stating it so the approver knows the model. - Denied heads are re-evaluated every cycle.
attemptedis only set after a successful claim (:134-139), so a gated PR from an untrusted contributor costs oneGET /pulls/Nper cycle (after the 90s probe TTL) until it is admitted or closed. That is intentional (TestSweepWorkflowApprovalsDeniedCanBeAdmittedLater) and cheap, just noting the API cost on repos with many first-time fork PRs.
Body ↔ diff: the superseder body says it is #16615's head unchanged plus fix commits; the branch is 94610bc + two signed commits (e06da93 ledger bounding + refusal evidence, c4b15fc docs), which matches. CI is green at c4b15fc.
— hive: agent=reviewer-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88
runtime-and-quota.md and webhooks.md said the approval sweep runs after every CI enrichment pass. main_eval_cycle.go only calls SweepWorkflowApprovals when the eval budget decision does not shed optional steps, so it is skipped in conserve/critical API-budget mode, on off-cadence cycles and on cached (webhook-wake) cycles. Say so, and note that EnrichCIStatus still runs on those cycles so the `waiting on workflow approval` state stays visible until the next full normal-mode cycle approves the head. Hive-Fix-Attempt: 3/6 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: ci-maintainer <280983584+hivecommons-hive[bot]@users.noreply.github.com>
There was a problem hiding this comment.
Decision needed: @clubanderson should confirm this trust policy for auto-approving gated workflow runs (default on; App, dependabot[bot], renovate[bot] and lgtm-admitted PRs trusted) before it lands, since it lets the hive start CI on code the gate was holding.
Routing to a human rather than approving: this PR gives the hive the ability to start CI on code GitHub was holding behind "Approve and run workflows". I read the tree at 746fa2b; the code is correct as far as I can verify, and it implements #16603 as written. The facts a maintainer needs:
What is trusted (src/pkg/github/workflow_auto_approval.go:20-39, workflowApprovalTrusted): a run is approved when (a) the PR carries the auto-merge/lgtm label, (b) the PR author or the run's triggering actor is the App bot, or (c) either of those logins is in governor.ci.auto_approve_workflow_actors, defaulting to dependabot[bot], renovate[bot] (src/pkg/config/governor_ci.go:22-27). auto_approve_workflows is on by default (governor_ci.go:16-18). All three are exactly what #16603 specifies, so I am not re-asking them — only asking the owner to confirm before the capability goes live on every repo this hive serves.
Guards I verified exist: the sweep re-fetches the PR before acting and bails if head SHA, open state or draft changed (workflow_auto_approval.go:84-88); runs from a different head repository are skipped (:99-101); held/exempt/sentinel-labelled PRs and paused repos are skipped (:56, :91); the POST goes through WritebackAllowed(..., KindCIRerun, ...) (:134), so repos that already forbid CI-rerun writebacks also forbid this; one attempt per head, claimed before the first POST (:139-147); 403/404 recorded once and surfaced as "needs workflow approval on GitHub" (:150-156). Tests cover the decision table, once-per-head, concurrent passes and permission refusal (workflow_auto_approval_test.go).
One open question, not a defect: because the App is a trusted triggering actor, any hive-initiated rerun of a run on an otherwise-untrusted first-time contributor's PR would make that rerun approvable (:111, workflowTriggeringActor prefers triggering_actor). #16603 asks for App-as-actor trust explicitly, so this is by design; I mention it only so the owner is choosing it knowingly. If that is not wanted, the fix is to drop actor from the App check and keep it for the allowlist.
Superseder of #16615 with @thatguywob's commits preserved; checks green except mobile-shots still running. I have not approved or changed anything.
— hive: agent=reviewer-2 backend=copilot model=claude-fable-5.1 copilot=1.0.88
|
Re-authoring: the hive's fixer gave up on this PR after 6 attempts on |
Supersedes #16615 (adopted in place, re-homed because a hive commit on the contributor branch cannot carry a squash-safe sign-off; original commits by @thatguywob preserved).
Closes #16603
Fixes #16603
This branch is #16615's head
94610bc8a15cas pushed by @thatguywob (forkthatguywob/hive), unchanged. Last lane reason on the original:check-failing:build-and-test.Hive fix agent: rebase this branch on
v5, fix the failing checks / review asks, and push to THIS branch. Keep the original author's commits and theirSigned-off-by; add your own sign-off on your commits. Do not open another PR.Sign-off attribution: the original PR would squash the App's signed fixes as the contributor. This App-authored superseder keeps every original commit and sign-off unchanged and attributes the squash to the App instead. DCO and all merge gates still apply here.