Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add username/password in Metricbeat autodiscover hints #15349

Merged
merged 6 commits into from
Jan 9, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions libbeat/autodiscover/builder/helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ func TestGenerateHints(t *testing.T) {
"co.elastic.metrics/module": "prometheus",
"co.elastic.metrics/period": "10s",
"co.elastic.metrics/metrics_path": "/metrics/prometheus",
"co.elastic.metrics/username": "user",
"co.elastic.metrics/password": "pass",
"co.elastic.metrics.foobar/period": "15s",
"co.elastic.metrics.foobar1/period": "15s",
"not.to.include": "true",
Expand All @@ -92,6 +94,8 @@ func TestGenerateHints(t *testing.T) {
"module": "prometheus",
"period": "15s",
"metrics_path": "/metrics/prometheus",
"username": "user",
"password": "pass",
},
},
},
Expand Down
18 changes: 18 additions & 0 deletions metricbeat/autodiscover/builder/hints/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ const (
timeout = "timeout"
ssl = "ssl"
metricspath = "metrics_path"
username = "username"
password = "password"

defaultTimeout = "3s"
defaultPeriod = "1m"
Expand Down Expand Up @@ -112,6 +114,8 @@ func (m *metricHints) CreateConfig(event bus.Event) []*common.Config {
sslConf := m.getSSLConfig(hints)
procs := m.getProcessors(hints)
metricspath := m.getMetricPath(hints)
username := m.getUsername(hints)
password := m.getPassword(hints)

moduleConfig := common.MapStr{
"module": mod,
Expand All @@ -130,6 +134,12 @@ func (m *metricHints) CreateConfig(event bus.Event) []*common.Config {
if metricspath != "" {
moduleConfig["metrics_path"] = metricspath
}
if username != "" {
moduleConfig["username"] = username
}
if password != "" {
moduleConfig["password"] = password
}

logp.Debug("hints.builder", "generated config: %v", moduleConfig.String())

Expand Down Expand Up @@ -198,6 +208,14 @@ func (m *metricHints) getMetricPath(hints common.MapStr) string {
return builder.GetHintString(hints, m.Key, metricspath)
}

func (m *metricHints) getUsername(hints common.MapStr) string {
return builder.GetHintString(hints, m.Key, username)
}

func (m *metricHints) getPassword(hints common.MapStr) string {
return builder.GetHintString(hints, m.Key, password)
}

func (m *metricHints) getPeriod(hints common.MapStr) string {
if ival := builder.GetHintString(hints, m.Key, period); ival != "" {
return ival
Expand Down
10 changes: 10 additions & 0 deletions metricbeat/docs/autodiscover-hints.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@ The time interval for metrics retrieval, ie: 10s

Metrics retrieval timeout, default: 3s

[float]
===== `co.elastic.metrics/username`

The username to use for authentication

[float]
===== `co.elastic.metrics/password`

The password to use for authentication
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should put a note here advising not to use plain text passwords here, but references to ENV vars in the Metricbeat container, or passwords stored in keystore. Long term I think we should implement a way to allow referencing passwords from k8s secrets


[float]
===== `co.elastic.metrics/ssl.*`

Expand Down