diff --git a/changelog.d/changed-15182.md b/changelog.d/changed-15182.md new file mode 100644 index 0000000000..e4ced4a1a6 --- /dev/null +++ b/changelog.d/changed-15182.md @@ -0,0 +1 @@ +- The rebase-then-merge follow-through now counts a head as the hive's own by its committer: an email-domain-only match (no GitHub login resolved) needs GitHub to report the commit as verified, and the author counts only when GitHub resolves it to the App bot, since a signature never vouches for the author address ([#15182](https://github.com/hivecommons/hive/issues/15182)). diff --git a/src/docs/operator-reference.md b/src/docs/operator-reference.md index 53aac8ac26..88ae7351d3 100644 --- a/src/docs/operator-reference.md +++ b/src/docs/operator-reference.md @@ -479,7 +479,7 @@ verified owner or an authorized user with the `merger` role: | Decision | What it does | Audit / ledger | |---|---|---| | `merge-now` — *Merge now as maintainer* (secondary; *Approve and let hive merge* leads) | Comments on the PR that @you merged it from the dashboard, then merges it at once through the hive's GitHub App (`MergePRVia`, audit path `dashboard`). Refused when the PR is merged or closed, or when you are its author. | `repo_item_decision_merge`; `last_operator_action.action: merge-now`; toast *merged*. | -| `merge-now` on a PR whose `mergeable_state` is `dirty` or `behind` — *Rebase, then merge as maintainer* | Never a GitHub 405. Records your approval first (/lgtm + /approve naming you), arms a rebase-then-merge follow-through (`/data/rebase-merge-followups.json`), kicks the rebase (update-branch on the hive's own PR when only behind; otherwise the fixer lane, which owns a parked PR with an armed follow-through), and answers `202 rebase-queued`. A 2-minute ticker then reads the PR: `mergeable_state: clean` on the rebased head → merges it with your approval attributed; still `dirty` after 2 h, CI red, or no rebase within the deadline → `failed` with the conflicting files and the options *Adopt into fresh branch* / *Close as superseded* (also left as a note on the PR). Refused on a fork whose author has not allowed maintainer edits (`head-not-pushable`). The approval is bound to the head you read: a new head on a contributor's PR counts as the rebase only when GitHub says the hive committed it (the fixer's rebase or update-branch under the App); a head anyone else pushes after your click settles the follow-through as `failed` (`foreign-head`) with nothing merged, a note on the PR, and *Approve the new head & merge* / *Close as superseded* as the ways out. | `repo_item_decision_merge` with `status: rebase-queued`; `last_operator_action.action: merge-now`, outcome `pending` → `applied` / `failed`, `followed[]` steps `approval-recorded`, `rebase-kicked`, `rebased`, `ci-green`, `merged` / `failed`; row `rebase_merge.state`; toast *rebase queued, merge to follow*. | +| `merge-now` on a PR whose `mergeable_state` is `dirty` or `behind` — *Rebase, then merge as maintainer* | Never a GitHub 405. Records your approval first (/lgtm + /approve naming you), arms a rebase-then-merge follow-through (`/data/rebase-merge-followups.json`), kicks the rebase (update-branch on the hive's own PR when only behind; otherwise the fixer lane, which owns a parked PR with an armed follow-through), and answers `202 rebase-queued`. A 2-minute ticker then reads the PR: `mergeable_state: clean` on the rebased head → merges it with your approval attributed; still `dirty` after 2 h, CI red, or no rebase within the deadline → `failed` with the conflicting files and the options *Adopt into fresh branch* / *Close as superseded* (also left as a note on the PR). Refused on a fork whose author has not allowed maintainer edits (`head-not-pushable`). The approval is bound to the head you read: a new head on a contributor's PR counts as the rebase only when GitHub says the hive committed it — update-branch under the App (author resolved to the App bot) or a committer GitHub resolves to the App bot; a committer matched by the pane identity email domain alone, with no GitHub login resolved, also needs GitHub to report the commit as *verified*, and the author counts only when GitHub resolves it to the App bot ([#15182](https://github.com/hivecommons/hive/issues/15182)). **Operational prerequisite:** the fixer's own rebase of a contributor PR is a plain unsigned git commit (the push broker sets `commit.gpgsign=false`, and the signed-commit reconciler only re-signs PRs the App bot authored), so on a `dirty` contributor PR the follow-through settles `failed` (`foreign-head`) unless the fixer host signs its pushes with a key GitHub verifies against a pane-domain address; *Approve the new head & merge* on the fixer's head is the way out until then. A head anyone else pushes after your click settles the follow-through as `failed` (`foreign-head`) with nothing merged, a note on the PR, and *Approve the new head & merge* / *Close as superseded* as the ways out. | `repo_item_decision_merge` with `status: rebase-queued`; `last_operator_action.action: merge-now`, outcome `pending` → `applied` / `failed`, `followed[]` steps `approval-recorded`, `rebase-kicked`, `rebased`, `ci-green`, `merged` / `failed`; row `rebase_merge.state`; toast *rebase queued, merge to follow*. | | `queue-merge` — *Approve and let hive merge* (lead) | Admits the head (`admitted_by: operator-approval:`), leaves an `APPROVED` review in your name with a note, adds the automerge label, and leaves the merge to the hive's auto-merge sweep, which merges through its own App on the next tick once CI is green and the head has soaked. On an untrusted author's PR that admission is the one thing that lets the trusted-author lane merge it: the lane's `untrusted-author-role` skip yields to the recorded approval for that exact head, and the merge comment names you (*merged by Hive on behalf of @you …*). Refused on your own PR. | `repo_item_decision_queue_merge`; `last_operator_action.action: queue-merge`; toast *approved — hive will merge on the next tick once CI is green*. | **Approve is the trust override for that head diff --git a/src/pkg/github/pr_merge_state.go b/src/pkg/github/pr_merge_state.go index a543c7d0bd..08d3b5fcab 100644 --- a/src/pkg/github/pr_merge_state.go +++ b/src/pkg/github/pr_merge_state.go @@ -110,11 +110,21 @@ func (c *Client) GetPRMergeState(ctx context.Context, repo string, number int) ( } // CommitByHive reports whether the commit at sha is the hive's own work: -// its author or committer resolves to the App bot (by login or noreply -// address) or to an address in the pane identity domain — the fixer's -// rebase or GitHub's update-branch under the App. A head a person pushed -// after a rebase-then-merge approval is new content the approval never -// covered, so the follow-through fails closed on it (hivecommons/hive#15104). +// its committer resolves to the App bot (by login or noreply address) or to +// an address in the pane identity domain, or its author resolves by login +// to the App bot, as on GitHub's update-branch under the App. When GitHub +// resolves no login for the committer, the email-only match also requires +// the commit's signature to be verified by GitHub, which binds the signing +// key to the committer address only (hivecommons/hive#15182); the author is +// free text GitHub never vouches for, so no email-only author match counts. +// The fixer's plain-git rebase of a contributor PR is an unsigned, +// email-only pane committer (the push broker sets commit.gpgsign=false and +// the signed reconcile pass only walks App-authored PRs), so it does not +// count unless the fixer host signs its pushes — the follow-through then +// settles foreign-head rather than trusting a spoofable address. A head a +// person pushed after a rebase-then-merge approval is new content the +// approval never covered, so the follow-through fails closed on it +// (hivecommons/hive#15104). func (c *Client) CommitByHive(ctx context.Context, repo, sha string) (bool, error) { if c == nil || c.client == nil { return false, ErrNoGitHubClient @@ -128,10 +138,19 @@ func (c *Client) CommitByHive(ctx context.Context, repo, sha string) (bool, erro if err != nil { return false, fmt.Errorf("reading %s/%s@%s: %w", owner, repoName, shortSHA(sha), err) } - if c.hiveCommitIdentity(safeGetLogin(rc.GetCommitter()), rc.GetCommit().GetCommitter().GetEmail()) { - return true, nil + committerLogin := safeGetLogin(rc.GetCommitter()) + if c.hiveCommitIdentity(committerLogin, rc.GetCommit().GetCommitter().GetEmail()) { + // An email-only match (no login resolved) counts only on a commit + // GitHub verified; a login resolved to the App bot counts as is. + if committerLogin != "" || rc.GetCommit().GetVerification().GetVerified() { + return true, nil + } } - return c.hiveCommitIdentity(safeGetLogin(rc.GetAuthor()), rc.GetCommit().GetAuthor().GetEmail()), nil + // The author counts only by a login resolved to the App bot: a signature + // never covers the author address, so a verified commit proves nothing + // about an email-only author match. + authorLogin := safeGetLogin(rc.GetAuthor()) + return authorLogin != "" && c.hiveCommitIdentity(authorLogin, rc.GetCommit().GetAuthor().GetEmail()), nil } // PRConflictCandidates names the files a PR changed that its base also diff --git a/src/pkg/github/pr_merge_state_commit_by_hive_test.go b/src/pkg/github/pr_merge_state_commit_by_hive_test.go new file mode 100644 index 0000000000..56a6ccc31b --- /dev/null +++ b/src/pkg/github/pr_merge_state_commit_by_hive_test.go @@ -0,0 +1,78 @@ +package github + +import ( + "context" + "encoding/json" + "net/http" + "net/http/httptest" + "testing" +) + +// An email-only hive committer identity (no login resolved) counts as the +// hive's own only on a commit GitHub verified; a login resolved to the App +// bot counts whatever the verification. GitHub's verification binds the +// signing key to the committer address only, so an email-only author match +// never counts, verified or not (hivecommons/hive#15182). +func TestCommitByHive(t *testing.T) { + t.Setenv(signedTrailerDomainEnv, "") + type identity struct{ login, email string } + cases := []struct { + name string + author, committer identity + verification map[string]any + want bool + }{ + {"email only, verified", identity{"", "quality@hive.kubestellar.io"}, identity{"", "quality@hive.kubestellar.io"}, map[string]any{"verified": true}, true}, + {"email only, unverified", identity{"", "quality@hive.kubestellar.io"}, identity{"", "quality@hive.kubestellar.io"}, map[string]any{"verified": false}, false}, + {"email only, no verification", identity{"", "quality@hive.kubestellar.io"}, identity{"", "quality@hive.kubestellar.io"}, nil, false}, + {"bot noreply email only, unverified", identity{"", "1+hive-app[bot]@users.noreply.github.com"}, identity{"", "1+hive-app[bot]@users.noreply.github.com"}, map[string]any{"verified": false}, false}, + {"bot login, unverified", identity{reconcileBot, "anything@example.com"}, identity{reconcileBot, "anything@example.com"}, map[string]any{"verified": false}, true}, + {"bot login, no verification", identity{reconcileBot, "anything@example.com"}, identity{reconcileBot, "anything@example.com"}, nil, true}, + {"person login, verified", identity{"alice", "quality@hive.kubestellar.io"}, identity{"alice", "quality@hive.kubestellar.io"}, map[string]any{"verified": true}, false}, + // A signer forging --author into the pane domain: the signature vouches + // for alice as committer, never for the author address. + {"person committer, email-only pane author, verified", identity{"", "quality@hive.kubestellar.io"}, identity{"alice", "alice@example.com"}, map[string]any{"verified": true}, false}, + {"person committer, email-only bot noreply author, verified", identity{"", "1+hive-app[bot]@users.noreply.github.com"}, identity{"alice", "alice@example.com"}, map[string]any{"verified": true}, false}, + // update-branch under the App: author resolves to the bot, GitHub commits. + {"bot login author, web-flow committer", identity{reconcileBot, "1+hive-app[bot]@users.noreply.github.com"}, identity{"web-flow", "noreply@github.com"}, map[string]any{"verified": true}, true}, + {"bot login author, web-flow committer, unverified", identity{reconcileBot, "1+hive-app[bot]@users.noreply.github.com"}, identity{"web-flow", "noreply@github.com"}, nil, true}, + // The fixer's rebase keeps the person as author; the hive commits. + {"person author, email-only pane committer, verified", identity{"alice", "alice@example.com"}, identity{"", "fixer@hive.kubestellar.io"}, map[string]any{"verified": true}, true}, + {"person author, email-only pane committer, unverified", identity{"alice", "alice@example.com"}, identity{"", "fixer@hive.kubestellar.io"}, map[string]any{"verified": false}, false}, + } + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.URL.Path != "/repos/acme/widget/commits/abc123" { + t.Fatalf("unexpected request: %s %s", r.Method, r.URL.String()) + } + commit := map[string]any{ + "author": map[string]any{"name": "n", "email": tc.author.email}, + "committer": map[string]any{"name": "n", "email": tc.committer.email}, + "message": "m", + } + if tc.verification != nil { + commit["verification"] = tc.verification + } + body := map[string]any{"sha": "abc123", "commit": commit} + if tc.author.login != "" { + body["author"] = map[string]any{"login": tc.author.login} + } + if tc.committer.login != "" { + body["committer"] = map[string]any{"login": tc.committer.login} + } + json.NewEncoder(w).Encode(body) + })) + defer server.Close() + c := NewClientForTest(server.URL, "acme", []string{"widget"}, nil) + c.SetAppBotLogin(reconcileBot) + got, err := c.CommitByHive(context.Background(), "acme/widget", "abc123") + if err != nil { + t.Fatalf("CommitByHive: %v", err) + } + if got != tc.want { + t.Errorf("CommitByHive = %v, want %v", got, tc.want) + } + }) + } +}