Authentication and authorization in InfluxDB
This page documents an earlier version of InfluxDB OSS. InfluxDB 3 Core is the latest stable version.
This document covers setting up and managing authentication and authorization in InfluxDB.
Authentication and authorization should not be relied upon to prevent access and protect data from malicious actors. If additional security or compliance features are desired, InfluxDB should be run behind a third-party service. If InfluxDB is being deployed on a publicly accessible endpoint, we strongly recommend authentication be enabled. Otherwise the data will be publicly available to any unauthenticated user.
Authentication
The InfluxDB API and the command line interface (CLI), which connects to the database using the API, include simple, built-in authentication based on user credentials. When you enable authentication, InfluxDB only executes HTTP requests that are sent with valid credentials.
Authentication only occurs at the HTTP request scope. Plugins do not currently have the ability to authenticate requests and service endpoints (for example, Graphite, collectd, etc.) are not authenticated.
Set up authentication
Create at least one admin user. See the authorization section for how to create an admin user.
If you enable authentication and have no users, InfluxDB will not enforce authentication and will only accept the query that creates a new admin user.
InfluxDB will enforce authentication once there is an admin user.
Enable authentication in your configuration file by setting the
auth-enabledoption totruein the[http]section:[http] enabled = true bind-address = ":8086" auth-enabled = true # Set to true log-enabled = true write-tracing = false pprof-enabled = true pprof-auth-enabled = true debug-pprof-enabled = false ping-auth-enabled = true https-enabled = true https-certificate = "/etc/ssl/influxdb.pem"If
pprof-enabledis set totrue, setpprof-auth-enabledandping-auth-enabledtotrueto require authentication on profiling and ping endpoints.Restart InfluxDB. Once restarted, InfluxDB checks user credentials on every request and only processes requests that have valid credentials for an existing user.
Authenticate requests
Authenticate with the InfluxDB API
There are two options for authenticating with the InfluxDB API.
If you authenticate with both Basic Authentication and the URL query parameters, the user credentials specified in the query parameters take precedence. The queries in the following examples assume that the user is an admin user. See the section on authorization for the different user types, their privileges, and more on user management.
Note: InfluxDB redacts passwords when you enable authentication.
Authenticate with Basic Authentication
curl -G http://localhost:8086/query \
-u todd:influxdb4ever \
--data-urlencode "q=SHOW DATABASES"Authenticate with query parameters in the URL or request body
Set u as the username and p as the password.
Credentials as query parameters
curl -G "http://localhost:8086/query?u=todd&p=influxdb4ever" \
--data-urlencode "q=SHOW DATABASES"Credentials in the request body
curl -G http://localhost:8086/query \
--data-urlencode "u=todd" \
--data-urlencode "p=influxdb4ever" \
--data-urlencode "q=SHOW DATABASES"Authenticate with the CLI
There are three options for authenticating with the CLI.
Authenticate with environment variables
Use the INFLUX_USERNAME and INFLUX_PASSWORD environment variables to provide
authentication credentials to the influx CLI.
export INFLUX_USERNAME=todd
export INFLUX_PASSWORD=influxdb4ever
echo $INFLUX_USERNAME $INFLUX_PASSWORD
todd influxdb4ever
influx
Connected to http://localhost:8086 version 1.13.0
InfluxDB shell 1.13.0Authenticate with CLI flags
Use the -username and -password flags to provide authentication credentials
to the influx CLI.
influx -username todd -password influxdb4ever
Connected to http://localhost:8086 version 1.13.0
InfluxDB shell 1.13.0Authenticate with credentials in the influx shell
Start the influx shell and run the auth command.
Enter your username and password when prompted.
> influx
Connected to http://localhost:8086 version 1.13.0
InfluxDB shell 1.13.0
> auth
username: todd
password:
>Authenticate using JWT tokens
For a more secure alternative to using passwords, include JWT tokens with requests to the InfluxDB API. This is currently only possible through the InfluxDB HTTP API.
- Add a shared secret in your InfluxDB configuration file
- Generate your JWT token
- Include the token in HTTP requests
Add a shared secret in your InfluxDB configuration file
InfluxDB uses the shared secret to encode the JWT signature.
By default, shared-secret is set to an empty string, in which case no JWT authentication takes place.
Add a custom shared secret in your InfluxDB configuration file.
The longer the secret string, the more secure it is:
[http]
shared-secret = "my super secret pass phrase"Alternatively, to avoid keeping your secret phrase as plain text in your InfluxDB configuration file, set the value with the INFLUXDB_HTTP_SHARED_SECRET environment variable.
Generate your JWT token
Use an authentication service to generate a secure token using your InfluxDB username, an expiration time, and your shared secret. There are online tools, such as https://jwt.io/, that will do this for you.
The payload (or claims) of the token must be in the following format:
{
"username": "myUserName",
"exp": 1516239022
}- username - The name of your InfluxDB user.
- exp - The expiration time of the token in UNIX epoch time. For increased security, keep token expiration periods short. For testing, you can manually generate UNIX timestamps using https://www.unixtimestamp.com/index.php.
Encode the payload using your shared secret. You can do this with either a JWT library in your own authentication server or by hand at https://jwt.io/.
The generated token follows this format: <header>.<payload>.<signature>
Include the token in HTTP requests
Include your generated token as part of the Authorization header in HTTP requests.
Use the Bearer authorization scheme:
Authorization: Bearer <myToken>Only unexpired tokens will successfully authenticate. Be sure your token has not expired.
Example query request with JWT authentication
curl -G "http://localhost:8086/query?db=demodb" \
--data-urlencode "q=SHOW DATABASES" \
--header "Authorization: Bearer <header>.<payload>.<signature>"Authenticate Telegraf requests to InfluxDB
Authenticating Telegraf requests to an InfluxDB instance with
authentication enabled requires some additional steps.
In the Telegraf configuration file (/etc/telegraf/telegraf.conf), uncomment
and edit the username and password settings.
###############################################################################
# OUTPUT PLUGINS #
###############################################################################
# ...
[[outputs.influxdb]]
# ...
username = "example-username" # Provide your username
password = "example-password" # Provide your password
# ...Restart Telegraf and you’re all set!
Authorization
Authorization is only enforced once you’ve enabled authentication. By default, authentication is disabled, all credentials are silently ignored, and all users have all privileges.
User types and privileges
Admin users
Admin users have READ and WRITE access to all databases and full access to the following administrative queries:
Database management
CREATE DATABASEDROP DATABASEDROP SERIESDROP MEASUREMENTCREATE RETENTION POLICYALTER RETENTION POLICYDROP RETENTION POLICYCREATE CONTINUOUS QUERYDROP CONTINUOUS QUERY