Influx 中的身份验证允许所有用户名

时间:2021-06-11 13:06:29

标签: python docker influxdb influxdb-python

我正在使用 docker 镜像 influxdb:1.8,我想从另一个容器中使用 Python 连接到我的 influx 数据库。我想出了如何在不环顾四周的情况下做到这一点。但是,我注意到无论我使用哪个用户名或密码,我都能够连接到我的数据库(甚至查询数据!)。

我的实验是使用 InfluxDBClient 和一些随机用户名和密码连接到 Influx。它不仅有效,而且打印 client_variable._username 或 client_variable._password 也有效。但是,revoke_admin_privileges 方法引发了“InfluxDBClientError: user not found”

using default parameters using random strings

为什么在我启动客户端对象时没有出现这个错误?

为了更好的理解,我连接了Influx容器,在本地启动了Influx。在那里,“show users”命令没有返回任何已知用户,这也让我感到惊讶,因为我在 docker-compose.yml 文件中指定了一个我想使用的用户名和密码。

对这一切有什么想法吗?

PS:这是我的 docker-compose.yml 中创建容器的部分。

  influxdb:
image: influxdb:1.8
restart: always
ports:
  - "8086:8086"
environment:
  - INFLUXDB_DB=first
  - INFLUXDB_ADMIN_USER=some_user
  - INFLUXDB_ADMIN_PASSWORD=your_password_hehe
  - INFLUXDB_HTTP_AUTH_ENABLED=false
networks:
  - mynetwork
volumes:
  - ./volumes/influxdb-volume:/var/lib/influxdb
cpus: 0.80
logging:
  driver: "none"

1 个答案:

答案 0 :(得分:0)

要激活身份验证系统,您必须将 INFLUXDB_HTTP_AUTH_ENABLED 设置为 true

根据https://github.com/influxdata/influxdb/blob/1.8/docker/init-influxdb.sh

...
AUTH_ENABLED="$INFLUXDB_HTTP_AUTH_ENABLED"

if [ -z "$AUTH_ENABLED" ]; then
    AUTH_ENABLED="$(grep -iE '^\s*auth-enabled\s*=\s*true' /etc/influxdb/influxdb.conf | grep -io 'true' | cat)"
else
    AUTH_ENABLED="$(echo ""$INFLUXDB_HTTP_AUTH_ENABLED"" | grep -io 'true' | cat)"
fi
...