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

ber*_*tin 2 influxdb

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

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

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

Mar*_*erg 5

“为什么”

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

在最简单的安装中,<insert DBMS here>应该只运行 - 用于集成测试、简单的评估目的等。我们可以生成一个 root/admin/superhoncho 用户密码,但通常情况下,这不会被更改,这是一个坏东西™

而且由于没有人会在没有启用身份验证和授权的情况下在生产中运行数据库,因此在默认安装中提供轻松访问无论如何都不是问题,是吗?

我倾向于同意这个推理,尽管我不同意在 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
Run Code Online (Sandbox Code Playgroud)

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

...
[http]
  auth-enabled = true
...
Run Code Online (Sandbox Code Playgroud)

接下来,我们使用这个修改后的配置文件启动我们的 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
Run Code Online (Sandbox Code Playgroud)

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

现在,我们连接到我们的 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;
Run Code Online (Sandbox Code Playgroud)

从现在开始,几乎所有东西都需要凭据

> 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
Run Code Online (Sandbox Code Playgroud)

授权

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

> 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
Run Code Online (Sandbox Code Playgroud)

进一步阅读(!!!)

忽略风险自负。你。有。是。警告。