Skip to content

Commit fa71388

Browse files
Allow to specify ES_USERNAME/ES_PASSWORD environment variables to connect to the ES node
Signed-off-by: Guillaume Lecerf <[email protected]>
1 parent 3d6277d commit fa71388

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
@@ -67,6 +67,9 @@ by replacing `.` and `-` with `_` and upper-casing the parameter name.
6767

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

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

7275
Setting | Privilege Required | Description

main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,13 @@ func main() {
111111
os.Exit(1)
112112
}
113113

114+
esUsername := os.Getenv("ES_USERNAME")
115+
esPassword := os.Getenv("ES_PASSWORD")
116+
117+
if esUsername != "" && esPassword != "" {
118+
esURL.User = url.UserPassword(esUsername, esPassword)
119+
}
120+
114121
// returns nil if not provided and falls back to simple TCP.
115122
tlsConfig := createTLSConfig(*esCA, *esClientCert, *esClientPrivateKey, *esInsecureSkipVerify)
116123

0 commit comments

Comments
 (0)