I have an unusual setup where I want to provide some authentication on the MailHog feature of DDEV-Local. How can I add basic authentication?
2 Answers
Since it turns out that MailHog supports basic auth and DDEV-Local provides the ability to add extra files into the container at build time, you can do this (updated for DDEV v1.19.0):
Add these four files to .ddev/web-build in your DDEV-Local project:
- mailhog.conf:
[program:mailhog]
command=/usr/local/bin/mailhog -auth-file=/etc/mailhog-auth.txt
autorestart=true
startretries=10
- mailhog-auth.txt:
test:$2a$04$qxRo.ftFoNep7ld/5jfKtuBTnGqff/fZVyj53mUC5sVf9dtDLAi/S
- Dockerfile:
ADD mailhog-auth.txt /etc
ADD mailhog.conf /etc/supervisor/conf.d
ADD healthcheck.sh /
- healthcheck.sh: (See gist - it's a little long to quote here.)
Now you can ddev start
and the mailhog auth with be "test":"test". The MailHog auth page gives more detail about how to generate a better password, and it will just go into mailhog-auth.txt.

- 9,963
- 1
- 47
- 89
As a followup to this issue, after an upgrade to DDEV v1.19.0 a project with basic auth configured for MailHog using the instructions listed here resulted in a project that would no longer spin up. It was only after finally deleting the entire DDEV setup for the project and systematically implementing one customization at a time that we finally isolated this as a problem. Needless to say, it was an afternoon wasted.
Not sure what changed with the web image for v1.19.0 but this solution, which was working fine in DDEV v1.18.2 now no longer works.
Leaving this for anyone else who may be wrestling with the same issue.

- 7
- 3
-
2Please don't give an answer that says "doesn't work". Instead, comment on the answer you don't have success with. – rfay Mar 16 '22 at 00:26
-
I edited the answer for v1.19, please delete this non-answer. I'm not sure how it could have worked before, as, because of the auth, the healthcheck was unable to connect to mailhog to check and see if it was running. – rfay Mar 16 '22 at 00:57
-
This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/31289471) – Gustavo Cesário Mar 21 '22 at 17:11