Skip to content

Commit b4c1aab

Browse files
committed
#74: Secure npm release publishing
1 parent d3d1f6d commit b4c1aab

3 files changed

Lines changed: 26 additions & 7 deletions

File tree

.github/workflows/release.yml

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ jobs:
99
# When a prerelease is promoted to a full release, update the npm latest tag
1010
promote:
1111
if: github.event.action == 'released'
12+
permissions:
13+
contents: read
1214
runs-on: ubuntu-24.04
1315
steps:
1416
- name: Checkout code
@@ -18,6 +20,10 @@ jobs:
1820
with:
1921
node-version-file: '.node-version'
2022
registry-url: https://registry.npmjs.org
23+
- name: Install supported npm CLI
24+
run: |
25+
npm install --global npm@11.5.1
26+
npm --version
2127
- name: Promote edge to latest
2228
run: |
2329
VERSION=$(echo "$TAG_NAME" | sed 's/^v//')
@@ -26,10 +32,13 @@ jobs:
2632
echo "::notice title=Promoted $VERSION to latest::The latest tag now points to $VERSION (was edge-only)"
2733
env:
2834
TAG_NAME: ${{ github.event.release.tag_name }}
29-
NODE_AUTH_TOKEN: ${{secrets.NPM_DEPLOY_TOKEN}}
35+
NODE_AUTH_TOKEN: ${{ secrets.NPM_DIST_TAG_TOKEN }}
3036

3137
deploy:
3238
if: github.event.action == 'published'
39+
permissions:
40+
contents: read
41+
id-token: write
3342
runs-on: ${{ matrix.os }}
3443
env:
3544
TERM: xterm
@@ -48,6 +57,10 @@ jobs:
4857
node-version-file: '.node-version'
4958
registry-url: https://registry.npmjs.org
5059
cache: npm
60+
- name: Install supported npm CLI
61+
run: |
62+
npm install --global npm@11.5.1
63+
npm --version
5164
- name: Install dependencies
5265
run: npm clean-install --prefer-offline --frozen-lockfile
5366

@@ -84,5 +97,3 @@ jobs:
8497
npm publish --access public --tag ${{ env.PRERELEASE_TAG }}
8598
echo "::notice title=Published ${{ github.ref_name }} to @${{ github.repository }}@${{ env.PRERELEASE_TAG }}::This is a pre-release published to the '${{ env.PRERELEASE_TAG }}' npm tag"
8699
fi
87-
env:
88-
NODE_AUTH_TOKEN: ${{ secrets.NPM_DEPLOY_TOKEN }}

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,14 @@ npm run test:unit
266266

267267
## Releasing
268268

269-
To deploy and publish a new version of the package to the `npm` registry you need only [create a release on GitHub](https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository) with a [semver](https://semver.org) tag.
269+
To deploy and publish a new version of the package to the `npm` registry you need only [create a release on GitHub](https://docs.github.com/en/repositories/releasing-projects-on-github/managing-releases-in-a-repository) with a [semver](https://semver.org) tag. Stable releases publish to the `latest` tag, while prereleases publish to `edge`. Promoting a prerelease to a full release moves that version to `latest`.
270270

271-
Note that prereleases will get pushed to the `edge` tag on the `npm` registry.
271+
Before releasing, maintainers must configure the following external access:
272+
273+
* Add a GitHub Actions trusted publisher to the `@lando/leia` package on npm with organization `lando`, repository `leia`, workflow filename `release.yml`, no environment, and the `npm publish` allowed action. The workflow publishes through OIDC and does not use an npm token.
274+
* Create a short-lived granular npm token with read and write access only to the `@lando/leia` package, no organization access, and 2FA bypass only when the package settings require it for unattended writes. Store it as the `NPM_DIST_TAG_TOKEN` GitHub Actions secret. npm granular tokens cannot be limited to one CLI command, so package-only read and write access is the narrowest permission available for the `npm dist-tag add` promotion step.
275+
276+
Configure both before running this workflow. After an authorized release verifies trusted publishing and promotion, revoke the broader `NPM_DEPLOY_TOKEN` that the previous workflow used.
272277

273278
## Maintainers
274279

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
"version": "1.0.0-beta.4",
55
"author": "Mike Pirog @pirog",
66
"license": "MIT",
7-
"repository": "github:lando/leia",
7+
"repository": {
8+
"type": "git",
9+
"url": "git+https://github.com/lando/leia.git"
10+
},
811
"bugs": "https://github.com/lando/leia/issues/new/choose/",
912
"homepage": "https://github.com/lando/leia",
1013
"keywords": [
@@ -19,7 +22,7 @@
1922
},
2023
"main": "lib/leia.js",
2124
"bin": {
22-
"leia": "./bin/leia"
25+
"leia": "bin/leia"
2326
},
2427
"files": [
2528
"/bin",

0 commit comments

Comments
 (0)