CorentinTh / enclosed

Minimalistic web app designed for sending private and secure notes.
https://enclosed.cc
Apache License 2.0
308 stars 13 forks source link

Authentication not working #181

Closed insanity67 closed 1 week ago

insanity67 commented 1 week ago

Describe the bug

I installed enclosed, everything works perfectly without authentication.

I deleted the conatiner and volume, and recreated with following docker line: docker run --name enclosed --restart unless-stopped -p 8787:8787 -e PUBLIC_IS_AUTHENTICATION_REQUIRED="true" -e AUTHENTICATION_JWT_SECRET="cff8d041963fcd1330xxxxxxxxxxxxe36b4677663651afa52eca9855" -e AUTHENTICATION_USERS=myuser@mydomain.com:$2a$10$yMW8mF.L2Na68/xnAoqrXej219jrYcU89dWfe/tfKbtyOZLZ.B1sa -e SERVER_CORS_ORIGINS="https://enc.mydomain.com" -v enclosed_data:/app/.data corentinth/enclosed

The AUTHENTICATION_USERS string was generated with: https://docs.enclosed.cc/self-hosting/users-authentication-key-generator

But I cannot login, tells me everytime "wrong username/password".

This logs did I get from docker:

{"level":30,"time":1726736855966,"pid":1,"hostname":"5d0f7c09b27d","namespace":"app","status":200,"method":"GET","path":"/login","routePath":"/*","durationMs":7,"msg":"Request completed"}
{"level":30,"time":1726736855999,"pid":1,"hostname":"5d0f7c09b27d","namespace":"app","status":200,"method":"GET","path":"/api/config","routePath":"/api/config","durationMs":1,"msg":"Request completed"}
{"level":30,"time":1726736856051,"pid":1,"hostname":"5d0f7c09b27d","namespace":"app","status":200,"method":"GET","path":"/site.webmanifest","routePath":"/*","durationMs":1,"msg":"Request completed"}
{"level":50,"time":1726736861769,"pid":1,"hostname":"5d0f7c09b27d","namespace":"middlewares:error","error":{"code":"auth.unauthorized","cause":{},"statusCode":401,"isCustomError":true},"msg":"Unauthorized"}
{"level":30,"time":1726736861770,"pid":1,"hostname":"5d0f7c09b27d","namespace":"app","status":401,"method":"POST","path":"/api/auth/login","routePath":"/api/auth/login","durationMs":5,"msg":"Request completed"}

What happened?

I expected to log in with my created username/password.

System information

Docker version 27.2.1, build 9e34c9b on Debian 12 Behind nginx proxy manager, running on the same docker instance.

Where did you encounter the bug?

Other (installations, docker, etc.)

insanity67 commented 1 week ago

I even tried enclosing AUTHENTICATION_USERS value in "" but did not change the error message.

Bartrpc commented 1 week ago

+1 Same problem here. I suspect that this could be related to middleware , which reverse proxy are you using ? I'm using Cloudflare tunnels and I supose it's not supported.

insanity67 commented 1 week ago

which reverse proxy are you using ?

Im using nginx proxy manager with default settings:

image

image

Bartrpc commented 1 week ago

@CorentinTh am I right, that some reverse proxy are not supported yet ?

insanity67 commented 1 week ago

@Bartrpc hmm... but how to self host this with ssl without some kind of reverse proxy? 🤔

Bartrpc commented 1 week ago

it must work behind reverse proxy, there is a pop-up with info that if you're using Enclosed with HTTP you will not be able to create notes. I dunno what to do. For now I'm stopping the container and waiting for developer response ;)

CorentinTh commented 1 week ago

Hi @insanity67 and @Bartrpc

When passing environment variables in the Docker CLI using the -e flag, you need to escape the $ sign (i.e., replace $ with \$). This is because the $ sign is interpreted by bash.

For example, with your command:

docker run --name enclosed --restart unless-stopped -p 8787:8787 -e PUBLIC_IS_AUTHENTICATION_REQUIRED="true" -e AUTHENTICATION_JWT_SECRET="cff8d041963fcd1330xxxxxxxxxxxxe36b4677663651afa52eca9855" -e AUTHENTICATION_USERS="myuser@mydomain.com:\$2a\$10\$yMW8mF.L2Na68/xnAoqrXej219jrYcU89dWfe/tfKbtyOZLZ.B1sa" -e SERVER_CORS_ORIGINS="https://enc.mydomain.com/" -v enclosed_data:/app/.data corentinth/enclosed

Alternatively, you can use the --env-file option to load environment variables from a file without needing to escape the content

I'll also consider adding an option to pass this variable as base64 in the future, which would eliminate the need to escape special characters.

Let me know if it solved the issue

insanity67 commented 1 week ago

@CorentinTh Wow, thanks for your quick reply! I escaped the "$", now everything works as expected 😍

CorentinTh commented 1 week ago

I'll add a warning on the variable generator page

insanity67 commented 1 week ago

@CorentinTh good idea, thank you! Really love that project, was looking for such a solution since ever.

Bartrpc commented 1 week ago

Ok, now works, thank You. It turns out that in env_file I had to do it with "" and \ and it's working :) .env -> AUTHENTICATION_USERS="user@proton.me:\$2a\$10\$8M4JjO8YP6pkDCqtFolzUOSb25ptxA3qqVCoa7ne50SfmrzUWQN5C"

I'm using docker-compose.yml and dockge for deploy :)

Bartrpc commented 1 week ago

You've to escape $ in .env file :) It's mandatory :)

Bartrpc commented 1 week ago

Thank You @CorentinTh - fantastic idea with that project :)