Repository navigation
Add npm trusted publishing #531
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,58 @@ | ||
| name: Publish | ||
|
|
||
| on: | ||
| push: | ||
| tags: | ||
| - "v*" | ||
|
|
||
| jobs: | ||
| publish: | ||
| name: Publish to npm | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| id-token: write | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Tagged commit is on master | ||
| run: git merge-base --is-ancestor "$GITHUB_SHA" origin/master | ||
|
|
||
| - uses: actions/setup-node@v4 | ||
| with: | ||
| node-version-file: .github/files/.nvmrc | ||
| registry-url: https://registry.npmjs.org | ||
|
|
||
| - name: Corepack | ||
| run: corepack enable | ||
|
|
||
| - name: Install | ||
| run: yarn | ||
|
|
||
| - name: Tag matches package versions | ||
| run: | | ||
| for pkg in db-client opentelemetry; do | ||
| version="v$(jq -r .version packages/$pkg/package.json)" | ||
| if [ "$version" != "$GITHUB_REF_NAME" ]; then | ||
| echo "::error::packages/$pkg is $version but tag is $GITHUB_REF_NAME" | ||
| exit 1 | ||
| fi | ||
| done | ||
|
|
||
| - name: Build | ||
| run: yarn build | ||
|
|
||
| - name: Pack | ||
| run: | | ||
| yarn workspace @kurrent/kurrentdb-client pack --out "$RUNNER_TEMP/db-client.tgz" | ||
| yarn workspace @kurrent/opentelemetry pack --out "$RUNNER_TEMP/opentelemetry.tgz" | ||
|
|
||
| - name: Update npm for trusted publishing | ||
| run: npm install -g npm@latest | ||
|
|
||
| - name: Publish | ||
| run: | | ||
| npm publish "$RUNNER_TEMP/db-client.tgz" --access public | ||
| npm publish "$RUNNER_TEMP/opentelemetry.tgz" --access public | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Script executed:
Repository: kurrent-io/KurrentDB-Client-NodeJS
Length of output: 8853
Web query:
GitHub Actions ACTIONS_ID_TOKEN_REQUEST_TOKEN environment variable available every step id-token write OIDC npm trusted publishing workflow authorizationResult:
Script executed (no clone):
Length of output: 4946
Script executed:
Repository: kurrent-io/KurrentDB-Client-NodeJS
Length of output: 5274
Script executed (no clone):
Length of output: 2738
Security Misconfiguration
Reachability: External
Exploitability: Difficult
CWE: CWE-250
View Security blast radius
Keep dependency installation outside the OIDC-enabled job.
If npm trusts this workflow to publish, a malicious dependency install script can request an OIDC token and publish before the version check.
Run installation, build, and pack in a job without
id-token: write. Pass the tarballs to a separate publish job that uses a compatible preinstalled npm. This separation does not prevent a compromised dependency from altering the tarballs.Source: Learnings