Skip to content
PolyPack
Docs: Trusted publishing

Trusted publishing

Publish from GitHub Actions with no PolyPack Token stored in GitHub.

With trusted publishing, a GitHub Actions workflow publishes your npm packages and pushes your images without a PolyPack Token stored anywhere. Instead of a long-lived secret, the workflow proves who it is with a short-lived ID token that GitHub signs, and PolyPack exchanges it for a Token that can publish one Pack and lasts 15 minutes.

Set it up

  1. Publish the first version the usual way, with a Token that can publish. A trusted publisher belongs to a Pack that exists.
  2. Add a trusted publisher. An Admin opens the Pack's page in PolyPack and, under Trusted publishers, names the GitHub repository (hopper-digital/ui), the workflow file in .github/workflows (release.yml) and, optionally, a GitHub environment.
  3. Let the workflow ask for an ID token with permissions: id-token: write, and publish as below. The Pack's Publish tab shows the workflow filled in for that Pack.

npm

Use PolyPack's GitHub Action: it exchanges GitHub's ID token for a Token that can publish only your Pack, sets npm up with it, and fails the job with PolyPack's reason if the exchange is refused. Then a plain npm publish works. Its inputs and versions are on its own page.

GitHub Actions: npm publish · .github/workflows/release.yml in hopper-digital/ui; no secret needed
on:
  release:
    types: [published]
jobs:
  publish:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      id-token: write
    steps:
      - uses: actions/checkout@v7
      - uses: actions/setup-node@v7
        with:
          node-version: 24
      - uses: cool-studio/polypack-actions@v1
        with:
          team: hopper
          pack: '@hopper/ui'
      - run: npm ci
      - run: npm publish

Without the action, npm 11.5.1 and later (Node 24) exchange the ID token themselves, but only with their default registry: run npm publish --registry https://hopper.pkg.polypack.io/npm/ (or set publishConfig.registry), or npm silently publishes without it and fails.

Docker and OCI

The same action logs docker, and helm if the runner has it, in to your Team's image host with a Token that can push only that image:

GitHub Actions: push an image · .github/workflows/release.yml; the job needs id-token: write
permissions:
  contents: read
  id-token: write
steps:
  - uses: actions/checkout@v7
  - uses: cool-studio/polypack-actions@v1
    with:
      team: hopper
      pack: api
  - run: |
      docker build -t hopper.cr.polypack.io/api:${{ github.ref_name }} .
      docker push hopper.cr.polypack.io/api:${{ github.ref_name }}

The action runs the polypack CLI's polypack ci, which any CI that can give it an ID token can run too.

What happens

  1. The workflow asks GitHub for an ID token addressed to your Team's registry. It says which repository, workflow file, commit, branch or tag, environment and run the job is, and is valid for a few minutes.
  2. It sends the ID token to PolyPack. PolyPack checks that GitHub signed it, that it is addressed to this Team's registry and not another, that it has not expired, and that it has not been used before.
  3. PolyPack looks for a trusted publisher on that Pack with the same repository, workflow file and, if one is set, environment.
  4. It answers with a Publisher Token: it publishes only that Pack, never creates a new one, and expires after 15 minutes. The workflow publishes with it like any Token.

Why it is safe

  • No long-lived secret. Nothing sits in GitHub's secret store to leak or to rotate, and each Token works on one Pack for minutes.
  • Tied to the repository, not its name. On its first publish, PolyPack records GitHub's numbers for the repository and its owner. A repository deleted and recreated under the same name, or an owner name someone else takes, is not trusted.
  • Approvals with environments. Name a GitHub environment that has required reviewers, and every publish waits for one.
  • Nothing to probe. A Pack that does not exist and a workflow that does not match get the same refusal.
  • A record of every publish. Each version shows the repository, commit and workflow run it came from, signed by PolyPack, so anyone who installs it can check it with polypack verify (see Signatures and provenance). The audit log records adding and removing trusted publishers and every exchange.
  • Private stays private. npm publishes provenance to a public log only for packages a registry says are public. PolyPack never does, so nothing about your private packages goes there.

Trusted publishers only

Once a workflow publishes a Pack, an Admin can lock the Pack to it: Trusted publishers only, on the Pack's page. From then on, its trusted publishers' workflows are the only way to publish or change it through the registry. A Member or Team Token that can publish is refused, with a message saying why, so a leaked Token cannot ship a release. Admins can still manage the Pack's versions in PolyPack, and can turn it off again.

If it does not work

  • npm says nothing when the exchange is refused: it carries on without a Token, and the publish fails with 401. Run npm publish --loglevel verbose to see PolyPack's reason.
  • "No trusted publisher of … matches this workflow": the repository, workflow file or environment differs from the trusted publisher's, the Pack name is wrong, or the repository was recreated.
  • "This is not a valid GitHub Actions ID token for this Registry": the workflow lacks id-token: write, the registry URL is another Team's, or the token expired or was used already.
  • Removing a trusted publisher stops its workflow at once, and revokes any of its Tokens still in use.

Limits

  • GitHub Actions only, for npm and Docker and OCI Packs. Composer Packs need none: their versions come from GitHub through Sync.
  • Up to 10 trusted publishers per Pack, on every Plan.