Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/security-pin-only-upstream-reachability.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- The opt-in `auto_merge.human_merge_pin_only` exception now admits an `action-sha` pin only when the new SHA is anchored in its upstream action repository: with a `# vX[.Y[.Z]]` comment the upstream `tags/vX…` ref (annotated tags dereferenced) must point at exactly that SHA, otherwise the SHA must be an ancestor of the upstream default branch ([#16399](https://github.com/hivecommons/hive/issues/16399)). GitHub resolves a `uses:` SHA across the whole fork network, so a pin-shaped line could otherwise point at a commit pushed to any fork. Any 404, mismatch, rate limit or API error keeps the human-merge-path hold; repos without the key are unaffected. The pin-only commit check now uses the shared PR commit lister ([#16401](https://github.com/hivecommons/hive/issues/16401)).
18 changes: 12 additions & 6 deletions src/docs/hive-merge.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,9 +196,16 @@ commit to the listed identity, since a spoofed committer email is not on the
signer's account and fails verification. Dependabot and Renovate commits are
web-flow committed and signed; a human trusted author must commit and sign as
themselves. A commit list that cannot be fetched, is empty, is longer than
GitHub serves, or does not end at the head holds the PR. The diff check reuses the file list the
GitHub serves, or does not end at the head holds the PR. Finally every new
`action-sha` pin must be anchored in its upstream action repository, because
GitHub resolves a `uses:` SHA across the whole fork network: with a
`# vX[.Y[.Z]]` comment, the upstream `tags/vX…` ref (annotated tags
dereferenced) must point at exactly the new SHA; without one, the new SHA must
be an ancestor of the upstream default branch. A 404, mismatch, rate limit or
any other API error holds the PR. Image digests are content-addressed and need
no such check. The diff check reuses the file list the
path gate already fetches, so a PR the classifier refuses costs no extra API
call; the commit list is read only once the diff qualifies. A repo without an
call; the commit list and upstream refs are read only once the diff qualifies. A repo without an
enabled entry behaves exactly as before. `/hive approve` applies the same check, so its
reply never contradicts the lane. Any other outcome holds the PR as before.
The exception only prevents a new path hold: a PR that already carries `hold`
Expand Down Expand Up @@ -228,10 +235,9 @@ permission/credential/signing text and non-pin edits fail closed.
This classifier proves **syntax only**, not authenticated identity, exact-head
binding, file-list completeness, semantic interpretation or review of upstream
references. The sweep supplies the author (GitHub's PR author login), the
verified-commit provenance of the head and file-list completeness itself; it
does not yet anchor a replaced action SHA to the upstream action's own refs
(GitHub resolves `uses:` SHAs across the fork network; the open second item
of #16399); the relay integration remains #16265;
verified-commit provenance of the head, file-list completeness and the
upstream anchoring of each action SHA itself (#16399); the relay integration
remains #16265;
attribution and safe hold release are tracked in #16269. None of the
schema or classifier APIs grants permission to merge or clears a hold. Native
required checks and producer bindings, freshness, current reviews, substantive
Expand Down
4 changes: 2 additions & 2 deletions src/docs/operator-reference/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ Go callers keep reading `cfg.Agents`, `cfg.Governor.Gateways` and so on through
| `project.label_driven_supersede_park_actors` | `[]` (off) | Automation logins (for example a lifecycle bot running as `github-actions[bot]`) whose park labels a later trusted acceptance supersedes on label-driven repos: Hive removes the label, says so in the release comment, and releases the issue ([#13605](https://github.com/hivecommons/hive/issues/13605)). Park labels added by people, by unlisted bots, or by a listed bot after the acceptance still block; `hold` is never superseded. Per-repo override: `project.repo_policies[].label_driven_supersede_park_actors`. |
| `auto_merge.allow_unprotected_base` | Deprecated no-op. | Accepted so older configs keep loading. `hive-merge` now merges into any protected or unprotected branch the App can write, subject to the CI-evidence gate and GitHub's own merge rules. |
| `auto_merge.no_ci_ok` | Empty by default. | Explicit repo list whose zero-CI merge-request verdict may pass; failing or pending CI evidence is still enforced. |
| `auto_merge.human_merge_pin_only` | Unset (off); enforced by the automerge sweep lanes and `/approve` (#16266), **not yet by the `hive-merge` relay** (#16265). | Per-repo schema for `enabled`, `paths`, `kinds` (`action-sha`, `image-digest`, `version-pin`) and `trusted_authors`. Enabled entries require all three lists. The sweep does not place a human-merge-path hold on a PR whose author is in `trusted_authors`, whose complete diff (every changed file, guarded or not) is pin replacements, and whose every commit is authored by a `trusted_authors` login with a GitHub-verified signature; it never clears an existing hold. See [hive-merge.md](../hive-merge.md) for grammar, restrictions and outstanding integration/deployment requirements (#16242). |
| `auto_merge.human_merge_pin_only` | Unset (off); enforced by the automerge sweep lanes and `/approve` (#16266), **not yet by the `hive-merge` relay** (#16265). | Per-repo schema for `enabled`, `paths`, `kinds` (`action-sha`, `image-digest`, `version-pin`) and `trusted_authors`. Enabled entries require all three lists. The sweep does not place a human-merge-path hold on a PR whose author is in `trusted_authors`, whose complete diff (every changed file, guarded or not) is pin replacements, whose every commit is authored by a `trusted_authors` login with a GitHub-verified signature, and whose every new action SHA resolves in its upstream action repository (the `# vN` tag points at it, or it is on the default branch; #16399); it never clears an existing hold. See [hive-merge.md](../hive-merge.md) for grammar, restrictions and outstanding integration/deployment requirements (#16242). |
| `auto_merge.human_merge_paths` | Unset (off). | Per-repo map of `owner/repo` to glob patterns (same syntax as `intent.guardrail_path_patterns`) for paths a person must merge. Applies to every merge lane (App self-merge, trusted-author, label-queued, merge-request relay) whatever the intent tier; a matching PR is held with one comment, and an incomplete changed-file list fails closed. Details in the sweep key table below. |
| `auto_merge.human_merge_title_prefixes` | `["⚠️", "⚠"]` | Title prefixes (after trimming) that mark a PR as a breaking change a person must merge. Every auto-merge lane and the merge train skip the PR; the tracker parks it at 090 *Ready for human merge · human merge*. Set to `[]` to disable. |
| `auto_merge.human_merge_labels` | `["needs-owner-merge"]` | Labels (case-insensitive) that mark a PR a person must merge; same effect as the title prefixes. Set to `[]` to disable. |
Expand Down Expand Up @@ -526,7 +526,7 @@ auto_merge:
| Repository key | Case-insensitive `owner/repo`; configure each consumer separately. |
| `enabled` | Absent/false preserves the existing human-merge-path gate. |
| `paths` | Explicit allowed paths within the protected path matches, not a replacement for `human_merge_paths`. Required when enabled. |
| `kinds` | Explicit subset of `action-sha`, `image-digest`, `version-pin`; unknown kinds rejected. Required when enabled. |
| `kinds` | Explicit subset of `action-sha`, `image-digest`, `version-pin`; unknown kinds rejected. Required when enabled. An `action-sha` pin is admitted only when the upstream repo's `tags/<version comment>` (annotated tags dereferenced) points at the new SHA, or, without a comment, the SHA is an ancestor of the upstream default branch; any lookup failure holds. |
| `trusted_authors` | Explicit author allowlist; required when enabled. Matched against the PR author login and against the author login of every commit behind the head; each commit must also be committed by GitHub (`web-flow`) or by a trusted login and carry a GitHub-verified signature, since GitHub verifies the committer, not the author (web-flow-committed bot commits qualify; human authors must commit and sign as themselves). Not permission to trust arbitrary bot-looking logins. |

Edit the controller's active `hive.yaml` seed, not the consumer image repo.
Expand Down
111 changes: 87 additions & 24 deletions src/pkg/github/automerge/automerge_human_paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ func (c *Engine) currentHumanMergePinOnly(repo string) (config.PinOnlyException,
// and stays held (#16326). Once the diff is accepted, every commit behind the
// head must itself be provably the trusted author's: the PR author login only
// says who opened the PR, and any principal with write access can push onto
// that branch afterwards. The sweep lanes and /approve share this helper so
// they never disagree.
// that branch afterwards. Finally each new action SHA must resolve in its
// upstream repository, not merely somewhere in its fork network. The sweep
// lanes and /approve share this helper so they never disagree.
func (c *Engine) humanMergePinOnlyExempt(ctx context.Context, owner, repo string, pr *gh.PullRequest, files []intent.ChangedFile, matches []string) (bool, string) {
if len(matches) == 0 || pr == nil {
return false, ""
Expand All @@ -108,13 +109,87 @@ func (c *Engine) humanMergePinOnlyExempt(ctx context.Context, owner, repo string
if reported := pr.GetChangedFiles(); reported <= 0 || reported != len(files) {
return false, "complete changed-file list not proven"
}
if ok, why := intent.ClassifyPinOnly(files, matches, policy.Spec()); !ok {
ok, why, pins := intent.ClassifyPinOnlyActions(files, matches, policy.Spec())
if !ok {
return false, why
}
if why := c.pinOnlyCommitsTrusted(ctx, owner, repo, pr, policy); why != "" {
return false, why
}
return true, "all changes are approved pin replacements by verified trusted-author commits"
if why := c.pinOnlyActionPinsUpstream(ctx, pins); why != "" {
return false, why
}
return true, "all changes are approved pin replacements by verified trusted-author commits, anchored upstream"
}

// pinOnlyMaxTagDepth bounds annotated-tag dereferencing (a tag of a tag).
const pinOnlyMaxTagDepth = 3

// pinOnlyActionPinsUpstream returns "" when every accepted action-sha pin is
// a commit of its upstream action repository. GitHub resolves a `uses:` SHA
// through the whole fork network, so a 40-hex commit pushed to any fork of
// owner/repo is a valid pin; the classifier sees syntax only. A pin with a
// version comment must be exactly what tags/<version> (dereferenced through
// annotated tags) points at; one without must be an ancestor of the upstream
// default branch. Any API error, 404 or mismatch fails closed with a reason.
// Image digests are content-addressed and need no such anchor.
func (c *Engine) pinOnlyActionPinsUpstream(ctx context.Context, pins []intent.ActionPin) string {
if len(pins) == 0 {
return ""
}
ctx = hgithub.WithRESTCaller(ctx, "hive:automerge_pin_only")
for _, pin := range pins {
if why := c.pinOnlyActionPinUpstream(ctx, pin); why != "" {
return fmt.Sprintf("action %s@%s: %s", pin.Repo, stagelabels.ShortSHA(pin.SHA), why)
}
}
return ""
}

func (c *Engine) pinOnlyActionPinUpstream(ctx context.Context, pin intent.ActionPin) string {
owner, repo, ok := strings.Cut(pin.Repo, "/")
if !ok || owner == "" || repo == "" || pin.SHA == "" {
return "upstream repository or commit unknown"
}
if pin.Version != "" {
ref, _, err := c.gh.Git.GetRef(ctx, owner, repo, "tags/"+pin.Version)
if err != nil {
return fmt.Sprintf("tag %s could not be resolved upstream: %v", pin.Version, err)
}
obj := ref.GetObject()
for depth := 0; obj.GetType() == "tag"; depth++ {
if depth == pinOnlyMaxTagDepth {
return fmt.Sprintf("tag %s nests too deeply", pin.Version)
}
tag, _, err := c.gh.Git.GetTag(ctx, owner, repo, obj.GetSHA())
if err != nil {
return fmt.Sprintf("annotated tag %s could not be resolved upstream: %v", pin.Version, err)
}
obj = tag.GetObject()
}
if obj.GetType() != "commit" || !strings.EqualFold(obj.GetSHA(), pin.SHA) {
return fmt.Sprintf("upstream tag %s does not point at the pinned commit", pin.Version)
}
return ""
}
upstream, _, err := c.gh.Repositories.Get(ctx, owner, repo)
if err != nil {
return fmt.Sprintf("upstream repository could not be read: %v", err)
}
branch := upstream.GetDefaultBranch()
if branch == "" {
return "upstream default branch unknown"
}
// base=pin, head=default: "ahead" or "identical" means the pinned commit
// is an ancestor of (reachable from) the upstream default branch.
cmp, _, err := c.gh.Repositories.CompareCommits(ctx, owner, repo, pin.SHA, branch, &gh.ListOptions{PerPage: 1})
if err != nil {
return fmt.Sprintf("pinned commit could not be compared with upstream %s: %v", branch, err)
}
if status := cmp.GetStatus(); status != "ahead" && status != "identical" {
return fmt.Sprintf("pinned commit is not on upstream %s (compare status %q)", branch, status)
}
return ""
}

func pinOnlyTrustedLogin(policy config.PinOnlyException, login string) bool {
Expand All @@ -130,10 +205,6 @@ func pinOnlyTrustedLogin(policy config.PinOnlyException, login string) bool {
return false
}

// pinOnlyCommitsMaxPages bounds the commit listing; GitHub serves at most 250
// commits for a PR, and a pin bump has one or two.
const pinOnlyCommitsMaxPages = 3

// pinOnlyCommitsTrusted returns "" when every commit of pr is attributed to a
// trusted author, was committed by a trusted login or by GitHub itself
// (web-flow), carries a signature GitHub verified, and the current head is
Expand All @@ -153,21 +224,12 @@ func (c *Engine) pinOnlyCommitsTrusted(ctx context.Context, owner, repo string,
return "PR head SHA unknown"
}
ctx = hgithub.WithRESTCaller(ctx, "hive:automerge_pin_only")
opts := &gh.ListOptions{PerPage: 100}
var all []*gh.RepositoryCommit
for page := 0; ; page++ {
if page == pinOnlyCommitsMaxPages {
return "PR commit list too long to verify"
}
commits, resp, err := c.gh.PullRequests.ListCommits(ctx, owner, repo, pr.GetNumber(), opts)
if err != nil {
return fmt.Sprintf("PR commits could not be listed: %v", err)
}
all = append(all, commits...)
if resp == nil || resp.NextPage == 0 {
break
}
opts.Page = resp.NextPage
all, complete, err := hgithub.ListPRRepositoryCommits(ctx, c.gh, owner, repo, pr.GetNumber())
if err != nil {
return fmt.Sprintf("PR commits could not be listed: %v", err)
}
if !complete {
return "PR commit list too long to verify"
}
if len(all) == 0 {
return "PR has no commits to verify"
Expand Down Expand Up @@ -217,7 +279,8 @@ func pinOnlyTrustedCommitter(policy config.PinOnlyException, login string) bool
// ticks) and returns autoMergeReasonHumanMergePath, unless the repo's enabled
// auto_merge.human_merge_pin_only exception qualifies the PR (trusted author,
// complete list, every changed line a pin replacement, every commit a
// verified trusted-author commit) and returns ("", nil).
// verified trusted-author commit, every action SHA anchored in its upstream
// repository) and returns ("", nil).
func (c *Engine) humanMergePathGate(ctx context.Context, displayRepo, owner, repo string, pr *gh.PullRequest) (string, error) {
patterns := c.currentHumanMergePaths(owner + "/" + repo)
if len(patterns) == 0 {
Expand Down
Loading
Loading