Skip to content

Move SMTP auth to the config file#308

Merged
fabxc merged 1 commit intoprometheus:masterfrom
mpchadwick:smtp-auth
Apr 16, 2016
Merged

Move SMTP auth to the config file#308
fabxc merged 1 commit intoprometheus:masterfrom
mpchadwick:smtp-auth

Conversation

@mpchadwick
Copy link
Contributor

@mpchadwick mpchadwick commented Apr 15, 2016

Implements enhancement proposed in #306.

Note: I have left support for environment variables as a fallback since we probably don't want people's alerts to break if they pull down master and don't move their credentials from env variables to the config file.

Edit: Environment variables are no longer supported

Documentation additionally updated to reflect the fact that the config file is the preferred place to store creds.

config/config.go Outdated
func smtpAuthParam(key string, gc *GlobalConfig) (string, Secret) {
// Try to pull it from the global config
globalKey := "SMTPAuth" + key
reflected := reflect.Indirect(reflect.ValueOf(gc))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is getting a bit magic, I think it'd be okay to just switch to config file for this.

@mpchadwick
Copy link
Contributor Author

@brian-brazil updated per your feedback. I can squash as needed if you're OK with this (all into 1 commit or into 2 commits, one for code changes and the other for documentation).

config/config.go Outdated
)

var patAuthLine = regexp.MustCompile(`((?:api_key|service_key|api_url|token|user_key):\s+)(".+"|'.+'|[^\s]+)`)
var patAuthLine = regexp.MustCompile(`((?:api_key|service_key|api_url|token|user_key|auth_password|auth_secret):\s+)(".+"|'.+'|[^\s]+)`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just making that password and secret will be enough. We are just so specific for key and url because it could be something normal.

@brian-brazil
Copy link
Contributor

That looks good, can you squash please?

To string `yaml:"to"`
From string `yaml:"from"`
Smarthost string `yaml:"smarthost,omitempty"`
AuthUsername string `yaml:"auth_username"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These all have the same prefix. Would it be worthwhile to move them into their own YAML block?

@fabxc
Copy link
Contributor

fabxc commented Apr 16, 2016

@mpchadwick Thanks a lot! Added two comments.

@mpchadwick
Copy link
Contributor Author

mpchadwick commented Apr 16, 2016

@brian-brazil @fabxc

Rebased to a single commit.

Just making that password and secret will be enough. We are just so specific for key and url because it could be something normal.

I updated the RegEx to be more loose. I agree that probably we'd always want to obscure anything matching these terms.

These all have the same prefix. Would it be worthwhile to move them into their own YAML block?

I guess it would be something like this?

global:
  # The smarthost and SMTP sender used for mail notifications.
  smtp_smarthost: 'localhost:25'
  smtp_from: 'alertmanager@example.org'
  smtp_auth:
  - username: 'alertmanager'
    password: 'password'  

I didn't address it because your comment was a question, but if you'd prefer that syntax I can.

@fabxc
Copy link
Contributor

fabxc commented Apr 16, 2016

Yes, that's what I had in mind. I would say grouping things together in a block is a good idea if you have a common prefix. We did it similar to TLS configs in Prometheus.

Of course any objections can be discussed.

@brian-brazil
Copy link
Contributor

For TLS there were 20-30 potential fields as things expand, there's only 4 here. I'd see this along the same lines as us not having an auth field in Prometheus for basic auth vs. token vs tls.

@fabxc
Copy link
Contributor

fabxc commented Apr 16, 2016

@brian-brazil
Copy link
Contributor

We have a basic_auth, a bearer_token and a bearer_token_file all of which are auth related. These are not however nested under an auth.

@fabxc
Copy link
Contributor

fabxc commented Apr 16, 2016

Ah, I see what you mean.
So it would be symmetric to put username and password in a separate block. However, don't see strong need in general. We can leave it as it is.

@brian-brazil
Copy link
Contributor

Yeah. There are a few other possible auth options, but if they come up (sound to be most likely in a full-Windows environment) we can refactor this a bit.

@fabxc
Copy link
Contributor

fabxc commented Apr 16, 2016

Okay. Thanks @mpchadwick 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants