Vinicius Morais
Vinicius Morais

Reputation: 595

How set authenticate in InfluxDB?

I'm having troubling with set authenticate in InfluxDB. First the follow tutorial told me to change the config file:

https://docs.influxdata.com/influxdb/v1.7/administration/authentication_and_authorization/#set-up-authentication

[http]
  enabled = true
  bind-address = ":8086"
  auth-enabled = true # ✨
  log-enabled = true
  write-tracing = false
  pprof-enabled = false
  https-enabled = false
  https-certificate = "/etc/ssl/influxdb.pem"

But when i change, and reload the server. I can't create users.

 CREATE USER paul WITH PASSWORD 'timeseries4days' WITH ALL PRIVILEGES
 ERR: unable to parse Basic Auth credentials
 Warning: It is possible this error is due to not setting a database.
 Please set a database with the command "use <database>".

So, when a use my database that i created:

 USE example
 ERR: unable to parse Basic Auth credentials

Now i don't know what i exactly do to set my authenticate to give only a user (In this case paul) the power to READ and WRITE my database example.

Upvotes: 5

Views: 18083

Answers (2)

SRJ
SRJ

Reputation: 2846

InfluxDB 1.x

In this example I have started influx using docker container

docker run -d --name=influxdb \  
 -p 8086:8086 \
 -v  /tmp/testdata/influx:/root/.influxdb2 \
      --net=influxdb-telegraf-net \
      influxdb:1.8.0

Login to influxdb shell and execute queries

influx -username "my_username" -password "my_password"

InfluxDB 2.x

In this example I have started influx using docker container

docker run -d --name=influxdb \  
 -p 8086:8086 \
 -v  /tmp/testdata/influx:/root/.influxdb2 \
      --net=influxdb-telegraf-net \
      influxdb:2.0

Do the setup via login to Influxdb or InfluxDB UI

I've logged into container

influx setup

Typical response

root@189e1232a869:/# influx setup
> Welcome to InfluxDB 2.0!
? Please type your primary username sj
? Please type your password *************
? Please type your password again *************
? Please type your primary organization name abc
? Please type your primary bucket name abc
? Please type your retention period in hours, or 0 for infinite 6
? Setup with these parameters?
  Username:          sj
  Organization:      abc
  Bucket:            abc
  Retention Period:  6h0m0s
 Yes
> Config default has been stored in /etc/influxdb2/influx-configs.
User    Organization    Bucket
sj  abc     abc

Create a config

influx config create \
  -n config-name \
  -u http://localhost:8086 \
  -p example-user:example-password \
  -o example-org

Run queries

influx query

Other available commands

root@189e1232a869:/# influx
Influx Client

Usage:
  influx [command]

Available Commands:
  apply       Apply a template to manage resources
  auth        Authorization management commands
  backup      Backup database
  bucket      Bucket management commands
  completion  Generates completion scripts
  config      Config management commands
  dashboards  List Dashboard(s).
  delete      Delete points from influxDB
  export      Export existing resources as a template
  help        Help about any command
  org         Organization management commands
  ping        Check the InfluxDB /health endpoint
  query       Execute a Flux query
  restore     Restores a backup directory to InfluxDB.
  secret      Secret management commands
  setup       Setup instance with initial user, org, bucket
  stacks      List stack(s) and associated templates. Subcommands manage stacks.
  task        Task management commands
  telegrafs   List Telegraf configuration(s). Subcommands manage Telegraf configurations.
  template    Summarize the provided template
  user        User management commands
  v1          InfluxDB v1 management commands
  version     Print the influx CLI version
  write       Write points to InfluxDB

Reference : https://docs.influxdata.com/influxdb/v2.5/tools/influx-cli/

You can create multiple configuration and switch between them in influxDB 2.0 https://docs.influxdata.com/influxdb/v2.5/reference/cli/influx/config/

Upvotes: 0

Samuel Toh
Samuel Toh

Reputation: 19298

Now that Authentication is enabled, you'll need to authenticate yourself before you can do anything in the database.

The error unable to parse Basic Auth credentials is suggesting that you did not pass in any credentials.

If you're trying use the influx binary to create an user then you'll have to set the -username and -password options.

For instance:

influx -username "my_username" -password "my_password" \
        -execute "CREATE USER parul WITH PASSWORD 'timeseries4days'

Upvotes: 11

Related Questions