Skip to content

Commit 80e25fa

Browse files
authored
Merge pull request #461 from guillaumelecerf/feature/support-username-password
Allow to specify ES_USERNAME/ES_PASSWORD environment variables to connect to the ES node
2 parents 845aff6 + fa71388 commit 80e25fa

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ by replacing `.` and `-` with `_` and upper-casing the parameter name.
6868

6969
#### Elasticsearch 7.x security privileges
7070

71+
Username and password can be passed either directly in the URI or through the `ES_USERNAME` and `ES_PASSWORD` environment variables.
72+
Specifying those two environment variables will override authentication passed in the URI (if any).
73+
7174
ES 7.x supports RBACs. The following security privileges are required for the elasticsearch_exporter.
7275

7376
Setting | Privilege Required | Description

main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,13 @@ func main() {
125125
os.Exit(1)
126126
}
127127

128+
esUsername := os.Getenv("ES_USERNAME")
129+
esPassword := os.Getenv("ES_PASSWORD")
130+
131+
if esUsername != "" && esPassword != "" {
132+
esURL.User = url.UserPassword(esUsername, esPassword)
133+
}
134+
128135
// returns nil if not provided and falls back to simple TCP.
129136
tlsConfig := createTLSConfig(*esCA, *esClientCert, *esClientPrivateKey, *esInsecureSkipVerify)
130137

0 commit comments

Comments
 (0)