Skip to main content
PMG and vet in GitHub Actions can call SafeDep Cloud with a short-lived credential instead of an API key. The job exchanges its GitHub OIDC ID token for the credential, so GitHub stores no SafeDep secret. The tools call this OIDC mode. For how the exchange works and what the credential can do, see Workload identity.
This guide needs the SafeDep Cloud Team or Enterprise plan. See pricing.

Prerequisites

  • An owner of your GitHub organization, for step 1.
  • A SafeDep Cloud Owner or Admin of your tenant, for steps 2 and 3.
  • Your tenant domain, such as your-team.your-org.safedep.io. The tenant-id input of the action takes this value. safedep auth status shows it in the tenant field. The Tenant ID button on the API keys settings page also shows it.
  • The safedep CLI v0.12.0 or later, signed in with safedep auth login.
  • For PMG: the safedep/pmg action v0.37.0 or later, which installs PMG v0.37.0 or later. safedep/pmg@v2 with the default version: latest meets this.
  • For vet: the vet v2 GitHub Action. safedep/vet-action@v1 has no OIDC mode and needs an API key.

Set up the tenant

1

Link the SafeDep GitHub App

An owner of the GitHub organization installs the SafeDep GitHub App, and links the installation to your tenant when SafeDep Cloud asks.If the app is already installed:
  1. An owner of the GitHub organization accepts the new permission Members: read of the SafeDep GitHub App in the organization settings on GitHub.
  2. An owner of the GitHub organization links the installation to your tenant again, as at install time.
SafeDep Cloud checks with GitHub that the person is an owner of the organization. A link by a user who is not an owner still runs the pull request scans and the project sync. It creates no provider, so jobs get no credential. For a personal account, the account itself links the installation.
2

Check the provider

A provider is the record in your tenant that accepts the GitHub OIDC tokens of one GitHub account. The link of an owner creates it. List the providers:
LINK must be active. If your account has no row, see Troubleshoot.
3

Create the org-wide rule

Replace acme with the account in the PROVIDER column:
--grant tool lets a job make only the calls that PMG and vet use. For the list, see What the credential can do.
A rule with no --repository covers every repository of the GitHub account. This includes the repositories that the app installation does not select. The command prints the same warning.
The rule covers only the default events. When a repository has no project, its first run that publishes scan results creates the project. This works only when the app installation selects the repository.

Change the workflow

Give the job id-token: write, set tenant-id, and remove api-key. Store the tenant domain as a GitHub Actions variable, because it is not a secret. These examples use a variable with the name SAFEDEP_CLOUD_TENANT_DOMAIN.
The action gets the credential before it starts the proxy. Its post step revokes the credential. See What happens at the end of the job. In OIDC mode, the action ignores the endpoint-id input and prints a warning. For the result of each failure case, see Use GitHub OIDC instead of an API key in the PMG action documentation.

Check the credential

  1. Run the workflow.
  2. List the exchanges of the last day:
Each tool that got a credential shows one row with the outcome issued. After the job ends, the DETAIL column of a revoked credential says revoked. If the list is empty, no exchange reached your provider. Read the log of the PMG or vet step, and see Troubleshoot.

Move from an API key

While the job sets api-key, the PMG action and the vet action use the API key. So you can move one workflow at a time.
In OIDC mode, the endpoint of a job is gh:<owner>/<repo>. The PMG action uses the same default with an API key, so that endpoint and its history stay the same. A job that used another endpoint ID reports under a new endpoint. This applies to a job with an endpoint-id input, and to a job on an older action that used gha/<owner>/<repo>. The history stays on the old endpoint. Labels on the old endpoint do not move.
1

Add the permission

Add id-token: write to the permissions of the job.
2

Remove the API key input

Remove the api-key input. Keep tenant-id.
3

Run the workflow

Run the workflow, and check the credential.
4

Change the other workflows

Do steps 1 to 3 for each other workflow that uses the API key.
5

Delete the secret

When no workflow uses the API key, delete its secret from GitHub.
6

Delete the API key

Delete the API key on the API keys settings page.

Narrow the rule

For each flag, see the safedep workload command reference. A job gets a credential when any rule matches it. A narrower rule does not limit the org-wide rule. To give credentials to some repositories only, delete the org-wide rule. Then create rules that name the repositories:
  • --repository names a repository of the account. The server stores its numeric ID, so a rename does not change the rule. Repeat the flag for more repositories.
  • --ref takes a full ref, such as refs/heads/main, or a prefix that ends with /*, such as refs/heads/release/*.
  • --event lists the events that the rule covers. See Events that a rule covers.
  • --max-lifetime sets the longest life of a credential, from 1m to 6h. The default is 6h. PMG cannot refresh its credential, so give a PMG job a maximum life that is longer than the job.
  • --project-binding manual stops a run from creating a project for a repository. A member adds the repository as a project first. The default is auto for a rule with no --repository, and manual for a rule with --repository.
Each of --repository, --ref and --event adds one condition to the rule. When more than one rule matches a job, SafeDep Cloud uses the rule with the most conditions. Its --max-lifetime and --project-binding apply. When two such rules have the same number of conditions, the older rule applies. The CLI has no condition on the runner. For self-hosted runners, see Self-hosted runners.

Events that a rule covers

A rule with no --event covers only these default events: push, pull_request, merge_group, schedule, workflow_dispatch and release. An outsider can start most other events, so a rule must list them. For the reason, see Which events a rule covers. To allow an event such as pull_request_target, create a rule that lists it, and name the repositories that need it:
A rule with --event covers only the events that it lists. A run of an event outside the defaults can fetch the policy, check in and send events. It publishes no scan results to a project.

Troubleshoot

When SafeDep Cloud refuses the exchange, the PMG step fails. The error and the job summary name the tenant and the reason that SafeDep Cloud gives. vet scans with no SafeDep Cloud data and writes the reason in the workload_exchange_failed diagnostic. To see the refused exchanges of your tenant, run safedep workload exchange list --denied --since 1d. The rows are in the order that a PMG job meets them. The last row is for the admin who creates rules.

Workload Identity

See how the exchange works and what a compromised step can do.

PMG in GitHub Actions

Block malicious packages in GitHub Actions.

Authentication

See the other ways that tools sign in to SafeDep Cloud.

Review CI Blocks

See the packages that PMG blocked across your pipelines.