Skip to content

Check the PR author's repo permission instead of org association - #28

Merged
tnsardesai merged 2 commits into
mainfrom
hypeship/pr-risk-repo-permission
Oct 28, 2026
Merged

tnsardesai merged 2 commits into
mainfrom
hypeship/pr-risk-repo-permission

Conversation

@tnsardesai

@tnsardesai tnsardesai commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

#26 and #27 didn't fix the "author is not an org member" skips, because no token we have can see private org membership. Every Kernel member is private. A throwaway probe run in kernel/infra checked three tokens (the workflow token, a kernel-internal repo token, and a kernel-internal token requested with members: read):

check result, all three tokens
author_association, from the API and from the pull_request payload CONTRIBUTOR for org members
GET /orgs/kernel/members/{user} 404 for everyone
GET /repos/{repo}/collaborators/{user}/permission write/admin for members, none for kernel-internal[bot] and outsiders

So the check is now "the author has write or admin access to the repo", read with the workflow token. Bots have no repo permission and are still skipped. The one difference from "org member" is that an outside collaborator with write access would also qualify, and they can already push to the repo.

This also removes the read-only app token #27 added, since the workflow token is enough. The credential layout is back to how it was in #25.

Testing

  • The fake PR always reports CONTRIBUTOR, so the tests fail if the check goes back to author_association. New cases cover read/none permission, a silent skip for a bot author, and the exact gh api call for the permission endpoint, including URL-quoting kernel-internal[bot]. All 41 repo tests pass and actionlint is clean.
  • Live gather against real PRs: infra#1741 (member) is eligible, and kernel#4795 (kernel-internal[bot]) is skipped with "author does not have write access".

Note

Medium Risk
Changes who enters automated PR risk classification—a security workflow gate—though behavior aligns with intended trust (people who can push).

Overview
Fixes PR Risk incorrectly skipping private org members, who always appear as CONTRIBUTOR on author_association regardless of token.

Eligibility now requires the PR author to have admin or write on the repo via GET .../collaborators/{user}/permission, which correctly identifies members while still excluding bots (none) and read-only users. Outside collaborators with write access qualify as well—they can already push.

The Generate read token GitHub App step is removed; Gather uses github.token again because the workflow token is sufficient for the permission API. Docs and tests are updated for the new skip reason and API call (including URL-encoding for bot logins).

Reviewed by Cursor Bugbot for commit 29b35e8. Bugbot is set up for automated code reviews on this repo. Configure here.

@tnsardesai
tnsardesai requested review from sjmiller609 and removed request for sjmiller609 October 27, 2026 21:36
@tnsardesai

Copy link
Copy Markdown
Contributor Author

@sjmiller609 my agent went rogue trying to figure out how to get the right permission to gate approval to owners only! so sorry for some many review requests.

I just manually tested that this version though and it looks good! So this should work

See https://github.com/kernel/infra/actions/runs/40590614886/job/122493576280 which tests that eligible=False reason=.github/workflows/pr-risk.yml is on the deny list (.github/**) existing_comment=False

And see https://github.com/kernel/infra/actions/runs/40590621451 which tests the happy case. Leaving a comment like https://github.com/kernel/infra/pull/1852#issuecomment-6454580049

@tnsardesai
tnsardesai merged commit b19d002 into main Oct 28, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants