Skip to content

Add workflow to auto-approve bot workflow runs#7345

Open
philipbalinov wants to merge 5 commits intomainfrom
philip/auto-approve-bot-runs
Open

Add workflow to auto-approve bot workflow runs#7345
philipbalinov wants to merge 5 commits intomainfrom
philip/auto-approve-bot-runs

Conversation

@philipbalinov
Copy link
Copy Markdown
Contributor

Summary

  • GitHub now requires maintainer approval for workflows triggered by bot-authored events (changelog)
  • This adds a companion workflow that auto-approves action_required runs from github-actions[bot] and dependabot[bot]
  • Uses workflow_run trigger which runs in the default branch context, so it is not itself subject to the approval gate

Test plan

  • Merge this PR
  • Wait for the next bot-authored PR (e.g. providers update or Dependabot bump)
  • Verify the CodeQL / other workflows no longer sit in action_required state

🤖 Generated with Claude Code

GitHub now requires maintainer approval for workflows triggered by
bot-authored events (github-actions[bot], dependabot[bot]). This
companion workflow listens for workflow_run requests in action_required
state and auto-approves them for trusted bot actors.

Ref: https://github.blog/changelog/2025-04-15-upcoming-breaking-changes-and-releases-for-github-actions/

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@mondoo-code-review mondoo-code-review Bot left a comment

Choose a reason for hiding this comment

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

Workflow logic looks correct but the echo statement has a script injection vulnerability via the actor login field.

Comment thread .github/workflows/auto-approve-bot-runs.yml Outdated
Avoid script injection by passing workflow_run event fields through
env: rather than interpolating ${{ }} directly in the shell script.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@mondoo-code-review mondoo-code-review Bot left a comment

Choose a reason for hiding this comment

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

Workflow auto-approves bot runs but the actor allowlist includes github-actions[bot], which could be exploited to bypass approval gates.

Comment thread .github/workflows/auto-approve-bot-runs.yml Outdated
Comment thread .github/workflows/auto-approve-bot-runs.yml
Address review feedback:
- Scope workflow_run trigger to "CodeQL Advanced" only
- Restrict to version/ branches to narrow the approval surface
- Poll run status instead of checking conclusion in the if-condition,
  since conclusion is unset at the requested event stage

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@mondoo-code-review mondoo-code-review Bot dismissed their stale review April 23, 2026 14:49

Superseded by new review

Copy link
Copy Markdown

@mondoo-code-review mondoo-code-review Bot left a comment

Choose a reason for hiding this comment

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

Well-scoped workflow for auto-approving bot runs with reasonable guards, but the GITHUB_TOKEN may lack permission to approve runs.

Comment thread .github/workflows/auto-approve-bot-runs.yml
Comment thread .github/workflows/auto-approve-bot-runs.yml Outdated
Comment thread .github/workflows/auto-approve-bot-runs.yml
GitHub's approval gate checks the commit author, not the workflow run
actor.  When a bot-authored PR is merged by a human the run's actor is
the human, but head_commit.author.name is still the bot.

- Check head_commit.author.name instead of actor.login
- Remove workflow scope restriction (all CI workflows need approval)
- Remove version/ branch restriction (post-merge runs land on main)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

@mondoo-code-review mondoo-code-review Bot left a comment

Choose a reason for hiding this comment

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

Auto-approve workflow for bot runs has a security concern with insufficient actor validation and a minor robustness issue.

Comment thread .github/workflows/auto-approve-bot-runs.yml
Comment thread .github/workflows/auto-approve-bot-runs.yml
Comment thread .github/workflows/auto-approve-bot-runs.yml Outdated
Add head_repository check to prevent fork PRs with crafted
author.name from bypassing the approval gate. Also bump retry
count to 5 and emit ::warning:: on timeout for Actions UI visibility.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@philipbalinov
Copy link
Copy Markdown
Contributor Author

/review

Copy link
Copy Markdown

@mondoo-code-review mondoo-code-review Bot left a comment

Choose a reason for hiding this comment

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

Well-structured workflow with good security guards, but the GITHUB_TOKEN likely lacks permission to approve workflow runs.

Comment thread .github/workflows/auto-approve-bot-runs.yml
Comment thread .github/workflows/auto-approve-bot-runs.yml
Comment thread .github/workflows/auto-approve-bot-runs.yml
Copy link
Copy Markdown

@mondoo-code-review mondoo-code-review Bot left a comment

Choose a reason for hiding this comment

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

Well-structured workflow with good security guards, but uses GITHUB_TOKEN which lacks permission to approve workflow runs.

Comment thread .github/workflows/auto-approve-bot-runs.yml
Comment thread .github/workflows/auto-approve-bot-runs.yml
Comment thread .github/workflows/auto-approve-bot-runs.yml
Copy link
Copy Markdown

@mondoo-code-review mondoo-code-review Bot left a comment

Choose a reason for hiding this comment

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

Well-structured workflow with good security guards, but the GITHUB_TOKEN likely lacks permission to approve workflow runs.

Comment thread .github/workflows/auto-approve-bot-runs.yml
Comment thread .github/workflows/auto-approve-bot-runs.yml
Comment thread .github/workflows/auto-approve-bot-runs.yml
@philipbalinov philipbalinov dismissed stale reviews from mondoo-code-review[bot] and mondoo-code-review[bot] April 24, 2026 13:00

Repeat false positives — all concerns previously addressed in prior review rounds. The workflow correctly validates source repository, uses allowlist checking, handles environment variables safely, and executes in default-branch context with proper permissions.

Copy link
Copy Markdown

@mondoo-code-review mondoo-code-review Bot left a comment

Choose a reason for hiding this comment

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

Well-structured workflow with good security checks; one potential concern around token permissions.


permissions:
actions: write

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 warningGITHUB_TOKEN (i.e. github.token) may not have sufficient privileges to approve workflow runs that require environment/deployment approvals. If this doesn't work as expected, you may need a GitHub App token or PAT with appropriate permissions. Worth verifying in a test run.

if: >-
github.event.workflow_run.head_repository.full_name == github.repository &&
contains(fromJSON('["github-actions[bot]","dependabot[bot]"]'),
github.event.workflow_run.head_commit.author.name)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 suggestion — The allowlist of bot names is hardcoded in the workflow condition. Consider extracting it to a repository variable (e.g. vars.APPROVED_BOT_AUTHORS) so adding a new bot doesn't require modifying the workflow file and going through review.

# workflow_run runs in the default-branch context, so it is not itself
# subject to the approval gate.
workflow_run:
types: [requested]
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 suggestion — The workflow_run trigger with only types: [requested] and no workflows: filter means this fires for every workflow run in the repo. This is likely fine (the if guard filters appropriately), but adding an explicit workflows: list would reduce unnecessary job spin-ups and make intent clearer.

Copy link
Copy Markdown

@mondoo-code-review mondoo-code-review Bot left a comment

Choose a reason for hiding this comment

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

Well-structured workflow with good security guards, but the GITHUB_TOKEN likely lacks permission to approve workflow runs.

- name: Approve workflow run if pending
env:
GH_TOKEN: ${{ github.token }}
RUN_ID: ${{ github.event.workflow_run.id }}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔴 critical — The default GITHUB_TOKEN (i.e. github.token) cannot approve workflow runs that require approval — GitHub requires a PAT or a GitHub App token with actions:write scope for gh run approve. This workflow will fail with a 403 at the approve step.

Use a GitHub App token or a PAT stored as a repository secret instead:

GH_TOKEN: ${{ secrets.BOT_APPROVE_TOKEN }}

if: >-
github.event.workflow_run.head_repository.full_name == github.repository &&
contains(fromJSON('["github-actions[bot]","dependabot[bot]"]'),
github.event.workflow_run.head_commit.author.name)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 warning — The allowlist only covers github-actions[bot] and dependabot[bot]. If another trusted bot (e.g. renovate[bot]) is added later, it must be updated here too. Consider documenting this near the list, or extracting it into a repository variable for easier maintenance.

# workflow_run runs in the default-branch context, so it is not itself
# subject to the approval gate.
workflow_run:
types: [requested]
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 suggestion — The workflow_run trigger with no workflows filter will fire for every workflow in the repo, including itself (though the if guard will skip it). Adding an explicit workflows filter narrows the trigger scope and avoids unnecessary job evaluations:

on:
  workflow_run:
    workflows: ["CI", "Release"]  # list the workflows that bots trigger
    types: [requested]

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.

1 participant