useGrant

Trust GitHub Actions

Add GitHub Actions to a tenant as a trusted identity provider.

Add GitHub Actions as an identity provider

  1. Create a new tenant or open an existing one.
  2. Click Add identity provider.
  3. Enter https://token.actions.githubusercontent.com as the provider URL.
  4. Click Fetch fingerprint to fetch the provider's certificate fingerprint.
  5. Enter the audience your workflows use when requesting tokens.
  6. Click Add identity provider.

Add a policy

Policies decide which workflows are allowed. Open the identity provider and add a policy:

  1. Enter a name, a description and the expected audience.
  2. Add a condition on the sub claim, for example stringEquals with repo:octo-org/octo-repo:ref:refs/heads/main. Replace the values with your own repository details.
  3. Save the policy.

Use the stringLike operator with * as a wildcard to allow any branch, pull request or environment of a repository, for example repo:octo-org/octo-repo:*.

Note

By default, the audience is the URL of the repository owner, such as the organization that owns the repository. You can set a custom audience with the toolkit's core.getIDToken(audience) function.

See GitHub's guide to security hardening with OpenID Connect for how the claims are generated.

Generate an ID token in GitHub Actions

Your workflow needs the id-token: write permission to request an ID token from GitHub's OIDC provider. You can then generate a token with the actions/toolkit package:

name: Generate ID token

permissions:
  id-token: write

jobs:
  generate-id-token:
    runs-on: ubuntu-latest
    steps:
      - name: Generate ID token
        uses: actions/github-script@v7
        with:
          result-encoding: string
          script: |
            // core is available globally
            const idToken = await core.getIDToken();
            console.log(idToken);

To request a token with a custom audience, pass the audience to core.getIDToken:

import * as core from "@actions/core";

const idToken = await core.getIDToken("https://api.example.com");
console.log(idToken);

See the core package for more details.

Validate the token

Send the token to your server, then validate it against the tenant policy:

import UseGrant from "@usegrant/sdk";

const usegrant = new UseGrant(process.env.USEGRANT_API_KEY);

const { exp } = await usegrant.validateToken("tenantId", "policyId", idToken);

On this page