Skip to content

Drop NPM_TOKEN, publish via npm Trusted Publishers (OIDC) - #9

Merged
swift-man merged 2 commits into
mainfrom
chore/npm-oidc-publish
Apr 24, 2026
Merged

Drop NPM_TOKEN, publish via npm Trusted Publishers (OIDC)#9
swift-man merged 2 commits into
mainfrom
chore/npm-oidc-publish

Conversation

@swift-man

Copy link
Copy Markdown
Owner

Replace the long-lived NPM_TOKEN secret with npm Trusted Publishers so publish is authenticated via GitHub Actions OIDC.

Why

NPM_TOKEN automation tokens expire every 90 days, forcing a manual rotation every release cycle. npm Trusted Publishers exchanges a short-lived OIDC token for npm credentials at publish time — no static secret to keep alive, no rotation calendar.

Changes

  • Remove the `NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}` env line from the publish step.
  • Comment-document why the env block is empty.

The pieces OIDC needs are already wired:

  • `permissions: id-token: write` on the job
  • `registry-url: "https://registry.npmjs.org"\` on `actions/setup-node`
  • `--provenance` on `npm publish`

Pre-merge requirement

Trusted publisher must be configured on npm first:
`@swift-man/material-design-color` → Settings → Publishing access → Add trusted publisher → GitHub Actions → repo `swift-man/MaterialDesignColor`, workflow `npm-publish.yml`. (Already set up by the maintainer before opening this PR.)

Post-merge

```bash
gh secret delete NPM_TOKEN --repo swift-man/MaterialDesignColor
```

Test plan

  • After merge: cut a patch release (e.g. v2.0.1) or use `workflow_dispatch`, confirm publish succeeds without NPM_TOKEN, confirm provenance statement still gets signed.

🤖 Generated with Claude Code

The publish workflow currently authenticates with a long-lived
NPM_TOKEN secret that npm caps at 90 days, so the maintainer has
to rotate it every release cycle. npm Trusted Publishers (added
in 2024) lets GitHub Actions trade its short-lived OIDC token for
a per-publish npm credential — no static secret to manage, and
the credential is gone before the workflow exits.

The pieces this needs are already in place: id-token: write
permission on the job, registry-url set on actions/setup-node,
and --provenance on npm publish. Just remove the NODE_AUTH_TOKEN
env line so npm falls through to OIDC. Document the wiring in
a step comment so it's obvious why there's no token.

Trusted publisher must be configured on the npm package side
(@swift-man/material-design-color → Settings → Publishing access)
pointing at this repo + workflow filename. After this PR merges
the NPM_TOKEN secret can be deleted.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

@mlx-review-bot mlx-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

npm-publish.yml 파일에서 NPM_TOKEN 사용이 제거되었습니다. OIDC를 사용하여 인증을 처리하는 방식이 설명되었습니다.

개선된 점

  • NPM_TOKEN 사용이 제거되어 보안이 향상되었습니다.

라인 단위 코멘트

  • 라인 단위로 남길 개선 사항은 발견되지 않았습니다.

사용된 모델: mlx-community/Qwen2.5-Coder-7B-Instruct-4bit

@codex-review-bot codex-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

정적 토큰 제거 자체는 보안 방향이 맞지만, 현재 워크플로는 Trusted Publishers가 요구하는 런타임 버전을 만족하지 못할 가능성이 큽니다. NODE_AUTH_TOKEN을 제거한 상태에서 Node 20의 기본 npm으로 publish를 시도하면 OIDC 인증 경로가 동작하지 않아 릴리스가 실패할 수 있습니다. 병합 전 publish 런타임을 Trusted Publishers 지원 버전으로 올리는 수정이 필요합니다.

좋은 점

  • 장기 수명 NPM_TOKEN을 제거하고 GitHub Actions OIDC 기반 publish로 전환한 점은 토큰 유출 및 주기적 회전 부담을 줄입니다.
  • id-token: write, registry-url, --provenance가 publish 흐름에 함께 배치되어 인증 의도가 워크플로 안에서 확인됩니다.

🔴 반드시 수정할 사항

  • .github/workflows/npm-publish.yml의 Node/npm 버전이 npm Trusted Publishers 요구 조건을 만족하도록 갱신해야 합니다. 공식 npm 문서 기준 Trusted Publishers는 Node 22.14.0 이상 및 npm 11.5.1 이상이 필요하므로, actions/setup-nodenode-version22.14.0 이상 또는 24로 올리고 npm 버전도 함께 보장하는 구성이 필요합니다. 참고: https://docs.npmjs.com/trusted-publishers

💡 권장 개선 사항

  • 변경 후 workflow_dispatch로 실제 publish 경로를 한 번 검증해 OIDC 설정의 저장소명, 워크플로 파일명, 브랜치 조건이 npm 쪽 Trusted Publisher 설정과 정확히 일치하는지 확인하는 것이 좋습니다.
⚠️ 인라인 게시에서 제외된 지적 1건 (RIGHT-side diff 밖 · GitHub 422 방어) — 펼쳐 보기
  • .github/workflows/npm-publish.yml:36 — [Major] 문제 → NPM_TOKEN을 제거했지만 publish 런타임은 여전히 Node 20입니다. npm Trusted Publishers는 Node 22.14.0 이상 및 npm 11.5.1 이상이 필요하므로, Node 20에 번들된 npm에서는 OIDC 인증이 동작하지 않을 수 있습니다. 영향 → 릴리스 시 npm publish가 인증 실패로 중단되어 패키지를 배포하지 못합니다. 제안 → node-version22.14.0 이상 또는 24로 올리고, 필요하면 publish 전에 npm --version 확인 또는 npm 11.5.1 이상 설치 단계를 추가해 지원 버전을 명시적으로 보장하세요.

리뷰 모델: gpt-5.5

@gemini-pr-review-bot gemini-pr-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

장기 유지되던 정적 토큰을 제거하고 OIDC 기반의 npm Trusted Publishers 인증으로 전환한 모범적인 보안 강화 PR입니다. 인증 교환에 필요한 권한과 환경 설정이 적절히 구성되었으며, 전반적인 배포 워크플로우가 더욱 안전하고 유지보수하기 쉽게 개선되었습니다.

좋은 점

  • 보안성이 취약한 정적 시크릿 주입 방식을 폐기하고 OIDC 인증 방식을 도입하여, 토큰 유출 위험과 90일 주기의 수동 토큰 교체 부담을 완전히 제거한 점이 훌륭하게 설계되었습니다.
  • 수동 배포와 릴리스 이벤트가 공존하는 상황에서 태그 변수가 누락되지 않도록, ${TAG:-latest} 쉘 매개변수 확장을 통해 빈 문자열에 대한 안전한 기본값 폴백(fallback)을 구현한 점이 좋습니다.

개선할 점

  • 새로운 OIDC 기반 배포 인프라가 적용됨에 따라, 향후 npm 측의 Trusted Publisher 설정 여부가 배포 워크플로우 성공의 핵심 전제조건이 되었습니다. PR 본문에 명시된 이 구성 요구사항을 리포지토리의 운영 가이드나 CONTRIBUTING.md 문서에도 반영해두면, 새로운 메인테이너의 온보딩과 권한 관련 트러블슈팅에 큰 도움이 될 것입니다.

기술 단위 코멘트 1건은 각 라인에 별도 표시됩니다.


리뷰 생성 모델: gemini-3.1-pro-preview

Comment thread .github/workflows/npm-publish.yml Outdated
# actions/setup-node lets `npm publish` exchange a short-lived OIDC
# token for an npm credential at publish time. No NPM_TOKEN secret
# required; nothing to rotate every 90 days.
run: npm publish --provenance --tag "${TAG:-latest}"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Suggestion] 커맨드 라인에서 --provenance 플래그를 지정하여 출처 서명을 활성화한 것은 아주 좋은 보안 실천입니다. 대안적인 방법으로 package.jsonpublishConfig 객체 내부에 "provenance": true 속성을 선언하여 관리하면, CLI 인자를 줄이고 패키지 배포 관련 정책을 설정 파일 한 곳으로 더 명확하게 응집시킬 수 있습니다.

Codex flagged that npm Trusted Publishers needs npm 11.5.1+ to
perform the OIDC token exchange, but the publish workflow was
pinned to Node 20 (which ships npm 10). Without the upgrade the
new authentication path would silently miss its credential
exchange and the next release would fail.

Bump actions/setup-node to Node 22 in both the publish workflow
and the Swift CI workflow — keeping the two in sync so the smoke
test runs on the same npm the release does.

While here, take Gemini's suggestion and move `provenance: true`
into package.json's `publishConfig`. The CLI flag and the manifest
key do the same thing, but pinning it in the manifest means
provenance applies regardless of who runs `npm publish` (CI,
maintainer locally, future workflows), instead of being one CLI
arg that someone could omit.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

@codex-review-bot codex-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

변경 범위는 npm 배포 인증을 장기 토큰에서 신뢰할 수 있는 게시자 기반으로 전환하는 데 집중되어 있습니다. 워크플로의 권한, 레지스트리 설정, 배포 전 빌드·스모크 테스트 흐름이 서로 맞물려 있어 의도한 OIDC 배포 경로와 일관됩니다. 다만 npm 쪽 신뢰할 수 있는 게시자 설정은 저장소 코드만으로 검증되지 않으므로, 첫 배포에서 확인이 필요합니다.

좋은 점

  • 배포 워크플로에서 장기 NPM_TOKEN 의존성을 제거하고 id-token 권한과 setup-node registry-url 조합으로 인증 경로를 단순화한 점
  • publishConfig.provenance 를 package.json에 두어 로컬과 워크플로 배포 모두에서 provenance 설정이 동일하게 적용되도록 한 점
  • CI의 Node 버전을 배포 워크플로와 맞춰 패키징·스모크 테스트가 배포 런타임에 더 가깝게 실행되도록 한 점

💡 권장 개선 사항

  • npm 신뢰할 수 있는 게시자 설정은 코드 리뷰에서 확인할 수 없으므로, 병합 후 첫 workflow_dispatch 또는 패치 릴리스에서 인증과 provenance 서명이 성공하는지 반드시 확인하는 운영 체크가 필요합니다.

리뷰 모델: gpt-5.5

@mlx-review-bot mlx-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

npm publish workflow에서 Node.js 버전을 22로 업데이트하고, npm publish 명령어에서 인증 방식을 변경했습니다.

반드시 수정할 사항

  • npm publish 명령어에서 인증 방식이 변경되었으나, NPM_TOKEN secret이 사용되지 않도록 코드를 수정해야 합니다.

권장 개선사항

  • npm publish 명령어에서 provenance 설정을 유지하도록 코드를 수정할 수 있습니다.

개선된 점

  • Node.js 버전을 22로 업데이트하여 최신 기능을 사용할 수 있습니다.

라인 단위 코멘트

  • 자동 리뷰에서 1개의 라인 단위 개선 사항을 남겼습니다.

사용된 모델: mlx-community/Qwen2.5-Coder-7B-Instruct-4bit

with:
node-version: "20"
# Node 22 ships npm 11; npm Trusted Publishers (OIDC) requires
# npm 11.5.1+ to perform the OIDC token exchange.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Major] npm publish 명령어에서 인증 방식이 변경되었으나, NPM_TOKEN secret이 사용되지 않도록 코드를 수정해야 합니다.

@swift-man
swift-man merged commit 4bc5473 into main Apr 24, 2026
1 check passed
@swift-man
swift-man deleted the chore/npm-oidc-publish branch April 24, 2026 18:22

@gemini-pr-review-bot gemini-pr-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NPM_TOKEN을 제거하고 npm Trusted Publishers (OIDC)를 도입하여 유지보수성과 보안을 크게 개선한 훌륭한 PR입니다. OIDC 기반 인증과 provenance 설정이 권장되는 패턴으로 정확하게 적용되었습니다.

좋은 점

  • 장기 유효 정적 크리덴셜(NPM_TOKEN) 의존성을 제거하고 GitHub Actions OIDC를 통한 단기 자격 증명 교환 방식을 도입하여 공급망 보안을 크게 강화한 점
  • provenance: true를 CLI 플래그 대신 package.jsonpublishConfig에 선언하여, 실행 주체와 무관하게 항상 출처 증명이 포함되도록 구조화한 점

기술 단위 코멘트 1건은 각 라인에 별도 표시됩니다.


리뷰 생성 모델: gemini-3.1-pro-preview

# Node 22 ships npm 11; npm Trusted Publishers (OIDC) requires
# npm 11.5.1+ to perform the OIDC token exchange.
node-version: "22"
registry-url: "https://registry.npmjs.org"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Suggestion] npm 11.5.1+의 네이티브 OIDC 기능을 퍼블릭 레지스트리에 사용할 때, actions/setup-node에서 registry-url을 명시하면 .npmrc_authToken=${NODE_AUTH_TOKEN} 구문이 주입됩니다. 이번 PR에서 NODE_AUTH_TOKEN 환경 변수를 제거했으므로 빈 변수 참조로 인한 불필요한 경고가 발생할 수 있습니다. 기본 퍼블릭 레지스트리 대상이므로 이 라인을 제거하고 npm 내부의 기본 레지스트리 처리에 맡기는 것을 고려해 보세요.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant