Search code examples
dockerinfluxdb

InfluxDB can create the first user only when auth is turned off


Is there a way of creating an user in InfluxDB with authentication enabled? Disclaimer: I am a novice to InfluxDB.

I created a Docker container running InfluxDB with authentication enabled by setting auth-enabled = true in http section of the influxdb.conf file.

[http]
  ...
  # Determines whether user authentication is enabled over HTTP/HTTPS.
  auth-enabled = true
  ...

As there are no users, I tried to create one using the following command:

docker exec influxdb influx -execute "create user admin with password 'blabla' with all privileges"

However, this fails with

"stdout": "ERR: error authorizing query: no user provided

So it is kind of a chicken-and-egg problem. You cannot create a user, because this requires logging in as a user in the first place.

It works when authentication is disabled. So I can do the following:

  1. Create config with authentication disabled.
  2. Start InfluxDB
  3. Create users
  4. Change config so authentication is now enabled.
  5. Restart InfluxDB

but in that case I have to store the config in a specific Docker volume and it still leaves a window when anybody could log in without authentication. So it can be automated, but it is not an elegant solution.

Is there an elegant solution for this problem?


Solution

  • Most DB images provide a way to configure an admin-user and admin-passwort via environment variables. InfluxDB does this too: https://hub.docker.com/_/influxdb/

    Set the environment variables INFLUXDB_ADMIN_USER and INFLUXDB_ADMIN_PASSWORD in your container to create the admin user with the given password. You can also enable auth by an environment variable INFLUXDB_HTTP_AUTH_ENABLED