alertmanager icon indicating copy to clipboard operation
alertmanager copied to clipboard

Email client should attempt to use STARTTLS whenever its offered.

Open calvinmorrow opened this issue 11 years ago • 13 comments

Forgive the ignorance if this is untrue since I'm pretty unfamiliar with Go; my understanding from reading through manager/notifier.go is that AUTH appears to be sent to the server shortly after initial connection, and that STARTTLS follows after AUTH. (Host/Port information is extracted in the getSMTPAuth function to setup the tls config).

For both security reasons (especially with PLAIN authentication) as well as some providers mandating such, a STARTTLS command should be issued prior to AUTH. This would allow the password to have some reasonable level of protection during transmit and also fix issues with providers such as Gmail/Google that mandate STARTTLS prior to AUTH.

Currently using AlertManager with Gmail results in the following error: 530 5.7.0 Must issue a STARTTLS command first. gs7sm7571158pbc.6 - gsmtp

calvinmorrow avatar Jul 10 '15 05:07 calvinmorrow

Sounds reasonable to me, but I'm not knowledgeable about SMTP stuff.

/CC-ing the alertmanager's SMTP auth author, @logan - any opinions here?

juliusv avatar Jul 10 '15 06:07 juliusv

alertmanager should be issuing STARTTLS before AUTH, if you're configured to use PLAIN auth. Which environment variables are you setting?

logan avatar Jul 10 '15 19:07 logan

I'm setting SMTP_AUTH_USERNAME and SMTP_AUTH_PASSWORD.

calvinmorrow avatar Jul 10 '15 23:07 calvinmorrow

Can you confirm that you don't have SMTP_AUTH_SECRET set?

logan avatar Jul 10 '15 23:07 logan

Correct, I do not have SMTP_AUTH_SECRET set.

calvinmorrow avatar Jul 10 '15 23:07 calvinmorrow

In that case, maybe those environment variables aren't being exported to alertmanager?

The logic is around here: https://github.com/prometheus/alertmanager/blob/master/manager/notifier.go#L494

If those variables are set, and if the SMTP host supports PLAIN auth, then a *tls.Config should be returned. If you scroll down you'll see that that should trigger a STARTTLS.

Maybe you could try adding some debug output and run in your environment, to see for sure what's going on?

logan avatar Jul 11 '15 00:07 logan

I ran some tests and I have a better idea what's happening, but I really don't know why.

Both of the environment variables are being set correctly as follows:

[root@43458953000c alertmanager]# echo $SMTP_AUTH_USERNAME
[email protected]
[root@43458953000c alertmanager]# echo $SMTP_AUTH_PASSWORD
<snip>
[root@43458953000c alertmanager]# ./alertmanager -config.file=config/alertmanager.conf -notification.smtp.smarthost=gmail-smtp-msa.l.google.com:587  
alertmanager, version  ()
  build user:       
  build date:       
  go version:       
WARN[0000] Couldn't load silences, starting up with empty silence list: open silences.json: no such file or directory  file=main.go line=56
INFO[0000] Replacing aggregator rules (old: 0, new: 1)...  file=manager.go line=246
INFO[0000] Running notification dispatcher...            file=main.go line=127
INFO[0000] listening on :9093                            file=web.go line=78
INFO[0001] Recomputing notification outputs (active alerts have changed, inhibit rules have changed)  file=manager.go line=398
INFO[0348] Recomputing notification outputs (active alerts have changed)  file=manager.go line=398
INFO[0348] Sent 1 notifications                          file=manager.go line=353
ERRO[0348] Error sending email notification: 530 5.7.0 Must issue a STARTTLS command first. ks7sm18887821pbc.34 - gsmtp  file=notifier.go line=593
INFO[0349] Sent Slack notification: 11591738576348113040: HTTP 200: ok  file=notifier.go line=333

I ran a tcpdump looking at port 587 and got the following (ascii, cleaned up slightly) https://gist.github.com/calvinmorrow/27b7a4a162a0a52aecca

Looking it over I'm not seeing any obvious attempts to login at all.

Besides the two environment variables, is there anything else I need to provide to trigger PLAIN auth?

calvinmorrow avatar Jul 13 '15 15:07 calvinmorrow

It looks like gmail doesn't talk about its AUTH support until after the TLS negotiation. So we'll need a way to configure the notifier to use TLS unconditionally. (Which makes sense; who doesn't use TLS with SMTP?)

logan avatar Jul 13 '15 16:07 logan

I can imagine individuals behind a corporate firewall with their own mail server might eschew SMTP with TLS. I'm not saying that's a good practice, but I can see it happening.

That said, if STARTTLS is offered by the mail server, I think you'd want to use it under any circumstance, not necessarily just for AUTH.

calvinmorrow avatar Jul 13 '15 16:07 calvinmorrow

I agree, STARTTLS should be used always (but with a flag to disable it and/or certificate validation).

matthiasr avatar Jul 13 '15 16:07 matthiasr

I am facing the same issue: Error sending email notification: 530 5.7.0 Must issue a STARTTLS command first. h9sm9698689wjx.20

Is a fix or workaround available?

ghost avatar Sep 09 '15 11:09 ghost

PR #266 implements this, so I think this issue can be closed.

stapelberg avatar Apr 04 '16 06:04 stapelberg

I Think this answer would help you LINK

vedantjain0087 avatar Mar 03 '18 07:03 vedantjain0087