Skip to content

fix(dependabot-rebase): use GITHUB_TOKEN for update-branch to fix HTTP 403 on workflow files#141

Merged
don-petry merged 3 commits intomainfrom
fix/dependabot-rebase-github-token
Apr 16, 2026
Merged

fix(dependabot-rebase): use GITHUB_TOKEN for update-branch to fix HTTP 403 on workflow files#141
don-petry merged 3 commits intomainfrom
fix/dependabot-rebase-github-token

Conversation

@don-petry
Copy link
Copy Markdown
Contributor

Problem

The `dependabot-automerge-petry` GitHub App lacks the `workflows` permission. When `update-branch` merges main into a Dependabot PR branch and main contains new/updated `.github/workflows/` files, the API returns HTTP 403:

```
gh: refusing to allow a GitHub App to create or update workflow
`.github/workflows/feature-ideation-reusable.yml`
without `workflows` permission (HTTP 403)
```

This was silently preventing all Dependabot branch updates since new workflow files were added to main (via PRs #139, #140).

Fix

Use `GITHUB_TOKEN` for the `update-branch` API call. In a `push`-triggered workflow, `GITHUB_TOKEN` has implicit `workflows: write` permission. Reserve the app bot token for approvals and merges, where its identity matters:

Operation Token Why
`update-branch` `GITHUB_TOKEN` Has `workflows` write permission
Approve App token Approval attributed to trusted bot identity
Merge App token Push attributed to app → triggers workflow again (self-sustaining chain)

Security benefit

Using `GITHUB_TOKEN` (github-actions bot) as the pusher and the app as the approver cleanly satisfies `require_last_push_approval` — the pusher and approver are now definitively different identities, removing any ambiguity raised in PR #140's review.

Changes

  • Job permissions: `contents: write`, `pull-requests: write`, `workflows: write`
  • `update-branch` call: uses `GITHUB_TOKEN` (via default `GH_TOKEN` env)
  • Approvals and merges: use `APP_TOKEN` (explicitly via `GH_TOKEN="$APP_TOKEN"` prefix)

🤖 Generated with Claude Code

… for approvals

The GitHub App lacks 'workflows' permission, causing update-branch to fail
with HTTP 403 when the merge would include .github/workflows/ changes from main.

Fix: use GITHUB_TOKEN (which has implicit workflows write permission in
push-triggered workflows) for the update-branch call. Reserve the app token
for approvals and merges, where the app bot identity matters:
- Approvals: attributed to the trusted app bot (satisfies require_last_push_approval
  since GITHUB_TOKEN was the pusher, not the app)
- Merges: attributed to the app bot so the resulting push to main re-triggers
  this workflow, enabling the self-sustaining serialization chain

Also adds contents:write, pull-requests:write, workflows:write permissions
to the job so GITHUB_TOKEN can perform these operations.
Copilot AI review requested due to automatic review settings April 16, 2026 17:54
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 16, 2026

Warning

Rate limit exceeded

@don-petry has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 9 minutes and 21 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 9 minutes and 21 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 7aeb8f70-9e67-45e6-b7ef-dcbc76b24498

📥 Commits

Reviewing files that changed from the base of the PR and between 35e0e20 and a06933c.

📒 Files selected for processing (3)
  • .github/workflows/dependabot-rebase-reusable.yml
  • .github/workflows/dependabot-rebase.yml
  • standards/workflows/dependabot-rebase.yml
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/dependabot-rebase-github-token

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

… scope)

'workflows' is a GitHub App permission, not a GitHub Actions job permission
scope. actionlint correctly rejects it. GITHUB_TOKEN with contents:write in
a push-triggered workflow already handles .github/workflows/ file updates.
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

Updates the org’s reusable Dependabot rebase/merge workflow to avoid HTTP 403s when update-branch needs to merge workflow-file changes (by switching that API call to use GITHUB_TOKEN), while keeping approvals and merges attributed to the GitHub App identity.

Changes:

  • Elevates job permissions in the reusable workflow to enable update-branch when .github/workflows/* changes are involved.
  • Uses GITHUB_TOKEN for update-branch, and uses the app token only for re-approvals and merges (via GH_TOKEN="$APP_TOKEN").

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .github/workflows/dependabot-rebase-reusable.yml
… caller stubs

Reusable workflow permissions are capped by the calling job. Update both the
live caller (.github/workflows/dependabot-rebase.yml) and the standards
template (standards/workflows/dependabot-rebase.yml) to grant write
permissions so the reusable's GITHUB_TOKEN can call update-branch and
approve PRs.

Also update the pinned SHA to origin/main (35e0e20) which includes the
re-approval fix from PR #140.
@sonarqubecloud
Copy link
Copy Markdown

@don-petry don-petry merged commit f5c167c into main Apr 16, 2026
19 checks passed
@don-petry don-petry deleted the fix/dependabot-rebase-github-token branch April 16, 2026 18:01
don-petry pushed a commit that referenced this pull request Apr 16, 2026
The caller stubs referenced SHA 35e0e20 (PR #140), which predates the
GITHUB_TOKEN change from PR #141. Update to f5c167c (HEAD of main after
PR #141 merged) so the reusable workflow used has contents:write/
pull-requests:write job permissions and uses GITHUB_TOKEN for update-branch.
don-petry added a commit that referenced this pull request Apr 16, 2026
* fix(dependabot-rebase): update pinned SHA to include GITHUB_TOKEN fix

The caller stubs referenced SHA 35e0e20 (PR #140), which predates the
GITHUB_TOKEN change from PR #141. Update to f5c167c (HEAD of main after
PR #141 merged) so the reusable workflow used has contents:write/
pull-requests:write job permissions and uses GITHUB_TOKEN for update-branch.

* docs: clarify SHA bump is allowed in caller stub header comment

The previous header said 'MUST NOT change the uses: line', but bumping
the pinned SHA when upgrading the reusable workflow version is intentional
and necessary. Clarify what is forbidden vs what is allowed.

---------

Co-authored-by: DJ <dj@Rachels-Air.localdomain>
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