ddevobsolete

How can I add basic authentication to the MailHog service in DDEV


I have an unusual setup where I want to provide some authentication on the MailHog feature of DDEV. How can I add basic authentication?


Solution

  • Note that this question/answer are obsolete because DDEV now uses Mailpit instead at least since v1.23.0. You'll want to look at the instructions there to find a parallel approach.

    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:

    1. mailhog.conf:
    [program:mailhog]
    command=/usr/local/bin/mailhog -auth-file=/etc/mailhog-auth.txt
    autorestart=true
    startretries=10
    
    1. mailhog-auth.txt:
    test:$2a$04$qxRo.ftFoNep7ld/5jfKtuBTnGqff/fZVyj53mUC5sVf9dtDLAi/S
    
    1. Dockerfile:
    ADD mailhog-auth.txt /etc
    ADD mailhog.conf /etc/supervisor/conf.d
    ADD healthcheck.sh /
    
    1. 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.