Authenticate Depot CI with OIDC
A Depot CI job can trade the OIDC token Depot issues for each job for a short-lived PostHog token. You don't store a personal API key as a secret, and the token only works on one project. The overview covers trust policies, requests, and the token exchange for every provider.
What the job needs
- A job that runs in Depot CI
- The
id-token: writepermission, so Depot issues an OIDC token to the job - A trusted workload in your PostHog project that matches your Depot organization, the repository, and the runs you pick
- Your PostHog project ID and host, in
posthog.jsonor in the job's environment
PostHog trusts Depot's issuer, https://identity.depot.dev.
How the job gets a token
hog knows it runs in Depot CI when the job has a DEPOT_JOB_URL variable. Depot runners for GitHub Actions don't set it, so their jobs use GitHub's tokens, as described on the GitHub Actions page.
Depot sets the same token request variables in the job that GitHub Actions does, ACTIONS_ID_TOKEN_REQUEST_URL and ACTIONS_ID_TOKEN_REQUEST_TOKEN. hog uses them to ask for a token whose audience is your PostHog host, then exchanges it at /oauth/token/.
Depot's OIDC tokens live 5 minutes, and the PostHog token never outlives the token it came from. hog keeps the PostHog token in memory and exchanges a new Depot token when it's close to expiring, or after a 401, so a long job keeps working.
See Depot's OIDC docs for how Depot issues these tokens and what each claim holds.
Which runs a policy matches
A policy identifies the repository with two claims, and both must match:
repository_id- the repository's ID, assigned by the forge that hosts it. For a GitHub repository, this is the GitHub repository ID.repository- the repository's full name, such asacme/web. If you rename the repository, update the policy.
Every Depot policy must also set two conditions:
org_id- your Depot organization ID, so no other Depot organization's job matchesforge- the forge that hosts the repository,githubby default. Two forges can give the same ID to different repositories.
These two pin your account, not the runs, so they don't count as the condition every policy needs. repository_owner_id also pins your account, so it doesn't count either. A policy also sets at least one of ref, event_name, or workflow_ref.
| Claim | What it holds | Example value |
|---|---|---|
org_id | Your Depot organization ID | abcd1234efgh |
forge | The forge that hosts the repository | github |
ref | The Git ref the run is for | refs/heads/main |
event_name | The event that started the workflow | push |
workflow_ref | The workflow file and the ref it ran from | acme/web/ci.yaml@refs/heads/main |
repository_owner_id | The forge's ID for the account that owns the repository. It survives renames. Optional. | 123456 |
A policy that sets ref or workflow_ref must also set event_name. Pull request runs, and runs started with depot ci run, carry a branch's ref and workflow too, so without an event the policy could trust code nobody pushed.
Which runs carry which claims:
- A run for a push to
maincarriesevent_name=pushandref=refs/heads/main. - A pull request from a branch in the same repository carries
event_name=pull_requestandref=refs/pull/<number>/merge. - Pull requests from forks get no token.
- A run you start with
depot ci run, for example from your machine, carriesevent_name=api, so it never matches a policy that requirespush.
Depot tokens don't carry environment or protected-branch claims, so a Depot policy can't pin those.
Presets in PostHog settings
Under Which runs can get a token, the settings page offers these presets. A new policy starts with both.
| Preset | Conditions it sets | When to use it |
|---|---|---|
| Your Depot organization | org_id = <organization ID> and forge = github | Every Depot policy for a GitHub repository |
Pushes to a branch (branch main) | ref = refs/heads/<branch> and event_name = push | Jobs that run after code lands on a branch, such as deploys from main. Runs started with depot ci run don't match. |
To use another claim from the table above, pick it under One claim of the token and enter its exact value. For a repository on another forge, set org_id and forge that way instead of the organization preset.
Why the defaults are safe
- Pinning
org_idandforgemeans only jobs your Depot organization runs, for the repository on that forge, can match. - Pushes to a branch pins both the branch and the event. Requiring
event_name=pushmeans runs that other events start, such as pull requests, don't match. Only code pushed to the branch gets a token.
Set up a trusted workload
Only organization admins and owners can add a trusted workload. Anyone else in the project can ask an admin for one.
In PostHog settings
- In your project settings, go to Trusted workloads and click Add trusted workload.
- Under Provider, pick Depot CI.
- In Repository, enter
owner/repoand click Look up. PostHog fills in the Repository ID. - Under Which runs can get a token, enter your Depot organization ID in Your Depot organization. Copy it exactly as Depot shows it in your organization settings.
- Keep Pushes to a branch and change the branch if it isn't
main, or pick another claim. - Give the trusted workload a Name, and pick the Scopes the job needs.
- Click Add trusted workload, then copy the
posthog.jsonkeys and the job snippet PostHog shows.
Look up works only when the forge is github. PostHog looks the repository up on GitHub, through your project's GitHub integration first and then for public repositories, like it does for GitHub Actions. For a repository on another forge, or one PostHog can't find, enter the Repository ID yourself. For a GitHub repository, you can get it with the GitHub CLI: gh api repos/<owner>/<repo> --jq .id.
With hog ci setup
Logged in with hog auth login, run this in your repository:
hog finds .depot/workflows, reads owner/repo from your origin remote, asks PostHog to look up the repository ID, and applies both presets. Depot CI offers two presets:
--preset organization=<organization ID>- Your Depot organization, required. It also setsforgetogithub.--preset branch_push=<branch>- Pushes to a branch
hog always adds the required preset. Without a value for it, or without a preset that says which runs may get a token, hog asks.
- If PostHog can't look up the repository, pass
--subject-idwith its ID and--repositorywith its exact name. hog ci setupsets up GitHub repositories only. For a repository on another forge, add the trusted workload in PostHog settings.- When the repository also has
.github/workflows, hog can't tell which provider you mean, so pass--provider depot_ci. - List the scopes the job needs in
--scope, separated by commas, such as--scope error_tracking:write,query:read. - hog names the policy
<repository> on Depot CI.
hog then creates a policy request. If you're an admin at a terminal, it opens the approval page and waits. Otherwise it prints the link to send to an admin. hog ci setup --wait waits for up to 10 minutes and keeps the request, so you can run it again later. The overview lists every flag. Before you approve a request, check its Depot organization ID.
Configure the job
A job needs your PostHog project ID and host, and a way to get its token. The settings page, and hog ci setup, print all of this with your values filled in.
1. Add the project to posthog.json (preferred)
Add these keys to posthog.json in the repository. hog looks for the file from the current folder up to the git root.
projectIdis your project's ID: the number in your project URL, such as12345inhttps://us.posthog.com/project/12345.hostcounts in a CI job only when it's PostHog Cloud,https://us.posthog.comorhttps://eu.posthog.com, so a change to the file can't send the job's token elsewhere. Without a host, hog useshttps://us.posthog.com.- Never put
HOG_PERSONAL_API_KEYinposthog.json.
2. Give the job an OIDC token
Add these keys to the job in your Depot CI workflow that runs hog. id-token: write lets the job ask Depot for an OIDC token. Setting permissions turns off every permission you don't list, so contents: read keeps checkout working.
3. Run hog in the job
Run hog commands in the job as usual. hog sees that it runs in Depot CI and exchanges the OIDC token for you. This example uploads source maps for error tracking, so the trusted workload needs the error_tracking:write scope:
PostHog/setup-hog installs the newest hog 1.x and puts it on PATH. To keep a new hog release from changing your build, pin version and sha256, as its README shows.
Or set environment variables
Instead of posthog.json, set HOG_HOST and HOG_PROJECT_ID in the job's env. They win when both are set.
A self-hosted PostHog always needs HOG_HOST in the job. When posthog.json names a host that isn't PostHog Cloud and the job doesn't set HOG_HOST, hog stops with a workload_host_not_allowed error that names the host to set.
Remove HOG_PERSONAL_API_KEY from the job. hog uses a personal API key ahead of the workload token. hog's usage analytics from this job carry a hashed workload ID, not a person.
Troubleshooting
| Problem | Likely cause | What to do |
|---|---|---|
| hog can't get an OIDC token | The job doesn't have id-token: write | Add the permission to the job. |
workload_audience_mismatch | The token's aud isn't the PostHog site URL hog sends it to | Set the host in posthog.json, or HOG_HOST, to the address you open PostHog at. |
workload_token_invalid | The token expired, its signature doesn't verify, or it lacks a claim PostHog needs | Run the job again. hog asks the provider for a fresh token on each exchange. |
workload_no_matching_policy | The run doesn't match the policy, for example a pull request, a run started with depot ci run, or another branch. A different Depot organization or forge, a renamed repository, or the wrong project ID, also cause it. | The error lists the claims the job sent. Compare them with the policy, or run hog ci setup to ask for a policy that matches. |
workload_policy_request_pending | An admin hasn't approved the request yet | Send the approval link from the error to an admin. |
workload_no_usable_scopes | The policy only grants scopes a workload can't use | Ask an admin to add scopes the job can use. |
workload_rate_limited | The policy used up its exchanges, or too many exchange attempts came from the runner's IP address | hog retries while the total wait stays within 60 seconds. Otherwise, run the job again later. |
workload_host_not_allowed from hog | posthog.json names a host that isn't PostHog Cloud, and the job doesn't set HOG_HOST | Set HOG_HOST in the job to the host the error names. |
A call fails with 403 | The policy doesn't grant the scope the call needs | The WWW-Authenticate header names the scope. Ask an admin to add it. |
See errors in the overview for every error code.





