percona / mongodb_exporter

A Prometheus exporter for MongoDB including sharding, replication and storage engines
Apache License 2.0
1.19k stars 424 forks source link

Authentication using environment variables does not work #739

Closed vitali-zevako closed 12 months ago

vitali-zevako commented 1 year ago

Describe the bug Authentication using environment variables does not work

To Reproduce Steps to reproduce the behavior: Tried using both methods:

export MONGODB_USER=xxx
export MONGODB_PASSWORD=xxx
/usr/bin/mongodb_exporter --mongodb.uri=mongodb://localhost:27017 --collect-all
MONGODB_USER=xxx MONGODB_PASSWORD=xxx /usr/bin/mongodb_exporter --mongodb.uri=mongodb://localhost:27017 --collect-all

But it works if i run it as:

/usr/bin/mongodb_exporter --mongodb.uri=mongodb://<user>:<pwd>@localhost:27017 --collect-all

Expected behavior Auth via env vars should work

Logs

level=info ts=2023-10-31T08:18:48.285Z caller=tls_config.go:195 msg="TLS is disabled." http2=false
ERRO[0013] cannot run getDiagnosticData: (Unauthorized) command getDiagnosticData requires authentication
ERRO[0013] cannot run getDiagnosticData: response is empty
ERRO[0013] cannot decode getDiagnosticData: <nil> for data field: unexpected data type
ERRO[0013] cannot decode getCmdLineOtpions: cannot execute getCmdLineOpts command: (Unauthorized) command getCmdLineOpts requires authentication
ERRO[0013] Failed to get database names: cannot get the database names list: (Unauthorized) command listDatabases requires authentication
2023/10/31 08:19:01 http: panic serving 172.26.6.184:51733: descriptor Desc{fqName: "", help: "", constLabels: {}, variableLabels: []} is invalid: (Unauthorized) command top requires authentication
goroutine 39 [running]:
net/http.(*conn).serve.func1()
    /opt/hostedtoolcache/go/1.19.9/x64/src/net/http/server.go:1850 +0xb8
panic({0x6d3800, 0x40002ff3c0})
    /opt/hostedtoolcache/go/1.19.9/x64/src/runtime/panic.go:890 +0x260
github.com/prometheus/client_golang/prometheus.(*Registry).MustRegister(...)
    /home/runner/go/pkg/mod/github.com/!percona-!lab/client_golang@v1.12.2-0.20220701073455-ee06569fd6a5/prometheus/registry.go:403
github.com/percona/mongodb_exporter/exporter.(*Exporter).makeRegistry(0x400007fef0, {0x974de0?, 0x40002be660}, 0x40002ae4e0, {0x9725e8?, 0x40002d9cb0}, {{0x400014dc30, 0x1, 0x1}, 0x0, ...})
    /home/runner/work/mongodb_exporter/mongodb_exporter/exporter/exporter.go:214 +0xbfc
github.com/percona/mongodb_exporter/exporter.(*Exporter).Handler.func1({0x9744d0, 0x400026e540}, 0x400013b400)
    /home/runner/work/mongodb_exporter/mongodb_exporter/exporter/exporter.go:332 +0x418
net/http.HandlerFunc.ServeHTTP(0x400027bad8?, {0x9744d0?, 0x400026e540?}, 0x0?)
    /opt/hostedtoolcache/go/1.19.9/x64/src/net/http/server.go:2109 +0x38
net/http.(*ServeMux).ServeHTTP(0x0?, {0x9744d0, 0x400026e540}, 0x400013b400)
    /opt/hostedtoolcache/go/1.19.9/x64/src/net/http/server.go:2487 +0x140
net/http.serverHandler.ServeHTTP({0x400020d3e0?}, {0x9744d0, 0x400026e540}, 0x400013b400)
    /opt/hostedtoolcache/go/1.19.9/x64/src/net/http/server.go:2947 +0x2cc
net/http.(*conn).serve(0x400019bc20, {0x974e18, 0x40001afc80})
    /opt/hostedtoolcache/go/1.19.9/x64/src/net/http/server.go:1991 +0x544
created by net/http.(*Server).Serve
    /opt/hostedtoolcache/go/1.19.9/x64/src/net/http/server.go:3102 +0x43c
ERRO[0013] cannot run getDiagnosticData: (Unauthorized) command getDiagnosticData requires authentication
ERRO[0013] cannot run getDiagnosticData: response is empty
ERRO[0013] cannot decode getDiagnosticData: <nil> for data field: unexpected data type
ERRO[0013] cannot decode getCmdLineOtpions: cannot execute getCmdLineOpts command: (Unauthorized) command getCmdLineOpts requires authentication
ERRO[0013] Failed to get database names: cannot get the database names list: (Unauthorized) command listDatabases requires authentication
2023/10/31 08:19:02 http: panic serving 172.26.6.184:51734: descriptor Desc{fqName: "", help: "", constLabels: {}, variableLabels: []} is invalid: (Unauthorized) command top requires authentication
goroutine 94 [running]:
net/http.(*conn).serve.func1()
    /opt/hostedtoolcache/go/1.19.9/x64/src/net/http/server.go:1850 +0xb8
panic({0x6d3800, 0x4000428990})
    /opt/hostedtoolcache/go/1.19.9/x64/src/runtime/panic.go:890 +0x260
github.com/prometheus/client_golang/prometheus.(*Registry).MustRegister(...)
    /home/runner/go/pkg/mod/github.com/!percona-!lab/client_golang@v1.12.2-0.20220701073455-ee06569fd6a5/prometheus/registry.go:403
github.com/percona/mongodb_exporter/exporter.(*Exporter).makeRegistry(0x400007fef0, {0x974de0?, 0x40003d2840}, 0x40002afad0, {0x9725e8?, 0x4000290ae0}, {{0x400014dc30, 0x1, 0x1}, 0x0, ...})
    /home/runner/work/mongodb_exporter/mongodb_exporter/exporter/exporter.go:214 +0xbfc
github.com/percona/mongodb_exporter/exporter.(*Exporter).Handler.func1({0x9744d0, 0x400026e9a0}, 0x400013b200)
    /home/runner/work/mongodb_exporter/mongodb_exporter/exporter/exporter.go:332 +0x418
net/http.HandlerFunc.ServeHTTP(0x4000072ad8?, {0x9744d0?, 0x400026e9a0?}, 0x0?)
    /opt/hostedtoolcache/go/1.19.9/x64/src/net/http/server.go:2109 +0x38
net/http.(*ServeMux).ServeHTTP(0x0?, {0x9744d0, 0x400026e9a0}, 0x400013b200)
    /opt/hostedtoolcache/go/1.19.9/x64/src/net/http/server.go:2487 +0x140
net/http.serverHandler.ServeHTTP({0x40002d84b0?}, {0x9744d0, 0x400026e9a0}, 0x400013b200)
    /opt/hostedtoolcache/go/1.19.9/x64/src/net/http/server.go:2947 +0x2cc
net/http.(*conn).serve(0x40002840a0, {0x974e18, 0x40001afc80})
    /opt/hostedtoolcache/go/1.19.9/x64/src/net/http/server.go:1991 +0x544
created by net/http.(*Server).Serve
    /opt/hostedtoolcache/go/1.19.9/x64/src/net/http/server.go:3102 +0x43c
ERRO[0014] cannot run getDiagnosticData: (Unauthorized) command getDiagnosticData requires authentication
ERRO[0014] cannot run getDiagnosticData: response is empty
ERRO[0014] cannot decode getDiagnosticData: <nil> for data field: unexpected data type
ERRO[0014] cannot decode getCmdLineOtpions: cannot execute getCmdLineOpts command: (Unauthorized) command getCmdLineOpts requires authentication
ERRO[0014] Failed to get database names: cannot get the database names list: (Unauthorized) command listDatabases requires authentication
2023/10/31 08:19:02 http: panic serving 172.26.6.184:51735: descriptor Desc{fqName: "", help: "", constLabels: {}, variableLabels: []} is invalid: (Unauthorized) command top requires authentication
goroutine 95 [running]:
net/http.(*conn).serve.func1()
    /opt/hostedtoolcache/go/1.19.9/x64/src/net/http/server.go:1850 +0xb8
panic({0x6d3800, 0x4000429540})
    /opt/hostedtoolcache/go/1.19.9/x64/src/runtime/panic.go:890 +0x260
github.com/prometheus/client_golang/prometheus.(*Registry).MustRegister(...)
    /home/runner/go/pkg/mod/github.com/!percona-!lab/client_golang@v1.12.2-0.20220701073455-ee06569fd6a5/prometheus/registry.go:403
github.com/percona/mongodb_exporter/exporter.(*Exporter).makeRegistry(0x400007fef0, {0x974de0?, 0x400006c1e0}, 0x40000908f0, {0x9725e8?, 0x4000467440}, {{0x400014dc30, 0x1, 0x1}, 0x0, ...})
    /home/runner/work/mongodb_exporter/mongodb_exporter/exporter/exporter.go:214 +0xbfc
github.com/percona/mongodb_exporter/exporter.(*Exporter).Handler.func1({0x9744d0, 0x400026e0e0}, 0x400013b300)
    /home/runner/work/mongodb_exporter/mongodb_exporter/exporter/exporter.go:332 +0x418
net/http.HandlerFunc.ServeHTTP(0x4000073ad8?, {0x9744d0?, 0x400026e0e0?}, 0x0?)
    /opt/hostedtoolcache/go/1.19.9/x64/src/net/http/server.go:2109 +0x38
net/http.(*ServeMux).ServeHTTP(0x0?, {0x9744d0, 0x400026e0e0}, 0x400013b300)
    /opt/hostedtoolcache/go/1.19.9/x64/src/net/http/server.go:2487 +0x140
net/http.serverHandler.ServeHTTP({0x40002d85a0?}, {0x9744d0, 0x400026e0e0}, 0x400013b300)
    /opt/hostedtoolcache/go/1.19.9/x64/src/net/http/server.go:2947 +0x2cc
net/http.(*conn).serve(0x4000284140, {0x974e18, 0x40001afc80})
    /opt/hostedtoolcache/go/1.19.9/x64/src/net/http/server.go:1991 +0x544
created by net/http.(*Server).Serve
    /opt/hostedtoolcache/go/1.19.9/x64/src/net/http/server.go:3102 +0x43c
ERRO[0014] cannot run getDiagnosticData: (Unauthorized) command getDiagnosticData requires authentication
ERRO[0014] cannot run getDiagnosticData: response is empty
ERRO[0014] cannot decode getDiagnosticData: <nil> for data field: unexpected data type
ERRO[0014] cannot decode getCmdLineOtpions: cannot execute getCmdLineOpts command: (Unauthorized) command getCmdLineOpts requires authentication
ERRO[0014] Failed to get database names: cannot get the database names list: (Unauthorized) command listDatabases requires authentication
2023/10/31 08:19:03 http: panic serving 172.26.6.184:51737: descriptor Desc{fqName: "", help: "", constLabels: {}, variableLabels: []} is invalid: (Unauthorized) command top requires authentication
goroutine 308 [running]:
net/http.(*conn).serve.func1()
    /opt/hostedtoolcache/go/1.19.9/x64/src/net/http/server.go:1850 +0xb8
panic({0x6d3800, 0x400014c9f0})
    /opt/hostedtoolcache/go/1.19.9/x64/src/runtime/panic.go:890 +0x260
github.com/prometheus/client_golang/prometheus.(*Registry).MustRegister(...)
    /home/runner/go/pkg/mod/github.com/!percona-!lab/client_golang@v1.12.2-0.20220701073455-ee06569fd6a5/prometheus/registry.go:403
github.com/percona/mongodb_exporter/exporter.(*Exporter).makeRegistry(0x400007fef0, {0x974de0?, 0x400025d6e0}, 0x400017cea0, {0x9725e8?, 0x400020c540}, {{0x400014dc30, 0x1, 0x1}, 0x0, ...})
    /home/runner/work/mongodb_exporter/mongodb_exporter/exporter/exporter.go:214 +0xbfc
github.com/percona/mongodb_exporter/exporter.(*Exporter).Handler.func1({0x9744d0, 0x400026e620}, 0x400013a100)
    /home/runner/work/mongodb_exporter/mongodb_exporter/exporter/exporter.go:332 +0x418
net/http.HandlerFunc.ServeHTTP(0x400006fad8?, {0x9744d0?, 0x400026e620?}, 0x0?)
    /opt/hostedtoolcache/go/1.19.9/x64/src/net/http/server.go:2109 +0x38
net/http.(*ServeMux).ServeHTTP(0x0?, {0x9744d0, 0x400026e620}, 0x400013a100)
    /opt/hostedtoolcache/go/1.19.9/x64/src/net/http/server.go:2487 +0x140
net/http.serverHandler.ServeHTTP({0x40001aeae0?}, {0x9744d0, 0x400026e620}, 0x400013a100)
    /opt/hostedtoolcache/go/1.19.9/x64/src/net/http/server.go:2947 +0x2cc
net/http.(*conn).serve(0x40002845a0, {0x974e18, 0x40001afc80})
    /opt/hostedtoolcache/go/1.19.9/x64/src/net/http/server.go:1991 +0x544
created by net/http.(*Server).Serve
    /opt/hostedtoolcache/go/1.19.9/x64/src/net/http/server.go:3102 +0x43c
ERRO[0016] cannot run getDiagnosticData: (Unauthorized) command getDiagnosticData requires authentication
ERRO[0016] cannot run getDiagnosticData: response is empty
ERRO[0016] cannot decode getDiagnosticData: <nil> for data field: unexpected data type
ERRO[0016] cannot decode getCmdLineOtpions: cannot execute getCmdLineOpts command: (Unauthorized) command getCmdLineOpts requires authentication
ERRO[0016] Failed to get database names: cannot get the database names list: (Unauthorized) command listDatabases requires authentication
2023/10/31 08:19:04 http: panic serving 172.26.6.184:51738: descriptor Desc{fqName: "", help: "", constLabels: {}, variableLabels: []} is invalid: (Unauthorized) command top requires authentication
goroutine 378 [running]:
net/http.(*conn).serve.func1()
    /opt/hostedtoolcache/go/1.19.9/x64/src/net/http/server.go:1850 +0xb8
panic({0x6d3800, 0x400020a830})
    /opt/hostedtoolcache/go/1.19.9/x64/src/runtime/panic.go:890 +0x260
github.com/prometheus/client_golang/prometheus.(*Registry).MustRegister(...)
    /home/runner/go/pkg/mod/github.com/!percona-!lab/client_golang@v1.12.2-0.20220701073455-ee06569fd6a5/prometheus/registry.go:403
github.com/percona/mongodb_exporter/exporter.(*Exporter).makeRegistry(0x400007fef0, {0x974de0?, 0x40002bf9e0}, 0x40001d2680, {0x9725e8?, 0x4000287860}, {{0x400014dc30, 0x1, 0x1}, 0x0, ...})
    /home/runner/work/mongodb_exporter/mongodb_exporter/exporter/exporter.go:214 +0xbfc
github.com/percona/mongodb_exporter/exporter.(*Exporter).Handler.func1({0x9744d0, 0x400026eb60}, 0x400013a300)
    /home/runner/work/mongodb_exporter/mongodb_exporter/exporter/exporter.go:332 +0x418
net/http.HandlerFunc.ServeHTTP(0x4000072ad8?, {0x9744d0?, 0x400026eb60?}, 0x0?)
    /opt/hostedtoolcache/go/1.19.9/x64/src/net/http/server.go:2109 +0x38
net/http.(*ServeMux).ServeHTTP(0x0?, {0x9744d0, 0x400026eb60}, 0x400013a300)
    /opt/hostedtoolcache/go/1.19.9/x64/src/net/http/server.go:2487 +0x140
net/http.serverHandler.ServeHTTP({0x4000286300?}, {0x9744d0, 0x400026eb60}, 0x400013a300)
    /opt/hostedtoolcache/go/1.19.9/x64/src/net/http/server.go:2947 +0x2cc
net/http.(*conn).serve(0x4000284a00, {0x974e18, 0x40001afc80})
    /opt/hostedtoolcache/go/1.19.9/x64/src/net/http/server.go:1991 +0x544
created by net/http.(*Server).Serve
    /opt/hostedtoolcache/go/1.19.9/x64/src/net/http/server.go:3102 +0x43c
ERRO[0016] cannot run getDiagnosticData: (Unauthorized) command getDiagnosticData requires authentication
ERRO[0016] cannot run getDiagnosticData: response is empty
ERRO[0016] cannot decode getDiagnosticData: <nil> for data field: unexpected data type
ERRO[0016] cannot decode getCmdLineOtpions: cannot execute getCmdLineOpts command: (Unauthorized) command getCmdLineOpts requires authentication
ERRO[0016] Failed to get database names: cannot get the database names list: (Unauthorized) command listDatabases requires authentication
2023/10/31 08:19:04 http: panic serving 172.26.6.184:51739: descriptor Desc{fqName: "", help: "", constLabels: {}, variableLabels: []} is invalid: (Unauthorized) command top requires authentication
goroutine 448 [running]:
net/http.(*conn).serve.func1()
    /opt/hostedtoolcache/go/1.19.9/x64/src/net/http/server.go:1850 +0xb8
panic({0x6d3800, 0x400020bed0})
    /opt/hostedtoolcache/go/1.19.9/x64/src/runtime/panic.go:890 +0x260
github.com/prometheus/client_golang/prometheus.(*Registry).MustRegister(...)
    /home/runner/go/pkg/mod/github.com/!percona-!lab/client_golang@v1.12.2-0.20220701073455-ee06569fd6a5/prometheus/registry.go:403
github.com/percona/mongodb_exporter/exporter.(*Exporter).makeRegistry(0x400007fef0, {0x974de0?, 0x400014fbc0}, 0x40002ae0d0, {0x9725e8?, 0x40003bca80}, {{0x400014dc30, 0x1, 0x1}, 0x0, ...})
    /home/runner/work/mongodb_exporter/mongodb_exporter/exporter/exporter.go:214 +0xbfc
github.com/percona/mongodb_exporter/exporter.(*Exporter).Handler.func1({0x9744d0, 0x400026efc0}, 0x400013a600)
    /home/runner/work/mongodb_exporter/mongodb_exporter/exporter/exporter.go:332 +0x418
net/http.HandlerFunc.ServeHTTP(0x4000074ad8?, {0x9744d0?, 0x400026efc0?}, 0x0?)
    /opt/hostedtoolcache/go/1.19.9/x64/src/net/http/server.go:2109 +0x38
net/http.(*ServeMux).ServeHTTP(0x0?, {0x9744d0, 0x400026efc0}, 0x400013a600)
    /opt/hostedtoolcache/go/1.19.9/x64/src/net/http/server.go:2487 +0x140
net/http.serverHandler.ServeHTTP({0x40002d9620?}, {0x9744d0, 0x400026efc0}, 0x400013a600)
    /opt/hostedtoolcache/go/1.19.9/x64/src/net/http/server.go:2947 +0x2cc
net/http.(*conn).serve(0x4000284e60, {0x974e18, 0x40001afc80})
    /opt/hostedtoolcache/go/1.19.9/x64/src/net/http/server.go:1991 +0x544
created by net/http.(*Server).Serve
    /opt/hostedtoolcache/go/1.19.9/x64/src/net/http/server.go:3102 +0x43c
ERRO[0022] cannot run getDiagnosticData: (Unauthorized) command getDiagnosticData requires authentication
ERRO[0022] cannot run getDiagnosticData: response is empty
ERRO[0022] cannot decode getDiagnosticData: <nil> for data field: unexpected data type
ERRO[0022] cannot decode getCmdLineOtpions: cannot execute getCmdLineOpts command: (Unauthorized) command getCmdLineOpts requires authentication
ERRO[0022] Failed to get database names: cannot get the database names list: (Unauthorized) command listDatabases requires authentication
2023/10/31 08:19:10 http: panic serving 172.26.6.184:51741: descriptor Desc{fqName: "", help: "", constLabels: {}, variableLabels: []} is invalid: (Unauthorized) command top requires authentication
goroutine 521 [running]:
net/http.(*conn).serve.func1()
    /opt/hostedtoolcache/go/1.19.9/x64/src/net/http/server.go:1850 +0xb8
panic({0x6d3800, 0x40002ff5a0})
    /opt/hostedtoolcache/go/1.19.9/x64/src/runtime/panic.go:890 +0x260
github.com/prometheus/client_golang/prometheus.(*Registry).MustRegister(...)
    /home/runner/go/pkg/mod/github.com/!percona-!lab/client_golang@v1.12.2-0.20220701073455-ee06569fd6a5/prometheus/registry.go:403
github.com/percona/mongodb_exporter/exporter.(*Exporter).makeRegistry(0x400007fef0, {0x974de0?, 0x400024ff20}, 0x40002af860, {0x9725e8?, 0x40003fdcb0}, {{0x400014dc30, 0x1, 0x1}, 0x0, ...})
    /home/runner/work/mongodb_exporter/mongodb_exporter/exporter/exporter.go:214 +0xbfc
github.com/percona/mongodb_exporter/exporter.(*Exporter).Handler.func1({0x9744d0, 0x400026f420}, 0x400013a800)
    /home/runner/work/mongodb_exporter/mongodb_exporter/exporter/exporter.go:332 +0x418
net/http.HandlerFunc.ServeHTTP(0x4000070ad8?, {0x9744d0?, 0x400026f420?}, 0x0?)
    /opt/hostedtoolcache/go/1.19.9/x64/src/net/http/server.go:2109 +0x38
net/http.(*ServeMux).ServeHTTP(0x0?, {0x9744d0, 0x400026f420}, 0x400013a800)
    /opt/hostedtoolcache/go/1.19.9/x64/src/net/http/server.go:2487 +0x140
net/http.serverHandler.ServeHTTP({0x40003fc7b0?}, {0x9744d0, 0x400026f420}, 0x400013a800)
    /opt/hostedtoolcache/go/1.19.9/x64/src/net/http/server.go:2947 +0x2cc
net/http.(*conn).serve(0x4000285400, {0x974e18, 0x40001afc80})
    /opt/hostedtoolcache/go/1.19.9/x64/src/net/http/server.go:1991 +0x544
created by net/http.(*Server).Serve
    /opt/hostedtoolcache/go/1.19.9/x64/src/net/http/server.go:3102 +0x43c

Environment

BupycHuk commented 12 months ago

Hello @vitali-zevako these new env variables were introduced recently and supported starting 0.40.0, please re-check with newer version.

mayankPratap-spec commented 2 months ago

Its not working for me even in 0.40.0, when i hardcode in the connection string, it works.