-
Notifications
You must be signed in to change notification settings - Fork 0
fix: use collaborator check and CLA_ACCESS_TOKEN for membership verification #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -68,6 +68,8 @@ jobs: | |||||||||||||||||||||||||
| - name: Check Membership (check all PR committers) | ||||||||||||||||||||||||||
| id: check-membership | ||||||||||||||||||||||||||
| if: steps.check-repo.outputs.is_knitli_repo == 'true' | ||||||||||||||||||||||||||
| env: | ||||||||||||||||||||||||||
| CLA_ACCESS_TOKEN: ${{ secrets.CLA_ACCESS_TOKEN }} | ||||||||||||||||||||||||||
| run: | | ||||||||||||||||||||||||||
| set -euo pipefail | ||||||||||||||||||||||||||
| REPO="${{ github.repository }}" | ||||||||||||||||||||||||||
|
|
@@ -146,17 +148,42 @@ jobs: | |||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # Query org membership API | ||||||||||||||||||||||||||
| response=$(curl -s -o /dev/null -w "%{http_code}" \ | ||||||||||||||||||||||||||
| # Check if user is a repository collaborator (works with GITHUB_TOKEN) | ||||||||||||||||||||||||||
| # This API returns 204 if user has push access, 404 otherwise | ||||||||||||||||||||||||||
| collab_response=$(curl -s -o /dev/null -w "%{http_code}" \ | ||||||||||||||||||||||||||
| -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | ||||||||||||||||||||||||||
| "https://api.github.com/orgs/knitli/members/$user") | ||||||||||||||||||||||||||
| "https://api.github.com/repos/$REPO/collaborators/$user") | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if [ "$response" == "204" ]; then | ||||||||||||||||||||||||||
| echo "User $user is a Knitli org member" | ||||||||||||||||||||||||||
| EXEMPT_USERS+=("$user (org member)") | ||||||||||||||||||||||||||
| if [ "$collab_response" == "204" ]; then | ||||||||||||||||||||||||||
| echo "User $user is a repository collaborator" | ||||||||||||||||||||||||||
| EXEMPT_USERS+=("$user (collaborator)") | ||||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| # Fallback: Check org membership using CLA_ACCESS_TOKEN (has org:read scope) | ||||||||||||||||||||||||||
| # Only attempt if CLA_ACCESS_TOKEN is available | ||||||||||||||||||||||||||
| if [ -n "$CLA_ACCESS_TOKEN" ]; then | ||||||||||||||||||||||||||
| org_response=$(curl -s -o /dev/null -w "%{http_code}" \ | ||||||||||||||||||||||||||
| -H "Authorization: Bearer $CLA_ACCESS_TOKEN" \ | ||||||||||||||||||||||||||
| "https://api.github.com/orgs/knitli/members/$user") | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if [ "$org_response" == "204" ]; then | ||||||||||||||||||||||||||
| echo "User $user is a Knitli org member" | ||||||||||||||||||||||||||
| EXEMPT_USERS+=("$user (org member)") | ||||||||||||||||||||||||||
| continue | ||||||||||||||||||||||||||
| elif [ "$org_response" == "404" ] || [ "$org_response" == "302" ]; then | ||||||||||||||||||||||||||
| # 404 = not a member, 302 = requester is not an org member (can't see membership) | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
| # 404 = not a member, 302 = requester is not an org member (can't see membership) | |
| # 404 = not a member or membership is concealed, 302 = authentication/redirect issue (requester is not an org member, cannot see membership) |
Copilot
AI
Dec 2, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The 302 status code typically indicates a redirect and often suggests an authentication issue rather than a definitive "not a member" response. Treating 302 the same as 404 might incorrectly categorize authentication failures as "not a member". Consider treating 302 as an error case (moving it to the else block on line 179) to fail securely when authentication issues occur: elif [ "$org_response" == "404" ]; then
| elif [ "$org_response" == "404" ] || [ "$org_response" == "302" ]; then | |
| # 404 = not a member, 302 = requester is not an org member (can't see membership) | |
| echo "User $user is NOT a collaborator or org member and may require CLA" | |
| NEEDS_CLA+=("$user") | |
| else | |
| # API error (rate limit, network issue, etc.) - fail open and require CLA | |
| elif [ "$org_response" == "404" ]; then | |
| # 404 = not a member | |
| echo "User $user is NOT a collaborator or org member and may require CLA" | |
| NEEDS_CLA+=("$user") | |
| else | |
| # API error (rate limit, network issue, 302 redirect, etc.) - fail open and require CLA |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment states "This API returns 204 if user has push access, 404 otherwise", but the GitHub collaborators API actually returns 204 if the user has any collaborator permission (read, write, or admin), not just push/write access. Consider updating the comment to: "This API returns 204 if user is a collaborator (read/write/admin), 404 otherwise"