OIDC Permissions for GitHub Actions
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 grants the OIDC CI token of the jobs it
matches CI Reporting by default. A GitHub organization
Owner can make it grant any application key
permission instead, or as well, on the job’s own
repository.
When to use it
Section titled When to use itUse 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
Section titled Granting permissionsWrite 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, pick what a policy grants under Permissions
in its editor. In the API, 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.
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:
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
Section titled 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 tab shows what the token of each allowed exchange got, under Granted, and the API returns it under
permissions.
See also
Section titled See alsoWas this page helpful?
Thanks for your feedback!