Verdaccio Htpasswd Authentication Plugin
verdaccio-htpasswd is the official and default authentication plugin for Verdaccio, a lightweight private npm proxy registry. It enables user authentication by leveraging standard Apache `htpasswd` files, making it a simple yet effective solution for managing access to private packages. The package is currently at version 10.5.5 and is actively maintained as part of the Verdaccio monorepo, receiving updates in alignment with Verdaccio's release cycle (e.g., it was updated alongside Verdaccio 5.24.0). Its primary differentiator is its seamless, built-in integration with Verdaccio, offering file-based user management, support for various hashing algorithms including bcrypt, MD5, SHA1, and crypt, and an easy configuration process. It's ideal for private registries where a full-fledged database-backed authentication system is overkill, providing a straightforward approach to user registration and login.
Common errors
-
Error: EACCES: permission denied, open './htpasswd'
cause Verdaccio does not have write permissions to create or update the specified htpasswd file.fixEnsure the directory containing the `htpasswd` file, and the file itself, has appropriate read/write permissions for the user running the Verdaccio process. For example, `chown verdaccio_user:verdaccio_group /path/to/htpasswd_file` and `chmod 600 /path/to/htpasswd_file`. -
npm adduser fails or results in 'You don't have enough permission to perform this action'
cause The `max_users` setting in `config.yaml` is set to a specific number (or -1 to disable registration) and the limit has been reached, or registration is disabled. Alternatively, the Verdaccio URL in the `npm adduser` command is incorrect.fixCheck the `max_users` setting in `config.yaml`. If you intend to allow more users or enable registration, ensure it's not set to -1 or a low number. Also, verify that the `npm adduser --registry <URL>` command uses the correct URL for your Verdaccio instance. -
Users cannot log in despite correct htpasswd entries
cause The 'algorithm' or 'rounds' settings in 'config.yaml' for the htpasswd plugin do not match the algorithm/rounds used to generate the passwords in the 'htpasswd' file.fixEnsure that the `algorithm` and `rounds` configured in your `config.yaml` match exactly how the passwords were generated in your `htpasswd` file. If you change these settings in Verdaccio, you may need to regenerate user passwords using the new algorithm/rounds.
Warnings
- gotcha Using a high 'rounds' value for the 'bcrypt' algorithm (default is 10) significantly increases CPU usage during password verification. This can lead to increased latency and performance issues in Verdaccio instances handling a large volume of authenticated requests. Conversely, a value too low increases brute-force attack risk.
- deprecated Verdaccio 5.x running on Node.js versions 21 or lower might emit `[DEP0106] DeprecationWarning: crypto.createDecipher is deprecated` if the default legacy token signature is enabled. This is due to a deprecated Node.js API used by Verdaccio's legacy token handling.
- breaking Verdaccio v6.0.0 (the core registry, not this plugin directly) dropped support for Node.js 16. While verdaccio-htpasswd itself is at version 10.x, it runs within a Verdaccio instance. Therefore, upgrading Verdaccio to v6.0.0 will require a minimum Node.js version of 18 or higher.
Install
-
npm install verdaccio-htpasswd -
yarn add verdaccio-htpasswd -
pnpm add verdaccio-htpasswd
Imports
- Auth
const Auth = require('verdaccio-htpasswd');import Auth from 'verdaccio-htpasswd';
- IAuthModule
import type { IAuthModule } from '@verdaccio/types'; - Auth
import Auth from 'verdaccio-htpasswd';
const Auth = require('verdaccio-htpasswd');
Quickstart
auth:
htpasswd:
file: ./htpasswd
# Maximum amount of users allowed to register, defaults to "+infinity".
# Set to -1 to disable registration via `npm adduser`.
# max_users: 1000
# Hash algorithm, possible options are: "bcrypt", "md5", "sha1", "crypt".
# Default algorithm is crypt, but 'bcrypt' is recommended for new installations.
algorithm: bcrypt
# Rounds number for "bcrypt", ignored for other algorithms.
# Setting this higher increases security but also CPU usage during verification.
rounds: 10
# Example package access configuration using htpasswd authentication
packages:
'@*/*':
access: $authenticated # Only authenticated users can access scoped packages
publish: $authenticated # Only authenticated users can publish scoped packages
'**':
access: $all # All users (including anonymous) can access public packages
publish: $authenticated # Only authenticated users can publish public packages