Vonng / pg_exporter

Advanced PostgreSQL & Pgbouncer Metrics Exporter for Prometheus
https://pigsty.io
Apache License 2.0
164 stars 42 forks source link

Exclude template DBs from discovery and schema-qualify discovery query #50

Closed ringerc closed 4 weeks ago

ringerc commented 4 weeks ago

When doing database auto-discovery, exclude all databases marked as templates and any databases that do not allow connections.

It's conceivable, but not very likely, that someone could want to scrape metrics from a template DB, but pg_exporter currently defaults to excluding template1 anyway. postgres_exporter also has the same behaviour of excluding template DBs from discovery. So I did not add a CLI option to override this behaviour.

Additionally, schema-qualify references to pg_database and the pg_is_in_recovery function call in the database discovery query to guarantee protection against any possible search_path based attacks. I can't immediately see how it'd be possible in this case, so it's not a vulnerability, but it's best practice to always schema-qualify everything in any query that could possibly be run as a privileged role.