This repository uses GitHub's trusted publishing workflow to securely publish packages to npm without using long-lived access tokens.
Trusted publishing is a security feature that allows GitHub Actions to publish packages to npm using short-lived, automatically generated tokens via OpenID Connect (OIDC). This eliminates the need to store long-lived npm tokens as repository secrets, reducing the attack surface and improving supply chain security.
The .github/workflows/release-please.yml workflow is configured with the following settings for trusted publishing:
permissions:
contents: write # Required for release-please to create releases
pull-requests: write # Required for release-please to create PRs
id-token: write # Required for trusted publishing to npmThe id-token: write permission enables the workflow to request OIDC tokens from GitHub's OIDC provider.
- uses: actions/setup-node@v4
with:
node-version: "22.12.0"
registry-url: "https://registry.npmjs.org"
always-auth: true # Enable authentication for trusted publishingThe always-auth: true setting ensures that authentication is enabled when publishing packages.
- name: Publish to NPM
run: npm publish --provenance --access publicThe --provenance flag enables build provenance, which creates a publicly verifiable link between the package and its source code and build. The --access public flag ensures the package is published as public.
To enable trusted publishing for this package on npm, you need to:
-
Log in to npm and navigate to the package settings for
@databiosphere/findable-ui -
Add a GitHub Actions Publishing Workflow:
- Go to the package's publishing settings
- Click "Add GitHub Actions Publishing Workflow"
- Configure the trusted publisher with:
- Repository:
DataBiosphere/findable-ui - Workflow:
.github/workflows/release-please.yml - Environment: (leave blank, no environment is used)
- Repository:
-
Verify the Configuration:
- Ensure the trusted publisher is listed in the package settings
- The workflow will use OIDC to authenticate automatically when publishing
- No Long-Lived Tokens: Eliminates the need to store npm access tokens as GitHub secrets
- Automatic Rotation: Tokens are short-lived and automatically generated for each workflow run
- Build Provenance: The
--provenanceflag creates verifiable attestations linking the package to its source - Reduced Attack Surface: Compromised secrets cannot be used outside the workflow context
- Audit Trail: All publishes are tied to specific GitHub Actions workflow runs
The following configuration is no longer needed with trusted publishing:
- Repository Secret:
DATABIOSPHERE_FINDABLE_UI_NPM_PUBLISH_TOKEN- This secret can be safely removed from the repository settings as it is no longer used. Important: Only remove this secret after confirming the trusted publishing workflow works successfully in production to avoid disrupting the release process. - NODE_AUTH_TOKEN Environment Variable: No longer required in the publish step
- Added
id-token: writepermission - Added
always-auth: truetosetup-nodeaction - Removed
NODE_AUTH_TOKENenvironment variable from publish step - Added
--provenanceand--access publicflags tonpm publish
To test the trusted publishing workflow:
- Create a test commit on a feature branch
- Merge to the
mainbranch - If the commit triggers a release (based on conventional commits), the workflow will:
- Create a release PR via release-please
- Once merged, create a GitHub release
- Automatically publish to npm using trusted publishing
Monitor the workflow run in the Actions tab to verify successful publication.
- npm Trusted Publishers Documentation
- GitHub: Publishing Node.js Packages
- npm Provenance Documentation
- OpenID Connect in GitHub Actions
If the workflow fails with an authentication error:
- Verify that trusted publishing is properly configured on npm for the package
- Ensure the repository, workflow path, and environment (if any) match exactly in the npm settings
- Confirm that the workflow has the
id-token: writepermission
If the package is published but provenance is not attached:
- Ensure the
--provenanceflag is included in thenpm publishcommand - Verify that the workflow has
id-token: writepermission - Check that the package is being published from a supported environment (GitHub Actions)
If the package fails to publish due to access issues:
- Ensure the
--access publicflag is set (for public packages) - Verify that the npm package settings allow public access
- Confirm that the organization and package name are correct