Skip to content

Fix approval gate using GitHub App token for org membership check#11479

Open
sylvainsf wants to merge 1 commit intomainfrom
fix-approvals-v2
Open

Fix approval gate using GitHub App token for org membership check#11479
sylvainsf wants to merge 1 commit intomainfrom
fix-approvals-v2

Conversation

@sylvainsf
Copy link
Copy Markdown
Contributor

Description

The approval gate in functional-test-cloud.yaml was reverted (#11474) because PR #11435 used permissions: members: read — an invalid GITHUB_TOKEN scope that caused a workflow parse error at line 114 col 7 after merging to main.

This PR re-implements the fix using a GitHub App token from the existing radius-functional-tests app (which already has org-level members:read) instead of the GITHUB_TOKEN.

Root Cause (from #11435)

github.event.pull_request.author_association returns CONTRIBUTOR instead of MEMBER for org members with private membership visibility, causing the approval gate to trigger incorrectly.

Fix

  • Adds a check-trust job that generates an app token via actions/create-github-app-token with permission-members: read
  • Same-repo PRs: Trusted immediately (only users with write access can push branches)
  • Fork PRs from org members: Trusted via gh api orgs/{org}/members/{username} using the app token (works regardless of membership visibility)
  • **Fork PR- **Fork PR- **Fork PR- **Fork PR- **Fork PR- **Fork PR- **Fork PR- **Fork PR- **Fork PR- **Fork PR- **Fork PR- **Fork PR- **Fork PR- **Fork PR- **Fork PR- **Fork PR- **Fork PR- **Fork PR- **Fork PR- **Fork PR- **Fork PR- **Fork Pheck - **Fork PR- **Fork PR- **Fork PR- **Fork PR- **Fork PR- **Fork PR- **Fork PR- **Fork PR- **Fork PR- **Fork PR- **Fork PR- **Fork PR- **Fork PR- **Fork PR- **Fork PR- **Fork PRsue (issue link required).

Fixes: #11435

Contributor checklist

Please verify that the PR meets the following requirements, where applicable:

  • An overview of proposed schema changes is included in a linked GitHub issue.
    • Yes
    • Not applicable
  • A design document PR is created in the design-notes repository, if new APIs are being introduced.
    • Yes
    • Not applicable
  • The design document has been review- The design document has been review- The design document has been review- The design document has been review- The design document has been review- The design document has been review- The design document has been review- The design document has been review- The design document has been review- The design document has been review- The design document has been review- The design document has been review- The design documentation repository](https://github.com/- The design document h c- The design document has been review- The design document has by user facing updates are made.
    • Yes
    • Not applicable
  • A PR fo- A PR fo- A PR fo- A PR fo- A PR fo- A PR fo- A ius-project/recipes) is created, if existing recipes are affected by the changes in this PR.
    • Yes
    • Not applicable

Replace the invalid 'permissions: members: read' (which is not a valid
GITHUB_TOKEN scope) with a GitHub App token from the existing
radius-functional-tests app, which already has org-level members:read.

This correctly identifies org members with private membership visibility,
fixing the false-positive approval gate triggers for private org members.
Copilot AI review requested due to automatic review settings March 24, 2026 10:26
@sylvainsf sylvainsf requested review from a team as code owners March 24, 2026 10:26
@sylvainsf sylvainsf requested a deployment to external-contributor-approval March 24, 2026 10:26 — with GitHub Actions Waiting
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Re-implements the functional-test-cloud approval gate so org members with private membership visibility are treated as trusted contributors, without using the invalid permissions: members: read GITHUB_TOKEN scope.

Changes:

  • Add a check-trust job that uses a GitHub App token to check org membership via the GitHub API.
  • Update approval-gate to depend on check-trust output (is-external) rather than author_association.
  • Adjust setup job dependencies/conditions to ensure tests only proceed when approval is granted (or not required).

Comment on lines +110 to +122
if: github.event_name == 'pull_request_target'
outputs:
is-external: ${{ steps.check.outputs.is-external }}
permissions: {}
steps:
- name: Generate App Token
id: app-token
uses: actions/create-github-app-token@f8d387b68d61c58ab83c6c016672934102569859 # v3.0.0
with:
app-id: ${{ vars.FUNCTIONAL_TEST_APP_ID }}
private-key: ${{ secrets.FUNCTIONAL_TEST_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
permission-members: read
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check-trust runs on pull_request_target for any fork of this repository. On forks, secrets.FUNCTIONAL_TEST_APP_PRIVATE_KEY/vars.FUNCTIONAL_TEST_APP_ID won't exist, so this job will fail and block the workflow. Add a github.repository == vars.RADIUS_REPOSITORY guard (job-level or on the app-token step) so forks skip this logic cleanly, consistent with other steps in this workflow that gate on vars.RADIUS_REPOSITORY.

Copilot uses AI. Check for mistakes.
Comment on lines +115 to +123
- name: Generate App Token
id: app-token
uses: actions/create-github-app-token@f8d387b68d61c58ab83c6c016672934102569859 # v3.0.0
with:
app-id: ${{ vars.FUNCTIONAL_TEST_APP_ID }}
private-key: ${{ secrets.FUNCTIONAL_TEST_APP_PRIVATE_KEY }}
owner: ${{ github.repository_owner }}
permission-members: read

Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The App token is generated unconditionally, even for same-repo PRs where it isn't needed (the job exits before making any API calls). Gate the token generation step so it only runs for fork PRs, to minimize secret usage and reduce blast radius if anything in this job changes in the future.

Copilot uses AI. Check for mistakes.
Comment on lines +128 to +144
HEAD_REPO: ${{ github.event.pull_request.head.repo.full_name }}
BASE_REPO: ${{ github.event.pull_request.base.repo.full_name }}
PR_AUTHOR: ${{ github.event.pull_request.user.login }}
ORG: ${{ github.repository_owner }}
run: |
# Same-repo PRs are always trusted (requires write access to push branches)
if [ "${HEAD_REPO}" = "${BASE_REPO}" ]; then
echo "Same-repo PR from ${PR_AUTHOR} — trusted"
echo "is-external=false" >> "${GITHUB_OUTPUT}"
exit 0
fi

# Fork PR: check if the author is an org member via GitHub API.
# Uses app token which can read org membership regardless of visibility settings.
# gh api returns exit code 0 for 204 (member) and non-zero for 404/302 (not a member).
if gh api "orgs/${ORG}/members/${PR_AUTHOR}" --silent 2>/dev/null; then
echo "Fork PR from org member ${PR_AUTHOR} — trusted"
Copy link

Copilot AI Mar 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For fork PRs, the trust decision is based on github.event.pull_request.user.login (PR author). A PR can be opened from a repo/branch the author has access to but does not own; in that case the head repo owner may be an external user who can still push new commits to the PR branch. Consider checking org membership for github.event.pull_request.head.repo.owner.login (or requiring both author and head repo owner to be members) so the gate is based on who controls the code being executed.

Copilot uses AI. Check for mistakes.
@github-actions
Copy link
Copy Markdown

Unit Tests

    2 files  ±0    416 suites  ±0   6m 56s ⏱️ +9s
4 878 tests ±0  4 876 ✅ ±0  2 💤 ±0  0 ❌ ±0 
5 793 runs  ±0  5 791 ✅ ±0  2 💤 ±0  0 ❌ ±0 

Results for commit 6d7334d. ± Comparison against base commit 612bfd0.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 51.05%. Comparing base (612bfd0) to head (6d7334d).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #11479      +/-   ##
==========================================
- Coverage   51.05%   51.05%   -0.01%     
==========================================
  Files         699      699              
  Lines       44316    44316              
==========================================
- Hits        22626    22624       -2     
- Misses      19522    19523       +1     
- Partials     2168     2169       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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