Skip to content

feat: support authenticated npm registry for CLI download - #325

Open
minijus wants to merge 1 commit into
crowdin:js-actionfrom
minijus:npm-registry-token-auth
Open

minijus wants to merge 1 commit into
crowdin:js-actionfrom
minijus:npm-registry-token-auth

Conversation

@minijus

@minijus minijus commented Nov 24, 2026 •

Copy link
Copy Markdown

Summary

Adds an npm_registry_token input so the CLI can be downloaded from an authenticated npm mirror (e.g. Artifactory/Nexus) set via npm_registry_url. Today a private registry can't be used, and users fall back to use_installed_cli: true plus a manual install step.

Changes

  • New npm_registry_token input. It is masked with core.setSecret.
  • The token is sent as Authorization: Bearer … only to URLs whose origin (scheme, host and port) matches npm_registry_url. This applies to the packument request and same-origin tarball downloads. Tarballs on another origin (e.g. a CDN) are downloaded without credentials.
  • Authenticated tarball downloads use the toolkit HTTP client, honor proxy settings, retry transient failures, and remove credentials on cross-origin redirects. Unauthenticated downloads still use tc.downloadTool.
  • A warning is logged when a supplied token is withheld because the tarball is on another origin.
  • INPUT_NPM_REGISTRY_TOKEN is removed from the process environment in run(), so the CLI and other subprocesses don't inherit the token.
  • README: documents the input and adds an example that pins cli_version with a Renovate annotation (customManagers:githubActionsVersions).
  • Unit tests cover the origin scoping, including look-alike hosts, userinfo, scheme and port changes, and a cross-port redirect. dist/ is rebuilt.

Example

env:
  # renovate: datasource=npm depName=@crowdin/cli-linux-x64
  CROWDIN_CLI_VERSION: '5.5.0'
steps:
  - uses: crowdin/github-action@v4
    with:
      cli_version: ${{ env.CROWDIN_CLI_VERSION }}
      npm_registry_url: https://artifactory.example.com/artifactory/api/npm/npm-remote
      npm_registry_token: ${{ secrets.NPM_REGISTRY_TOKEN }}

🤖 Generated by Claude Opus 5.5 (claude-opus-5.5)

@minijus
minijus force-pushed the npm-registry-token-auth branch 2 times, most recently from 58774dc to fb52449 Compare November 24, 2026 20:25
@minijus
minijus marked this pull request as ready for review November 24, 2026 20:34

@andrii-bodnar andrii-bodnar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@minijus thanks for the PR, this is a useful feature!

The custom download path seems overcomplicated. tc.downloadTool(url, dest, auth) already takes an authorization header, retries, honours proxies, and strips the header on cross-host redirects. Could we use it and drop downloadAuthenticated, the @actions/http-client dependency, and the related tests?

Also:

  • Warn when the token is withheld because the tarball is on a different origin.
  • Move the delete process.env... out of readInputs().

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@minijus
minijus force-pushed the npm-registry-token-auth branch from fb52449 to 51a7ffb Compare December 5, 2026 16:53
@minijus

minijus commented Dec 5, 2026

Copy link
Copy Markdown
Author

Thanks for the review! I've pushed the changes:

  • A warning is now logged when npm_registry_token is set but the tarball is on a different origin from npm_registry_url, so the token isn't sent.
  • Removing INPUT_NPM_REGISTRY_TOKEN from the environment moved out of readInputs() into run(), right after core.setSecret, so readInputs() doesn't change state anymore.

I looked into switching to tc.downloadTool(url, dest, auth) but kept the small custom download. The token should only go to the registry's own origin (scheme, host and port), and the toolkit can't guarantee that:

  • @actions/http-client, which tc.downloadTool uses, removes Authorization on a redirect only when the hostname changes. A redirect to another port on the same host still gets the token.
  • I also tried a custom RequestHandler that checks each redirect. It sees the host and port, but not the scheme, so a same-host, same-port http: to https: redirect would still get the token.

The custom code follows redirects itself and re-checks the full origin each time. Once the chain leaves the registry origin, the token is never sent again, and HTTPS-to-HTTP redirects are refused. It still uses @actions/http-client, so proxy settings work, and it keeps three retries like tc.downloadTool. Unauthenticated downloads still use tc.downloadTool. The tests for redirects to another port and to another scheme are the ones that would fail if this were simplified.

Happy to change this if you'd rather go another way.

🤖 Generated by Claude Opus 5.5 (claude-opus-5.5)

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.

2 participants