Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Web UI - Authentification #40

Open
jygastaud opened this issue Feb 27, 2015 · 15 comments
Open

Web UI - Authentification #40

jygastaud opened this issue Feb 27, 2015 · 15 comments

Comments

@jygastaud
Copy link

Hi,

Is there currently a way to have an authentification (at least Basic Auth) for the UI?

Thanks.

@ian-kent
Copy link
Member

Hi @jygastaud

Not at the moment - you could proxy it with nginx to add authentication there instead

I'll have a look at adding support for it - shouldn't be too difficult.

@grega
Copy link

grega commented May 22, 2015

👍 I'd love to have the option to require basic auth as well.

ian-kent added a commit to mailhog/http that referenced this issue May 27, 2015
ian-kent added a commit to mailhog/MailHog-Server that referenced this issue May 27, 2015
ian-kent added a commit to mailhog/MailHog-UI that referenced this issue May 27, 2015
@ian-kent
Copy link
Member

I've added support for HTTP auth, haven't done a new binary release yet though.

Let me know what you think - not really sure how well it'll work, bcrypting a password so often will probably be too slow. I'll probably switch to using cookies and api tokens to speed it up when I have a chance!

@GabLeRoux
Copy link

If someone's looking for ldap login, I haven't tried yet, but nginx-auth-ldap may be useful here if someone tries to proxy with nginx for auth.

@hamrant
Copy link

hamrant commented Mar 12, 2016

MailHog -auth-file=docs/example-auth
flag provided but not defined: -auth-file

@ashleyhindle
Copy link

This is definitely working now, I imagine this issue can be closed

Example command: /usr/local/bin/mailhog -auth-file=/home/mailhog/auth -api-bind-addr='0.0.0.0:80' -ui-bind-addr='0.0.0.0:80' -smtp-bind-addr='0.0.0.0:25'

@ian-kent
Copy link
Member

ian-kent commented Jul 7, 2016

Thanks, glad it's working 👍

I'll keep the issue open for now as a reminder to make password handling less bcrypt-crazy

@klokie
Copy link

klokie commented Sep 6, 2016

Nice!
Would you be able to explain how to enable basic auth via docker environment variables? I haven't figured that part out yet.

@fredleger
Copy link

fredleger commented Feb 8, 2017

@klokie :

Basically you will need to override the entry-point that is used as default command by the docker container.

In docker compose , something like:

entrypoint: MailHog -auth-file=/data/mailhog/auth.file

or on the command line just add "--entrypoint MailHog -auth-file=/data/mailhog/auth.file" to you docker run command.

@RuchyK
Copy link

RuchyK commented May 18, 2017

@fredleger ,
Running this command:

➜  ~ sudo docker run --name=maildocker -d -it -p 1025:1025 -p 8025:8025 --entrypoint MailHog -auth-file=/data/mailhog/auth.file mailhog/mailhog

fails with this error:

 invalid argument "uth-file=/data/mailhog/auth.file" for auth-file=/data/mailhog/auth.file: valid streams are STDIN, STDOUT and STDERR

Any idea?
The location passed to auth-file is on the host machine or on the docker?

@GabLeRoux
Copy link

GabLeRoux commented May 19, 2017

invalid argument "uth-file...
uth-file?

Maybe a typo on your side with docker command line?

Details about authentification can be found here:
https://github.com/mailhog/MailHog/blob/7ea7fe4/docs/Auth.md

The file should be inside docker. I suppose it's easier using docker-compose here, but I do get the same result as you with your command.

More details on docker run documentation

I was able to make a local MailHog install work this way:

go get github.com/mailhog/MailHog
echo "bob:$(MailHog bcrypt bob)" > auth.file
cat auth.file
bob:$2a$04$UIjxgUHqHWL4o5KVrF9AC.sbVxmXSOVMGhyz66Khx5ZFh2BdKnYKO
MailHog --auth-file=./auth.file

docker solution

🎉 I managed to get it working like this (without --entrypoint thingy):

docker run --name=maildocker -d -it -p 1025:1025 -p 8025:8025 -v $(pwd):/data/mailhog/ mailhog/mailhog -auth-file=/data/mailhog/auth.file

Output from the container's logs:

2017/05/19 18:01:45 Using in-memory storage
[HTTP] Loaded 1 users from /data/mailhog/auth.file
2017/05/19 18:01:45 [SMTP] Binding to address: 0.0.0.0:1025
[HTTP] Binding to address: 0.0.0.0:8025
2017/05/19 18:01:45 Serving under http://0.0.0.0:8025/
Creating API v1 with WebPath: 
Creating API v2 with WebPath: 
[APIv2] GET /api/v2/jim
[APIv2] GET /api/v2/messages
[APIv2] GET /api/v2/websocket
[APIv1] KEEPALIVE /api/v1/events

@fredleger
Copy link

fredleger commented May 20, 2017 via email

@RuchyK
Copy link

RuchyK commented May 21, 2017

thanks @GabLeRoux !
docker solution worked!!

@tanc
Copy link

tanc commented Jun 13, 2018

I'm running this with the following:

/usr/local/bin/mailhog \
  -api-bind-addr 78.157.123.28:8025 \
  -ui-bind-addr 78.157.123.28:8025 \
  -smtp-bind-addr 127.0.0.1:1025 \
  -auth-file=/etc/mailhog/auth.file

Authentication works for the UI but the websockets are unable to connect due to http auth and get a 401 error. Any advice?

If I disable the -auth-file then it all works.

@fabiofdsantos
Copy link

@tanc Try in Chrome.

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

No branches or pull requests