influxdata / telegraf

Agent for collecting, processing, aggregating, and writing metrics, logs, and other arbitrary data.
https://influxdata.com/telegraf
MIT License
14.6k stars 5.57k forks source link

Postgresql plugin does not support SCRAM-SHA-256 authentication #7438

Closed vitalca closed 2 years ago

vitalca commented 4 years ago

Relevant telegraf.conf:

[[inputs.postgresql]]
    address = "postgres://$PG_USERNAME:$PG_PASSWORD@$PG_HOST/$PG_DBNAME"
    databases = ["$PG_DBNAME"]

System info:

Steps to reproduce:

  1. enable SCRAM-SHA-256 authentication
    ALTER SYSTEM SET password_encryption = 'scram-sha-256';
  2. update passwords to recalculate hashes
    ALTER ROLE username PASSWORD 'xxx';
  3. update pg_hba.conf
  4. reload configs
    SELECT pg_reload_conf();
  5. try to start telegraf

Expected behavior:

No issues

Actual behavior:

E! Error in plugin [inputs.postgresql]: unknown authentication type: 10

Temporary workaround:

Configure trust authentication for telegraf in the pg_hba.conf

danielnelson commented 4 years ago

This would be a good addition, do you think it is something you could work on?

related: https://github.com/jackc/pgx/commit/5044e8473ad948114b6cb63f6f30f94fc7834667

powersj commented 2 years ago

Hi,

It looks like this was added to the library Telegraf uses here. I tried launching a container with docker run --rm --name postgres --net host -e POSTGRES_USER=postgres -e POSTGRES_PASSWORD=password -e POSTGRES_INITDB_ARGS=--auth-host=scram-sha-256 postgres and was able to connect successfully:

postgresql,db=postgres,host=ryzen,server=dbname\=postgres\ host\=localhost\ user\=postgres tup_inserted=0i,datname="postgres",sessions_fatal=0i,sessions_abandoned=0i,tup_updated=0i,xact_commit=5i,blk_read_time=0,datid=13757i,deadlocks=0i,blks_read=171i,active_time=0.414,temp_bytes=0i,tup_returned=2907i,numbackends=1i,tup_deleted=0i,blks_hit=3038i,xact_rollback=0i,blk_write_time=0,temp_files=0i,sessions_killed=0i,sessions=2i,session_time=5.272,tup_fetched=1520i,conflicts=0i,idle_in_transaction_time=0 1660678797000000000
postgresql,db=postgres,host=ryzen,server=dbname\=postgres\ host\=localhost\ user\=postgres buffers_alloc=73i,buffers_backend_fsync=0i,checkpoints_req=1i,buffers_clean=0i,checkpoint_write_time=1,buffers_checkpoint=0i,maxwritten_clean=0i,buffers_backend=0i,checkpoint_sync_time=2,checkpoints_timed=0i 1660678797000000000

I'm going to mark this as closed, but if you are still seeing this issue, please do reply and let us know along with how to reproduce and telegraf logs.

Thanks!