pgbouncer_exporter icon indicating copy to clipboard operation
pgbouncer_exporter copied to clipboard

Support environment variables for credentials

Open jsirianni opened this issue 1 year ago • 5 comments

Would it be possible to support environment variables for the exporter's configuration?

I intend to use this exporter with Kubernetes, right now I need to do something like this:

        - name: metrics-exporter
          image: prometheuscommunity/pgbouncer-exporter:v0.7.0
          args:
            - --pgBouncer.connectionString=postgres://pgbouncer:pgbouncer@localhost:5432/pgbouncer
            - --web.listen-address=:9127

It is more ideal to use environment variables as they can be derived from pre configured secrets.

        - name: metrics-exporter
          image: prometheuscommunity/pgbouncer-exporter:v0.7.0
          args:
            - --web.listen-address=:9127
          env:
            - name: PGBOUNCER_CONNECTION_STRING
              valueFrom:
                secretKeyRef:
                  name: pgbouncer-connection-string

This way, the configuration can be safely committed to a Git repo, and the secret can be managed by existing secret management tools within the K8s ecosystem.

jsirianni avatar Oct 17 '23 22:10 jsirianni

As I have the same request, maybe #151 is enough for this?

rsommer avatar May 15 '24 08:05 rsommer

#151 has been merged but then reverted by upstream - apparently, this is not wanted.

rsommer avatar Jul 29 '24 14:07 rsommer

ENV vars are not very secure, as they can be leaked in a number of ways. It is more recommended to read credentials from a file, as these are more easily protected from accidental exposure.

The PR was reverted because it added everything as ENV vars. This is not allowed.

A change that allows just the connection string as an ENV would be accepted.

SuperQ avatar Jul 31 '24 15:07 SuperQ

https://github.com/prometheus-community/pgbouncer_exporter/pull/153 would be a better solution if the issues were addressed.

SuperQ avatar Jul 31 '24 15:07 SuperQ

I opened #159 with the additional handling of PGBOUNCER_EXPORTER_METRICS_PATH and PGBOUNCER_EXPORTER_PIDFILE_PATH removed. While using a config file could also be valid and I am well aware of the shortcomings of environment variables, in a mainly via env vars configured container deployment this still would help keeping things in one place.

rsommer avatar Aug 01 '24 07:08 rsommer