---
title: OIDC Permissions for GitHub Actions
description: Let a trust policy grant the GitHub Actions jobs it matches more than CI Reporting, such as pausing the merge queue during a deploy, with no key stored in their secrets.
---

A [trust policy](/integrations/gha/oidc#trust-policies) grants the OIDC CI token of the jobs it
matches [CI Reporting](/api/application-keys#ci-reporting) by default. A GitHub organization
`Owner` can make it grant any [application key
permission](/api/application-keys#application-key-permissions) instead, or as well, on the job's own
repository.

## When to use it

Use it when a GitHub Actions job calls the Mergify API for more than its test results and scopes,
and keeps an application key in its secrets to do so: a deploy workflow that pauses the merge
queue, for instance.

## Granting permissions

Write a policy for the jobs that need more, matching as few of them as you can, rather than
widening the one your CI runs under. A job that several policies match gets what each of them
grants, so your test jobs keep CI Reporting from their own policy.

Only a GitHub organization `Owner`, signed in as themselves, creates, changes or deletes a policy
that grants more than CI Reporting.

On the [dashboard](https://dashboard.mergify.com), pick what a policy grants under **Permissions**
in its editor. In [the API](/api/ci-identity), a policy's `permissions` maps each resource it grants
to its level, such as `{"merge_queue_pause": "write"}`, and replaces CI Reporting: list
`"ci_reporting": "write"` too for jobs that upload test results.

:::caution
  Anyone who can push a branch to the policy's repositories can add a workflow it matches, and get
  its permissions. Limit the policy to an
  [environment](https://docs.github.com/en/actions/deployment/targeting-different-environments/using-environments-for-deployment)
  whose protection rules GitHub checks before the job starts. A reusable workflow pinned to a
  protected ref holds them back too, if it runs no code from the branch that calls it.
:::

The test framework plugins and the `mergify ci` commands exchange the job's ID token for their own
requests only. A step that calls the API for anything else exchanges it itself. This job runs in
the `production` environment, which its policy names, and pauses the merge queue while it deploys:

```yaml
jobs:
  deploy:
    runs-on: ubuntu-latest
    environment: production
    permissions:
      id-token: write
      contents: read
    steps:
      - name: Exchange the job's ID token for a Mergify token
        run: |
          id_token=$(curl -sSf -H "Authorization: Bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" \
            "$ACTIONS_ID_TOKEN_REQUEST_URL&audience=https://api.mergify.com" | jq -er .value)
          token=$(curl -sSf https://api.mergify.com/v1/ci/oidc/exchange \
            -H "Content-Type: application/json" \
            -d "{\"id_token\": \"$id_token\"}" | jq -er .token)
          echo "::add-mask::$token"
          echo "MERGIFY_JOB_TOKEN=$token" >> "$GITHUB_ENV"
      - name: Pause the merge queue
        run: |
          curl -sS --fail-with-body -X PUT \
            "https://api.mergify.com/v1/repos/$GITHUB_REPOSITORY/merge-queue/pause" \
            -H "Authorization: Bearer $MERGIFY_JOB_TOKEN" \
            -H "Content-Type: application/json" \
            -d '{"reason": "Deploying"}'
      # Your deploy steps: the token expires after one hour
      - name: Resume the merge queue
        if: always()
        run: |
          curl -sS --fail-with-body -X DELETE \
            "https://api.mergify.com/v1/repos/$GITHUB_REPOSITORY/merge-queue/pause" \
            -H "Authorization: Bearer $MERGIFY_JOB_TOKEN"
```

## How it behaves

- The token reaches only the operations whose path names the job's repository. An operation that
  names no repository refuses it, whatever the policy grants: use an application key for those.

- The [**Exchanges**](/integrations/gha/oidc#check-the-exchanges) tab shows what the token of each
  allowed exchange got, under **Granted**, and the API returns it under `permissions`.

## See also

- [OIDC Authentication for GitHub Actions](/integrations/gha/oidc)
- [Application key permissions](/api/application-keys#application-key-permissions)
- [Pausing the Merge Queue](/merge-queue/pause)
