Pub from CI
Your CI reads and publishes your private packages with no stored secret. Each job proves which repository it is with its CI provider's own identity token and gets a Pub token that lasts 15 minutes.
How it works
- Bind the repository. In the Control Room, open Organization and find CI access. Bind a repository says which repository's CI runs act for your organization, and optionally only from one workflow, environment or branch. An Owner or an Admin binds.
- Grant it packages. Each binding is a CI member of your organization. Its Packages button grants it packages to read, or to read and publish, exactly as for a teammate. With no grant it reads the global packages and your organization's engine, if it has one, and publishes nothing. Removing the binding removes the member and everything it was granted.
- Exchange in the job. The job requests its identity token for the audience
https://fex.flutterrific.ioand sends it to the exchange with your organization id, which is on the same Organization screen. - Use the Pub token.
dart pub token addhands it todart pub getanddart pub publish(flutter pubworks the same way).
Your CI provider
| Provider | Before you bind |
|---|---|
| GitHub Actions | GitHub.com is trusted already. For GitHub Enterprise Server, an Owner adds its issuer, https://<your host>/_services/token, as this organization's own. |
| GitLab CI/CD | GitLab.com is trusted already. For a self-managed GitLab, an Owner adds its address, https://<your host>, as this organization's own issuer. |
| Bitbucket Pipelines | Each Bitbucket workspace has its own issuer, so an Owner adds it first: in CI access, under This organization's own CI issuers, choose Bitbucket Pipelines and enter the workspace's URL name. |
| CircleCI | Each CircleCI organization has its own issuer, so an Owner adds it first: in CI access, under This organization's own CI issuers, choose CircleCI and enter the organization ID. |
The exchange
The job sends its identity token as a bearer token and your organization id as the body:
shell
curl -sS --fail-with-body -X POST https://api.fex.flutterrific.io/v1/ci/exchange \
-H "Authorization: Bearer $CI_TOKEN" -H "Content-Type: application/json" \
-d '{"orgId":"<your organization id>"}'It answers with the Pub token and what it may do:
json
{
"token": "dtc_…", // the Pub token, valid for 15 minutes
"keyId": "…",
"organizationId": "<your organization id>",
"packages": ["my_package"], // what it may publish ([] when it only reads)
"packageAccess": { … }, // what it may read
"expiresAt": 1767225600 // seconds since 1970
}- Each identity token is exchanged once. Exchange once per job, at the start, and keep the Pub token for the job's later steps.
- The Pub token reads the global packages, your organization's engine if it has one, and every package the CI member is granted, and publishes the ones granted to publish. It cannot do anything else.
- Every exchange is in your organization's Audit Log, with the repository, the run and the commit.
When the exchange refuses
A refusal names its reason first, so the job's log shows it as is:
json
{"error": {"code": "permission-denied",
"message": "TRUSTED PUBLISHER REF MISMATCH: …",
"details": {"reason": "TRUSTED PUBLISHER REF MISMATCH"}}}| Reason | What to do |
|---|---|
CI EXCHANGE ORG MISSING | The request named no organization. Send {"orgId": "<your organization id>"} as the body. |
CI OIDC TOKEN MISSING | The request carried no CI token. Send it as Authorization: Bearer <token>. |
CI OIDC AUDIENCE INVALID | The token was requested for another audience. Request it for https://fex.flutterrific.io, as the snippet does. |
CI OIDC ISSUER NOT TRUSTED | The token's issuer is not trusted for this organization. For Bitbucket, CircleCI, GitHub Enterprise Server or a self-managed GitLab, an Owner adds the issuer first. |
CI OIDC EXPIRED | The token expired before it was exchanged. Exchange it as soon as the job requests it. |
CI OIDC TOKEN REPLAYED | This token was exchanged already. Each token is exchanged once: exchange once per job. |
TRUSTED PUBLISHER NOT BOUND | No binding of this organization names the job's repository. Bind it in CI access, and check the orgId in the workflow. |
TRUSTED PUBLISHER REPOSITORY MISMATCH | The binding names another repository or project. The UUIDs and ids must be the job's own. |
TRUSTED PUBLISHER WORKFLOW MISMATCH | The job ran from another workflow or pipeline file than the binding allows. |
TRUSTED PUBLISHER ENVIRONMENT MISMATCH | The job did not run in the binding's environment (or, on CircleCI, did not use its context). |
TRUSTED PUBLISHER REF MISMATCH | The job ran on a branch or tag the binding's ref pattern does not match. |
TRUSTED PUBLISHER REPOSITORY ID MISMATCH | The repository was deleted and created again under the same name. Remove the binding and bind the new repository. |
TRUSTED PUBLISHER AMBIGUOUS | More than one binding matches the job. Narrow them (workflow, environment or ref) so exactly one does. |
CI OIDC CLAIM MISSING | The token lacks a claim the provider always sends. Check that the token is the provider's own CI token, requested as the snippet does. |
CI OIDC SSH RERUN | A CircleCI job rerun with SSH. Run it again without SSH. |
CI EXCHANGE RATE LIMITED | Too many exchanges for this repository or organization in a short time. Exchange once per job, then wait and retry. |
BOX STATE PUSH FAILED | The registry did not receive the new token. Retry the job. |