I am Dimitri and I am a user and contributor of Verdaccio.
Today, I will explain how I migrated my private dockerized <imgheight="16px"src="https://github.githubassets.com/images/icons/emoji/unicode/1f433.png"title="docker"/> Verdaccio registry from `v3.x` to `v4.x`.
I will also configure [`verdaccio-ldap`](https://www.npmjs.com/package/verdaccio-ldap) to authenticate my users against LDAP.
First of all, I wante to congratulate everyone who tested, contributed to Verdaccio <imgheight="16px"src="https://github.githubassets.com/images/icons/emoji/unicode/1f389.png"title="congrats"/> v4 <imgheight="16px"src="https://github.githubassets.com/images/icons/emoji/unicode/1f388.png"title="congrats"/>.
V4 include bunch of improvment, optimization, starting with the Web UI made completely redesigned with ReactJS and MaterialUI.
Not only that security has been improved with the introduction of the optional `JWT`, but `v4` also bring a new feature to `unpublish` packages.
First thing I had to do was to update my `Dockerfile`, this is what I have done:
```Dockerfile
FROM verdaccio/verdaccio:4.3
USER root
RUN npm i && npm i verdaccio-ldap
COPY conf /verdaccio/conf
RUN chown -R $VERDACCIO_USER_UID /verdaccio
USER verdaccio
```
-`v3.x` is now using by default `verdaccio` user for security reason. This is why need to switch to `root` user to use `npm`.
- We install `verdaccio-ldap` but you can install any plugin. _(Only if you don't want the `verdaccio-htaccess` builtin solution to be your user database)_
- Later, you **MUST** solve the `storage` directory **permissions** and **ownership**.
You SHOULD use scope for all your privates packages, in this scenario, we use LDAP groups for `access`, `publish` and `unpublish`.
Note that we do not use `proxy: npmjs` because they only exist on our private registry.
I recommend you to create scope for all of your private packages, and reserve the group on npmjs registry so no one will be able to publish publicly in it in the futur.
For all other packages, to prevent anyone to use our registry, we just allow `$authenticated` to publish.
We also use `proxy: npmjs` so we also serve all the public package on npmjs registry.
We allow `$all` to download from our registry, because it is public, but if you want to preserve your bandwidth or just forbid unknown user to authenticate, just use `$authenticated` as well.
You will have to mount the `storage` volume when using `Docker`, to do that, just use `-v` with `docker run` command:
```bash
docker run -v /srv/verdaccio/storage:/verdaccio/storage verdaccio-3-ldap
```
Remember, you have made a backup of your storage directory, now let's fix `permissions` and `ownership` to finish verdaccio migration.
Because within the docker container, the user is `verdaccio`, you can't run `chown` and `chmod` commands. Just do it directly from your host as `root`:
```bash
cd /srv/verdaccio/ # the location depend of your installation
chmod -R 777 storage
VERDACCIO_USER_UID=10001 # unless you have changed it
First, fill appropriate LDAP group for all your LDAP users that should have access to the private npm registry.
> We call `$IP` the IP address of the server. If you serve it over `https` behind a reverse proxy or directly, then fix all the following command to use the right protocol.
This is all the test I have done while configurating verdaccio, before going to production:
-`[x]` it should work with `verdaccio-htaccess` when `verdaccio-ldap` is **not** installed. <imgsrc="https://github.githubassets.com/images/icons/emoji/unicode/2714.png"title="OK"name="OK"height="16px"/>
-`[x]` it should work with `verdaccio-htaccess` when `auth.ldap` is disabled and `verdaccio-ldap` is installed. <imgsrc="https://github.githubassets.com/images/icons/emoji/unicode/2714.png"title="OK"name="OK"height="16px"/>
-`[x]` it should work with one `verdaccio-ldap`. <imgsrc="https://github.githubassets.com/images/icons/emoji/unicode/2714.png"title="OK"name="OK"height="16px"/>
-`[x]` it should work with `verdaccio-htaccess` and fallback to `verdaccio-ldap` through **web**. <imgsrc="https://github.githubassets.com/images/icons/emoji/unicode/2714.png"title="OK"name="OK"height="16px"/>
-`[x]` it should work with `verdaccio-htaccess` and fallback to `verdaccio-ldap` through **npm**. <imgsrc="https://github.githubassets.com/images/icons/emoji/unicode/274c.png"title="NOK"name="NOK"height="16px"/>_Either use `verdaccio-htaccess` or `verdaccio-ldap`, it is useless to use both, even if the web work with the two, the `npm --add-user` command will fail._
-`[x]``npm --adduser` should work with different users. <imgsrc="https://github.githubassets.com/images/icons/emoji/unicode/2714.png"title="OK"name="OK"height="16px"/>
-`[x]``npm --adduser` should fail with wrong user/password. <imgsrc="https://github.githubassets.com/images/icons/emoji/unicode/2714.png"title="OK"name="OK"height="16px"/>
-`[x]` it should auth with JWT and the `verdaccio-ldap` plugin. <imgsrc="https://github.githubassets.com/images/icons/emoji/unicode/2714.png"title="OK"name="OK"height="16px"/>
-`[x]` it should auth with legacy and the `verdaccio-ldap` plugin. <imgsrc="https://github.githubassets.com/images/icons/emoji/unicode/2714.png"title="OK"name="OK"height="16px"/>
-`[x]``npm i` in CI that download from the registry **should spam** the LDAP with authentication requests with legaxy. <imgsrc="https://github.githubassets.com/images/icons/emoji/unicode/2714.png"title="OK"name="OK"height="16px"/>
-`[x]``npm i` in CI that download from the registry should not spam the LDAP with authentication requests with JWT. <imgsrc="https://github.githubassets.com/images/icons/emoji/unicode/2714.png"title="OK"name="OK"height="16px"/>
The new design with material-UI is super nice btw.
-`[x]` it should authenticate with different users. <imgsrc="https://github.githubassets.com/images/icons/emoji/unicode/2714.png"title="OK"name="OK"height="16px"/>
-`[x]` it should fail to authenticate with different users and wrong password. <imgsrc="https://github.githubassets.com/images/icons/emoji/unicode/2714.png"title="OK"name="OK"height="16px"/>
-`[x]` it should show packages to users with `access` permissions. <imgsrc="https://github.githubassets.com/images/icons/emoji/unicode/2714.png"title="OK"name="OK"height="16px"/>
-`[x]` it should hide packages to users without `access` permissions. <imgsrc="https://github.githubassets.com/images/icons/emoji/unicode/2714.png"title="OK"name="OK"height="16px"/>
-`[x]``access` should work with a user with perms. <imgsrc="https://github.githubassets.com/images/icons/emoji/unicode/2714.png"title="OK"name="OK"height="16px"/>
-`[x]``access` should fail with a user without perms.. <imgsrc="https://github.githubassets.com/images/icons/emoji/unicode/2714.png"title="OK"name="OK"height="16px"/>
-`[x]``access` should work with a user in ldap group with perms. <imgsrc="https://github.githubassets.com/images/icons/emoji/unicode/2714.png"title="OK"name="OK"height="16px"/>
-`[x]``access` should fail with a user not in ldap group with perms. <imgsrc="https://github.githubassets.com/images/icons/emoji/unicode/2714.png"title="OK"name="OK"height="16px"/>
-`[x]``publish` should work with a user with perms. <imgsrc="https://github.githubassets.com/images/icons/emoji/unicode/2714.png"title="OK"name="OK"height="16px"/>
-`[x]``publish` should work with a user in ldap group with perms. <imgsrc="https://github.githubassets.com/images/icons/emoji/unicode/2714.png"title="OK"name="OK"height="16px"/>
-`[x]``publish` should fail with a user not in ldap group without perms. <imgsrc="https://github.githubassets.com/images/icons/emoji/unicode/2714.png"title="OK"name="OK"height="16px"/>
-`[x]``unpublish` should work with a user with perms. <imgsrc="https://github.githubassets.com/images/icons/emoji/unicode/2714.png"title="OK"name="OK"height="16px"/>
-`[x]``unpublish` should fail with a user without perms. <imgsrc="https://github.githubassets.com/images/icons/emoji/unicode/2714.png"title="OK"name="OK"height="16px"/>
-`[x]``unpublish` should work with a ldap group with perms. <imgsrc="https://github.githubassets.com/images/icons/emoji/unicode/2714.png"title="OK"name="OK"height="16px"/>
-`[x]``unpublish` should fail with a user not in ldap group with perms. <imgsrc="https://github.githubassets.com/images/icons/emoji/unicode/2714.png"title="OK"name="OK"height="16px"/>
Docker, LDAP are a great way to authenticate users from your organization. In this article, you have learned how to setup verdaccion with LDAP and Docker.
I have to thank the teams and community behind verdaccio projects, specially [Juan Picado](https://twitter.com/jotadeveloper), [Daniel Refde](https://twitter.com/DanielRufde) and [Sergio Hg](https://github.com/sergiohgz) for their help on the GitHub issues and the discord [chat](http://chat.verdaccio.org/).
Also, but not less important, I want to thank all the people that makes Verdaccio possible, contributing, donating, documenting, and more.
I hope it is well explained and you people of verdaccio are able to reproduce a configuration that fit with your LDAP.
To me it took a while to figure out the different errors I had and the most annoying things was those manual step to fix the permissions and access.
If you have any question, please check at the FAQ below, or feel free to reply to this blog post.
> If you 😍 Verdaccio as I do, helps them to grow by donating to the project via [OpenCollective](https://opencollective.com/verdaccio).
- Can we use two authentication plugin together such as `verdaccio-htaccess`?
No you can't, but pull request are welcome.
- Does my registry users need to re-authenticate?
If you use `JWT` for authentication, which I recommend, they will all have to re-authenticate.
- I have `404` or `401` errors with good credentials.
This is due to wrong permissions or ownership in `storage` directory, dont forget to `chmod -R 777 /verdaccio/storage` and `chown -R $VERDACCIO_USER_UID /verdaccio`.
- When should I use `--always-auth` when running `--add-user`?