为什么任何用户都可以登录influxdb?

Why can any user login influxdb?

我已经安装了influxdb。但是在服务器中,每个用户都可以在输入 inlux 时登录。

为什么会这样?是不是安全问题。我该如何解决?

我想使用特定的管理员用户及其管理员密码登录。

“为什么”

多年来不同的数据库使用的推理略有不同,但基本上是这样的:

In its most simple install, <insert DBMS here> should just run - for integration tests, simple evaluation purposes etc. We could generate a root/admin/superhoncho user password, but more often than not, this is not going to be changed, and that is a Bad Thing™.

And since nobody sane would run a database in production without authentication and authorisation enabled, providing easy access in the default installation is not a problem anyway, is it?

我倾向于同意这种推理,但我不同意在 DBMS 默认情况下禁用身份验证和授权的情况下,它也应该默认绑定到 localhost。您让外部世界可以访问您的 DBMS,并且它只是您公司的网络吗?您肯定已经考虑过其中的含义!

“如何”

身份验证

我将使用 docker 来说明它,在非 docker 环境中您必须做什么是很明显的。

首先,我们拉取 influxdb docker 镜像并一次性创建默认配置文件:

$ docker run --rm influxdb influxd config > influxdb.conf
Unable to find image 'influxdb:latest' locally
latest: Pulling from library/influxdb
...
Digest: sha256:0aa7fea5336b5e5cc1c80e16062865821ec772e06519c138947ef5ebd9b34907
Status: Downloaded newer image for influxdb:latest
Merging with configuration at: /etc/influxdb/influxdb.conf

现在我们将 influxdb.conf[http] 部分中的身份验证参数更改为 true:

...
[http]
  auth-enabled = true
...

接下来,我们使用修改后的配置文件启动我们的 InfluxDB:

$ docker run -d --name influxdb -p 8086:8086 \
      -v $PWD/influxdb.conf:/etc/influxdb/influxdb.conf:ro \
      influxdb -config /etc/influxdb/influxdb.conf
1987f962c331d2404a2564bb752d971553b13181dbbbb1e38cf50d345b3191c4

(你得到的哈希和会有所不同。)

现在,我们连接到我们的 influxdb 并创建管理员用户

$ docker exec -it influxdb influx
Connected to http://localhost:8086 version 1.7.8
InfluxDB shell version: 1.7.8
> create user admin with password 'secret' with all privileges;

From this point on, credentials are needed for pretty much everything

> show users
ERR: unable to parse authentication credentials
Warning: It is possible this error is due to not setting a database.
Please set a database with the command "use <database>".
> auth
username: admin
password: 
> show users
user  admin
----  -----
admin true

授权

简单助记符:“用户被授予每个数据库的权限。”因此,为了向用户授予某些东西,该用户必须首先存在:

> create user berkancetin with password 'supersecret';
> create database foobar
> grant read on foobar to berkancetin
> show users
user        admin
----        -----
admin       true
berkancetin false
> show grants for "berkancetin"
database privilege
-------- ---------
foobar   READ

进一步阅读 (!!!)

忽略后果自负。 你。有。是。警告。