Bright Labs

Fine-grained token permissions to read GitHub Actions runs (and re-run them)

To read GitHub Actions runs on a private repository with a fine-grained personal access token, give the token the Actions repository permission with read access. On a public repository you don't need to add any permission to read runs, because every fine-grained token already includes read-only access to all public repositories. Re-running failed jobs is different: it needs write access to Actions.

Below: which Actions call needs which permission, how to set up the token for a private repo, and what to check when GitHub still refuses it.

Which permission each Actions call needs

When you create a fine-grained token, you grant it a set of permissions. GitHub's permissions reference lists the endpoints you need to read run history in the Actions section, at read level. The endpoint that re-runs failed jobs is in the same section, at write level.

Actions endpoints for reading and re-running runs, from GitHub's fine-grained permissions reference
What you wantEndpointActions permission
List workflow runs for a repositoryGET /repos/{owner}/{repo}/actions/runsRead
List the jobs in a runGET /repos/{owner}/{repo}/actions/runs/{run_id}/jobsRead
Get one attempt of a runGET /repos/{owner}/{repo}/actions/runs/{run_id}/attempts/{attempt_number}Read
Download a job's logGET /repos/{owner}/{repo}/actions/jobs/{job_id}/logsRead
Re-run failed jobsPOST /repos/{owner}/{repo}/actions/runs/{run_id}/rerun-failed-jobsWrite

The log endpoint is easy to get wrong. It gets you a redirect URL to download a plain text file of logs for the job. That link expires after 1 minute. Download the file right away instead of saving the URL for later.

Public repositories: reading works without extra permissions

GitHub's token docs say tokens always include read-only access to all public repositories on GitHub. The docs for the workflow runs endpoint say anyone with read access to the repository can use it. Put those two together and a fine-grained token with no extra permissions should be able to list runs on a public repository.

The permissions reference says the same thing the other way round. Its permissions are required to access private resources, and some endpoints can also be used to access public resources without them. If you only read public repos, don't add any permissions.

Private repositories: create the token

This is where you have to add the permission yourself. Here's the path:

Then test it against the list-runs endpoint for that repo. If you get runs back, the token is set up right.

Re-running failed jobs needs write, not read

The rerun-failed-jobs endpoint re-runs all of the failed jobs and their dependent jobs in a workflow run, using the run's id. The permissions reference lists it under Actions at write level. So Actions read covers listing, and re-running needs Actions write.

If you re-run only now and then, think about keeping two tokens: a read-only one for scripts that read history, and a write one you use on purpose. That way the token your scripts carry around has only the permissions they need.

When the token still gets refused

You added Actions read and it still fails. Check these, roughly in this order:

What classic tokens need instead

If you're on a classic token, the workflow runs docs say classic tokens need the repo scope to use the endpoint with a private repository. GitHub recommends fine-grained tokens instead of classic ones whenever possible. It also says fine-grained tokens don't support every feature of classic tokens yet, so check GitHub's token docs if a call doesn't work with a fine-grained token.

Keep the token small, and keep it to yourself

GitHub's advice for permissions is to choose the minimal permissions necessary for your needs, and to treat your access tokens like passwords. Read-only Actions on one repository is about as small as a useful token gets. Don't paste it into shared config or a chat.

If you want run history so you can tell a flaky check from a real failure on a pull request, we built FlakeRadar for that. It's a Chrome extension, with a free plan, that reads the repo's own GitHub Actions history using a fine-grained token you create, and labels each failing check. For public repositories you give the token Public repositories (read-only). For private repositories on Pro, you give it read-only Actions and Pull requests. Its one-click re-run is off until you turn it on, and only that needs Actions: Read and write. The token stays on your device and goes only to api.github.com. FlakeRadar is not affiliated with or endorsed by GitHub.

Sources

Questions

Is Actions read enough to download job logs?

Yes. GitHub's fine-grained permissions reference lists the job logs endpoint under Actions at read level. The endpoint gives you a redirect URL that expires after 1 minute, so download the file right away.

Why can my token list runs but not re-run them?

Listing runs is listed under Actions at read level, but the rerun-failed-jobs endpoint is listed under Actions at write level. Give the token write access to Actions, or use a separate token for re-runs.

Can a fine-grained token call the Checks API?

GitHub's token docs list calling the Checks API as one of the features fine-grained tokens don't support yet, and say GitHub is working to close those gaps. For run, job and log data, use the Actions endpoints.

My token for an organization repo says pending. Can it do anything?

If the organization requires approval for fine-grained tokens, the token stays pending until an organization administrator reviews it. Until it's approved, it can only read public resources.

Related