fix: do not shadow caller GITHUB_TOKEN with GITHUB_APM_PAT#21
Merged
danielmeppiel merged 2 commits intomainfrom Mar 26, 2026
Merged
fix: do not shadow caller GITHUB_TOKEN with GITHUB_APM_PAT#21danielmeppiel merged 2 commits intomainfrom
danielmeppiel merged 2 commits intomainfrom
Conversation
When a caller provides GITHUB_TOKEN via step/job-level env: (e.g., a GitHub App token minted by gh-aw for cross-org private repo access), the action must not set GITHUB_APM_PAT to the default github.token. APM CLI token precedence is GITHUB_APM_PAT > GITHUB_TOKEN > GH_TOKEN. Before this fix, GITHUB_APM_PAT was unconditionally set to the action default (github.token, scoped to the workflow repo only), which shadowed the caller intentional GITHUB_TOKEN in APM resolution chain. This caused "Repository not found" / "Authentication failed" errors when installing packages from cross-org private repos. Fix: only forward github-token to GITHUB_APM_PAT when GITHUB_TOKEN was NOT already present in the environment, indicating no caller has provided a higher-specificity token. Fixes microsoft/apm#425 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Fixes token precedence issues when callers provide GITHUB_TOKEN via workflow/step env: by avoiding injecting the action’s default github-token into the higher-precedence GITHUB_APM_PAT, preventing accidental auth shadowing in APM.
Changes:
- Update token-export logic to only set
GITHUB_APM_PATwhenGITHUB_TOKENwasn’t already present. - Extend/add tests to ensure caller-provided
GITHUB_TOKENis preserved and not shadowed. - Regenerate
dist/index.jsto reflect the source change.
Reviewed changes
Copilot reviewed 2 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/runner.ts | Adjusts env var forwarding to avoid shadowing caller GITHUB_TOKEN with GITHUB_APM_PAT. |
| src/tests/runner.test.ts | Adds/updates tests covering the shadowing scenario (incl. gh-aw reproduction). |
| dist/index.js | Compiled output reflecting src/runner.ts changes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Addresses Copilot review: an empty-string GITHUB_TOKEN is not nullish, so ??= would not overwrite it. Use truthiness check (!!) instead of != null so both empty-string and undefined are treated as "no caller token", ensuring the github-token input is forwarded correctly. Adds regression test for the empty-string edge case. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a caller provides
GITHUB_TOKENvia step/job-levelenv:(e.g., a GitHub App token minted by gh-aw for cross-org private repo access), the action was unconditionally settingGITHUB_APM_PATto its defaultgithub-tokeninput (${{ github.token }}).APM CLI's token resolution precedence is:
Since
GITHUB_APM_PATtakes priority, APM would use the wrong token (the Actions workflow default, scoped only to the current repo) instead of the caller's intentionalGITHUB_TOKEN(the App token with cross-org access). This caused"Repository not found"/"Authentication failed"errors for users installing packages from cross-org private repos.Root Cause
Commit
cc84c04(v1.4.0) added:where
githubToken = core.getInput('github-token')defaults to${{ github.token }}— the Actions runner's automatic token, not any env var.The
??=operator correctly avoids clobbering an explicitly setGITHUB_APM_PAT, but it does not account for the case where the caller has setGITHUB_TOKEN(notGITHUB_APM_PAT) to a higher-specificity token. The result is a token mismatch:GITHUB_TOKENenv:GITHUB_APM_PAT${{ github.token }}(workflow-repo only)GITHUB_APM_PAT(wrong!)Fix
Only forward the
github-tokeninput toGITHUB_APM_PATwhenGITHUB_TOKENwas not already present in the environment. When a caller has explicitly providedGITHUB_TOKEN, they control auth and we must not inject a lower-specificity token into the higher-precedence variable.Testing
GITHUB_APM_PATis not set whenGITHUB_TOKENis already presentAffected Users
Any gh-aw user with
dependencies.github-appconfiguration that uses apm-action >= v1.4.0. The user's workflow generates a GitHub App token with cross-org access, sets it asGITHUB_TOKEN, but the action shadows it with the default token viaGITHUB_APM_PAT.Fixes microsoft/apm#425