albertito / chasquid

SMTP (email) server with a focus on simplicity, security, and ease of operation [mirror]

Home Page:https://blitiri.com.ar/p/chasquid/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

docker container won't restart due to dublicate hostname option in chasquid.conf

Jaywann opened this issue · comments

When the chasquid docker container is restarted, either manually or by docker, the entrypoint.sh echos the configuration option "hostname: < actual hostname >" into the chasquid.conf again resulting in:

Recreating chasquid ... done
Attaching to chasquid
chasquid      | _ chasquid.go:70     chasquid starting (version undefined)
chasquid      | ☠ chasquid.go:77     Error loading config: parsing config: proto: (line 28:1): non-repeated field "hostname" is repeated

this is simply due to this line in entrypoint.sh:

# Pick the default domain as default hostname for chasquid. This is only used
# in plain text sessions and on very rare cases, and it's mostly for aesthetic
# purposes.
echo "hostname: '$ONE_DOMAIN'" >> /etc/chasquid/chasquid.conf

This would be the simplest fix.

grep -iq 'hostname:' /etc/chasquid/chasquid.conf || echo "hostname: '$ONE_DOMAIN'" >> /etc/chasquid/chasquid.conf

Thanks a lot for finding and reporting this!

Would you mind giving commit 5305d58 a try? It's on the next branch, and is also included registry.gitlab.com/albertito/chasquid:next (since it is auto-built).

I've tested 5305d58 and it works a charm. I've also looked at the bash code a bit more. It seems that the hostname is taken from the certificates found under /configuration inside the container. I think this fix would require a complete remove of the container if only the certificate name changes, since the old certificate name would already exist in chasquid.conf and therefore not be updated.

I am however unaware if other parts of chasquid or the container scripts would require the deletion of the container anyways if the certificate name changes. If there is no other requirement I would propose the following change for the entrypoint.sh that also updates the hostname if it has changed.

CONF_FILE="/etc/chasquid/chasquid.conf"
if ! grep -iq "hostname: '$ONE_DOMAIN'" $CONF_FILE; then
        sed -i '/^hostname:/d' $CONF_FILE
        echo "hostname: '$ONE_DOMAIN'" >> $CONF_FILE
fi

Thank you for helping debug this and making chasquid better!

I think you're right, all the domain information is in the data volume (letsencrypt certs and /etc/chasquid/domains/), so it's possible a user removes a domain from both directories and then restarts the container without re-creating it.
Under those circumstances, the hostname: domain won't have a valid certificate. Thanks for finding this!

I like your suggested fix, although at this point I am more inclined to skip the conditional and always re-set it, so the flow is more direct:

sed -i '/^hostname:/d' /etc/chasquid/chasquid.conf
echo "hostname: '$ONE_DOMAIN'" >> /etc/chasquid/chasquid.conf

What do you think?

I absolutely agree with your point. This should solve the issue with no side effects and keeps the code clear and maintainable.