InfluxDBv2 authorization fails if docker secrets are used

I found the problem, it’s the token itself.

Provide token via environment:

docker compose file:

secrets:
  telegraf_influxdb_token:
    environment: "TELEGRAF_TOKEN"

results in:

alexander@ubuntu:~/home-automation$ docker exec -it telegraf cat /run/secrets/telegraf_influxdb_token
jCSAWc***Ong==alexander@ubuntu:~/home-automation$ 

Provide token via file:

docker compose file:

secrets:
  telegraf_influxdb_token:
    file: ./.secrets/telegraf_influxdb_token

results in:

alexander@ubuntu:~/home-automation$ docker exec -it telegraf cat /run/secrets/telegraf_influxdb_token
jCSAWc***Ong==
alexander@ubuntu:~/home-automation$ 

The new line at the end is the problem. However my PWD file doesn’t contain any new line:

alexander@ubuntu:~/home-automation$ cat -A .secrets/telegraf_influxdb_token 
jCSAW***Ong==$
alexander@ubuntu:~/home-automation$

I believe that is a bug in how telegraf reads the file. Google a bit, I found “Trim contents of slack api urls from files by srhb · Pull Request #2929 · prometheus/alertmanager · GitHub

Different SW, different use case, but same problem.

Any thoughts?