Skip to content

fix: move CODEOWNERS team membership check server-side (#173)#174

Open
mvvmm wants to merge 1 commit into
Cloudflare-Studio:mainfrom
mvvmm:fix/codeowners-team-membership
Open

fix: move CODEOWNERS team membership check server-side (#173)#174
mvvmm wants to merge 1 commit into
Cloudflare-Studio:mainfrom
mvvmm:fix/codeowners-team-membership

Conversation

@mvvmm
Copy link
Copy Markdown
Contributor

@mvvmm mvvmm commented May 12, 2026

Fixes #173.

github.token lacks read:org scope, so team membership checks in checkCodeowners always got 404 — silently treated as "not a member". Individual user entries worked fine because they're matched locally without any API call.

Fix: move team membership checks server-side into handleExchangeToken. When the actor isn't individually listed, orchestrate.ts forwards the team patterns to the OIDC exchange endpoint. The server generates an unscoped installation token (org-level access) to verify membership, then issues the normal scoped repo token if the actor qualifies.

Note: requires the bonk GitHub App to have Organization members: Read permission. Without it, the check fails closed (denies the token).

github.token has no read:org scope, so calls to
GET /orgs/{org}/teams/{team}/memberships/{actor} return 404 (not 403).
This was silently treated as 'not a member', causing team entries in
CODEOWNERS to always fail while individual user entries worked.

Move team membership verification into handleExchangeToken on the server:
- New checkTeamMembership() generates an unscoped installation token
  (org-level access) to call the membership API successfully
- Cross-org team patterns are rejected before any API call (security)
- orchestrate.ts checkCodeowners() returns team patterns instead of
  checking them client-side with github.token
- Team patterns are forwarded in the OIDC exchange request body as
  codeowners_teams + actor; server denies the token if actor is not
  a member of any listed team

Requires the bonk GitHub App to have Organization members: Read
permission configured.

Fixes Cloudflare-Studio#173
@mvvmm
Copy link
Copy Markdown
Contributor Author

mvvmm commented May 12, 2026

/bonk please review

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.

CODEOWNERS permission mode silently ignores team entries — team membership check always fails

1 participant