Skip to content

Commit e80e52f

Browse files
committed
ci: Enhance NPM publishing security with OIDC
Migrates the npm publish steps in the production and RC release workflows to use OpenID Connect (OIDC) for authentication. This removes the reliance on a long-lived npm token secret, improving security by leveraging short-lived, ephemeral credentials.
1 parent 1065dfb commit e80e52f

2 files changed

Lines changed: 9 additions & 12 deletions

File tree

.github/workflows/production-release.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ jobs:
156156
runs-on: ubuntu-latest
157157
needs: [validate-release]
158158
if: needs.validate-release.result == 'success' && needs.validate-release.outputs.is_valid == 'true'
159+
permissions:
160+
contents: read
161+
id-token: write
159162

160163
steps:
161164
- name: Checkout repository
@@ -165,17 +168,15 @@ jobs:
165168
uses: actions/setup-node@v4
166169
with:
167170
node-version: 20
171+
registry-url: 'https://registry.npmjs.org'
168172

169173
- name: Publish to npm
170174
if: needs.validate-release.outputs.is_dry_run != 'true'
171175
env:
172-
CI_NPM_TOKEN: ${{ secrets.CI_NPM_TOKEN }}
173176
VERSION: ${{ needs.validate-release.outputs.version }}
174177
run: |
175178
echo "Publishing version $VERSION to npm..."
176-
echo "//registry.npmjs.org/:_authToken=$CI_NPM_TOKEN" > ~/.npmrc
177179
npm publish
178-
rm ~/.npmrc
179180
echo "Published $VERSION to npm"
180181
181182
- name: Dry-run publish

.github/workflows/rc-release.yml

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,9 @@ jobs:
452452
runs-on: ubuntu-latest
453453
needs: [validate-release, prepare-branch, pre-publish-gate, validate-jira]
454454
if: always() && needs.pre-publish-gate.result == 'success' && needs.pre-publish-gate.outputs.passed == 'true' && (needs.validate-jira.result == 'success' || needs.validate-jira.result == 'skipped')
455+
permissions:
456+
contents: read
457+
id-token: write
455458
steps:
456459
- name: Checkout repository
457460
uses: actions/checkout@v5
@@ -463,6 +466,7 @@ jobs:
463466
uses: actions/setup-node@v4
464467
with:
465468
node-version: '20'
469+
registry-url: 'https://registry.npmjs.org'
466470

467471
- name: Install dependencies
468472
run: npm install
@@ -477,15 +481,7 @@ jobs:
477481
478482
- name: Publish RC to npm
479483
if: ${{ needs.validate-release.outputs.is_dry_run != 'true' }}
480-
env:
481-
CI_NPM_TOKEN: ${{ secrets.CI_NPM_TOKEN }}
482-
run: |
483-
if [[ -z "${CI_NPM_TOKEN}" ]]; then
484-
echo "CI_NPM_TOKEN is missing"; exit 1
485-
fi
486-
echo "//registry.npmjs.org/:_authToken=${CI_NPM_TOKEN}" > ~/.npmrc
487-
npm publish --tag rc
488-
rm -f ~/.npmrc
484+
run: npm publish --tag rc
489485

490486
# ===========================================================================
491487
# Create Pre-Release Tag

0 commit comments

Comments
 (0)