[GH-ISSUE #281] Failure to start using environment variables #186

Closed
opened 2026-03-15 13:05:13 +03:00 by kerem · 3 comments
Owner

Originally created by @jreydep on GitHub (Apr 20, 2024).
Original GitHub issue: https://github.com/axllent/mailpit/issues/281

I am trying to make a enviroment file when Mailpit is being started as service and I can use any variable inside without problem, but the moment I put in a certificate the start fails. The same env configuration but passed through flags works perfectly.

I no longer know if I am doing something wrong or if there is something in the file that is wrong. This is part of the file I have in "/etc/systemd/system/mailpit.service.d/override.conf"

[Service]
# TLS certificate for SMTP SSL/TLS. This option requires the MP_SMTP_TLS_KEY
# environment variable to be set too.
# @see https://mailpit.axllent.org/docs/configuration/certificates/
Environment="MP_SMTP_TLS_CERT=/etc/ssl/certs/ssl-cert-snakeoil.pem"
Environment="MP_SMTP_TLS_KEY=/etc/ssl/private/ssl-cert-snakeoil.key"

# Require all SMTP clients to use SSL/TLS encryption. If set to true, all
# connections to the SMTP server must be handled over TLS. This is different to
# STARTTLS which requires the initial connection to be unencrypted.
# Note that this option disables STARTTLS and may reduce client compatibility.
Environment="MP_SMTP_REQUIRE_TLS=true"
journalctl -u mailpit.service -n 40

Apr 20 21:49:02 Gaspar systemd[1]: Started mailpit.service - Mailpit is a small, fast, low memory, zero-dependency, multi-platform email testing tool and API for developers..
Apr 20 21:49:02 Gaspar mailpit[7084]: panic: runtime error: invalid memory address or nil pointer dereference
Apr 20 21:49:02 Gaspar mailpit[7084]: [signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x7d73ae]
Apr 20 21:49:02 Gaspar mailpit[7084]: goroutine 1 [running]:
Apr 20 21:49:02 Gaspar mailpit[7084]: github.com/axllent/mailpit/config.isFile({0xc00002e050?, 0x26?})
Apr 20 21:49:02 Gaspar mailpit[7084]:         /github/workspace/config/config.go:503 +0x4e
Apr 20 21:49:02 Gaspar mailpit[7084]: github.com/axllent/mailpit/config.VerifyConfig()
Apr 20 21:49:02 Gaspar mailpit[7084]:         /github/workspace/config/config.go:307 +0x8ed
Apr 20 21:49:02 Gaspar mailpit[7084]: github.com/axllent/mailpit/cmd.init.func3(0xc000024f00?, {0xccd40f?, 0x4?, 0xccd40b?})
Apr 20 21:49:02 Gaspar mailpit[7084]:         /github/workspace/cmd/root.go:34 +0x17
Apr 20 21:49:02 Gaspar mailpit[7084]: github.com/spf13/cobra.(*Command).execute(0x166f2c0, {0xc000022190, 0x0, 0x0})
Apr 20 21:49:02 Gaspar mailpit[7084]:         /go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:987 +0xab1
Apr 20 21:49:02 Gaspar mailpit[7084]: github.com/spf13/cobra.(*Command).ExecuteC(0x166f2c0)
Apr 20 21:49:02 Gaspar mailpit[7084]:         /go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:1115 +0x3ff
Apr 20 21:49:02 Gaspar mailpit[7084]: github.com/spf13/cobra.(*Command).Execute(...)
Apr 20 21:49:02 Gaspar mailpit[7084]:         /go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:1039
Apr 20 21:49:02 Gaspar mailpit[7084]: github.com/axllent/mailpit/cmd.Execute()
Apr 20 21:49:02 Gaspar mailpit[7084]:         /github/workspace/cmd/root.go:55 +0x1a
Apr 20 21:49:02 Gaspar mailpit[7084]: main.main()
Apr 20 21:49:02 Gaspar mailpit[7084]:         /github/workspace/main.go:20 +0x85
Apr 20 21:49:02 Gaspar systemd[1]: mailpit.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
Apr 20 21:49:02 Gaspar systemd[1]: mailpit.service: Failed with result 'exit-code'.
Originally created by @jreydep on GitHub (Apr 20, 2024). Original GitHub issue: https://github.com/axllent/mailpit/issues/281 I am trying to make a enviroment file when Mailpit is being started as service and I can use any variable inside without problem, but the moment I put in a certificate the start fails. The same env configuration but passed through flags works perfectly. I no longer know if I am doing something wrong or if there is something in the file that is wrong. This is part of the file I have in "/etc/systemd/system/mailpit.service.d/override.conf" ``` [Service] # TLS certificate for SMTP SSL/TLS. This option requires the MP_SMTP_TLS_KEY # environment variable to be set too. # @see https://mailpit.axllent.org/docs/configuration/certificates/ Environment="MP_SMTP_TLS_CERT=/etc/ssl/certs/ssl-cert-snakeoil.pem" Environment="MP_SMTP_TLS_KEY=/etc/ssl/private/ssl-cert-snakeoil.key" # Require all SMTP clients to use SSL/TLS encryption. If set to true, all # connections to the SMTP server must be handled over TLS. This is different to # STARTTLS which requires the initial connection to be unencrypted. # Note that this option disables STARTTLS and may reduce client compatibility. Environment="MP_SMTP_REQUIRE_TLS=true" ``` ``` journalctl -u mailpit.service -n 40 Apr 20 21:49:02 Gaspar systemd[1]: Started mailpit.service - Mailpit is a small, fast, low memory, zero-dependency, multi-platform email testing tool and API for developers.. Apr 20 21:49:02 Gaspar mailpit[7084]: panic: runtime error: invalid memory address or nil pointer dereference Apr 20 21:49:02 Gaspar mailpit[7084]: [signal SIGSEGV: segmentation violation code=0x1 addr=0x28 pc=0x7d73ae] Apr 20 21:49:02 Gaspar mailpit[7084]: goroutine 1 [running]: Apr 20 21:49:02 Gaspar mailpit[7084]: github.com/axllent/mailpit/config.isFile({0xc00002e050?, 0x26?}) Apr 20 21:49:02 Gaspar mailpit[7084]: /github/workspace/config/config.go:503 +0x4e Apr 20 21:49:02 Gaspar mailpit[7084]: github.com/axllent/mailpit/config.VerifyConfig() Apr 20 21:49:02 Gaspar mailpit[7084]: /github/workspace/config/config.go:307 +0x8ed Apr 20 21:49:02 Gaspar mailpit[7084]: github.com/axllent/mailpit/cmd.init.func3(0xc000024f00?, {0xccd40f?, 0x4?, 0xccd40b?}) Apr 20 21:49:02 Gaspar mailpit[7084]: /github/workspace/cmd/root.go:34 +0x17 Apr 20 21:49:02 Gaspar mailpit[7084]: github.com/spf13/cobra.(*Command).execute(0x166f2c0, {0xc000022190, 0x0, 0x0}) Apr 20 21:49:02 Gaspar mailpit[7084]: /go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:987 +0xab1 Apr 20 21:49:02 Gaspar mailpit[7084]: github.com/spf13/cobra.(*Command).ExecuteC(0x166f2c0) Apr 20 21:49:02 Gaspar mailpit[7084]: /go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:1115 +0x3ff Apr 20 21:49:02 Gaspar mailpit[7084]: github.com/spf13/cobra.(*Command).Execute(...) Apr 20 21:49:02 Gaspar mailpit[7084]: /go/pkg/mod/github.com/spf13/cobra@v1.8.0/command.go:1039 Apr 20 21:49:02 Gaspar mailpit[7084]: github.com/axllent/mailpit/cmd.Execute() Apr 20 21:49:02 Gaspar mailpit[7084]: /github/workspace/cmd/root.go:55 +0x1a Apr 20 21:49:02 Gaspar mailpit[7084]: main.main() Apr 20 21:49:02 Gaspar mailpit[7084]: /github/workspace/main.go:20 +0x85 Apr 20 21:49:02 Gaspar systemd[1]: mailpit.service: Main process exited, code=exited, status=2/INVALIDARGUMENT Apr 20 21:49:02 Gaspar systemd[1]: mailpit.service: Failed with result 'exit-code'. ```
kerem closed this issue 2026-03-15 13:05:18 +03:00
Author
Owner

@axllent commented on GitHub (Apr 20, 2024):

@jreydep I think I can see what is going on here - are you starting Mailpit via systemd as a non-privileged user (ie: not root), but are testing manually with the same environment variables as root? In your example, /etc/ssl/private/ssl-cert-snakeoil.key is only readable as root.

Can you please confirm this for me?

<!-- gh-comment-id:2067781924 --> @axllent commented on GitHub (Apr 20, 2024): @jreydep I think I can see what is going on here - are you starting Mailpit via systemd as a non-privileged user (ie: not root), but are testing manually with the same environment variables as root? In your example, `/etc/ssl/private/ssl-cert-snakeoil.key` is only readable as root. Can you please confirm this for me?
Author
Owner

@jreydep commented on GitHub (Apr 20, 2024):

Yes, that was the problem... another case of rubber duck. I started thinking the same thing a while ago and when in the .service I changed the user to root and it worked, I realized the permissions issue.

Sorry to respond late, I had taken the opportunity to have dinner and regain my mental health. Changing User and Group from mailpit to root allows the script to start without problems.

Description=Mailpit is a small, fast, low memory, zero-dependency, multi-platform email testing tool and API for developers.

[Service]
ExecStart=/usr/local/bin/mailpit
Restart=always
RestartSec=10
SyslogIdentifier=mailpit
User=root
Group=root

[Install]
WantedBy=multi-user.target
<!-- gh-comment-id:2067810786 --> @jreydep commented on GitHub (Apr 20, 2024): Yes, that was the problem... another case of _rubber duck_. I started thinking the same thing a while ago and when in the .service I changed the user to root and it worked, I realized the permissions issue. Sorry to respond late, I had taken the opportunity to have dinner and regain my mental health. Changing User and Group from mailpit to root allows the script to start without problems. ```[Unit] Description=Mailpit is a small, fast, low memory, zero-dependency, multi-platform email testing tool and API for developers. [Service] ExecStart=/usr/local/bin/mailpit Restart=always RestartSec=10 SyslogIdentifier=mailpit User=root Group=root [Install] WantedBy=multi-user.target ```
Author
Owner

@axllent commented on GitHub (Apr 20, 2024):

Glad to hear you found the cause. Just to clarify, you can easily run Mailpit as an unprivileged user provided:

  1. Your user has read/write permissions to the directory and database file where the data is stored
  2. Your user has access to all other files referenced in the startup options (eg: TLS certificates & config files etc)
  3. you are not explicitly running any of the smtp/http/pop3 ports < 1024

I've made a code change to help users understand the permissions issue you faced (rather than a complicated "panic" message) - which will make it's way into the next release. It will basically display a human-friendly manner that the file does not exist or they don't have permission to read it.

<!-- gh-comment-id:2067815092 --> @axllent commented on GitHub (Apr 20, 2024): Glad to hear you found the cause. Just to clarify, you can easily run Mailpit as an unprivileged user provided: 1. Your user has read/write permissions to the directory and database file where the data is stored 2. Your user has access to all other files referenced in the startup options (eg: TLS certificates & config files etc) 3. you are not explicitly running any of the smtp/http/pop3 ports < 1024 I've made a code change to help users understand the permissions issue you faced (rather than a complicated "panic" message) - which will make it's way into the next release. It will basically display a human-friendly manner that the file does not exist or they don't have permission to read it.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/mailpit#186
No description provided.