Skip to content
Latchkey

How to Restrict Who Can Trigger workflow_dispatch in GitHub Actions

Anyone with write access can trigger a manual workflow; for sensitive ones you may want an even tighter check.

Add a guard step that queries the actor permission level and fails the run unless they are an admin or maintainer.

Steps

  • Keep the workflow on workflow_dispatch.
  • Add a first job that checks the actor permission via the GitHub API.
  • Fail the run if the level is below admin (or your threshold).
  • Gate the real jobs behind that check with needs:.

Workflow

.github/workflows/manual-deploy.yml
on: workflow_dispatch
jobs:
  authorize:
    runs-on: ubuntu-latest
    steps:
      - name: Check permission
        env:
          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        run: |
          LEVEL=$(gh api "repos/${{ github.repository }}/collaborators/${{ github.actor }}/permission" --jq .permission)
          if [ "$LEVEL" != "admin" ]; then
            echo "::error::${{ github.actor }} is not an admin ($LEVEL)"
            exit 1
          fi
  deploy:
    needs: authorize
    runs-on: ubuntu-latest
    steps:
      - run: ./deploy.sh

Gotchas

  • For broad org policy, a protected environment with required reviewers is sturdier than an inline check.
  • The default token can read collaborator permission without extra scopes.
  • Latchkey runs the gated jobs on cheaper, self-healing runners once the authorization check passes.

Frequently asked questions

How do I restrict Who Can Trigger workflow_dispatch in GitHub Actions?
Add a guard step that queries the actor permission level and fails the run unless they are an admin or maintainer.

Related guides

References

Run this faster and cheaper on Latchkey managed runners - self-healing included. Start free → 30-day trial · No credit card