ci(security): use default GITHUB_TOKEN for git push, not App token#361
Merged
Conversation
The fix-dependabot-alerts workflow was using the GitHub App token for git push, which required granting the App `Contents: write` at the installation level. That permission wasn't (and didn't need to be) granted, causing the scheduled run to 403 at `git push` with 'Permission to microsoft/TypeChat.git denied to typeagent-bot[bot]'. Match the TypeAgent workflow pattern instead: keep `persist-credentials: false` on checkout (so the token isn't reachable from untrusted `npm` scripts during the verify phase), but at the very end of the job re-inject the workflow's own GITHUB_TOKEN — already scoped to `contents: write` via the workflow-level `permissions:` block — for the git push. The App token is now used only where it must be: - `gh api dependabot/alerts` (the default GITHUB_TOKEN can't reach this endpoint) - `gh pr create` / labels / closing superseded PRs (so the PR identity is the bot, not github-actions) Verified end-to-end: a manual workflow_dispatch run against a temp branch passed git push and opened #360. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
3 tasks
Contributor
There was a problem hiding this comment.
Pull request overview
Updates the fix-dependabot-alerts workflow to push remediation branches using the workflow-scoped default GITHUB_TOKEN (with contents: write) instead of the GitHub App token, aligning with the intended permission model and avoiding push failures due to missing App installation permissions.
Changes:
- Adds a dedicated
GIT_PUSH_TOKENenvironment variable wired to the defaultGITHUB_TOKENfor authenticatedgit push. - Keeps the GitHub App token (
GH_TOKEN) for Dependabot alerts API access andgh pr createso PRs are authored under the bot identity. - Switches the
git remote set-urlused for pushing to useGIT_PUSH_TOKENrather than the App token.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
The
fix-dependabot-alertsscheduled run is failing atgit pushwith:Root cause confirmed via a diagnostic step on a temp branch:
The workflow was using the GitHub App token for
git push, which requiresContents: writeat the App installation level. That's a permission the App didn't have (and shouldn't need to have — it has no business reading repo content for any other reason).Fix
Match the
microsoft/TypeAgentworkflow pattern: keeppersist-credentials: falseonactions/checkout(so the token isn't reachable from untrustednpminstall/build/test phases), but at the very end of the job — after all untrusted code has run — re-inject the workflow's ownGITHUB_TOKEN, already scoped tocontents: writevia the workflow-levelpermissions:block, for thegit push.The App token is now used only where it must be:
gh api dependabot/alerts(the defaultGITHUB_TOKENcan't reach this endpoint)gh pr create/ labelling / closing superseded PRs (so the PR identity is the bot, notgithub-actions)Verification
Manually triggered a
workflow_dispatchrun against a temp branch carrying this same patch — it passedgit pushand opened #360 with the legitimateminimatchpatch. Logs: https://github.com/microsoft/TypeChat/actions/runs/26842937700Cleanup follow-ups
dev/talzacc/diag-app-tokenwill be deleted after this lands.