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.shGotchas
- 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
How to Push to GHCR With the Built-In Token in GitHub ActionsPush container images to GitHub Container Registry from Actions using the built-in GITHUB_TOKEN and packages:…
How to Reuse a Workflow With workflow_call in GitHub ActionsBuild a reusable GitHub Actions workflow with on.workflow_call, declaring inputs and secrets, then call it fr…
How to Push a Multi-Arch Image to ECR in GitHub ActionsBuild and push a multi-arch (amd64 + arm64) Docker image to Amazon ECR in GitHub Actions using OIDC to authen…