content/kapacitor/v1/administration/auth/influxdb-enterprise-auth.md
Use user-based authorizations stored and managed in InfluxDB Enterprise to authenticate requests to the Kapacitor HTTP API.
The process of using InfluxDB Enterprise authorizations to authenticate with Kapacitor involves three components of the enterprise TICK stack:
Kapacitor parses user credentials provided in an API request.
Kapacitor checks to see if the username and password currently match any user details stored in the local Kapacitor cache.
If the user details are in the cache, skip to step 7.
If user details are not in the cache, Kapacitor sends the credentials to
the InfluxDB Enterprise meta API endpoint.
The InfluxDB Enterprise meta server checks if the credentials are valid and, if valid, returns a user details JSON document to Kapacitor.
Kapacitor checks the user details document for the correct privileges.
Kapacitor caches the user details.
If the user has the correct privileges, Kapacitor completes the request.
If the user does not have the correct privileges, Kapacitor aborts the
transaction and returns a 403 error with response body:
{"error":"user <USER> does not have \"read\" privilege for API endpoint \"/kapacitor/v1/tasks\""}
Use the InfluxDB Enterprise meta API to create a user with Kapacitor permissions or to create a role with Kapacitor permissions and assign a user to that role.
{{% note %}} The examples below use the InfluxDB Enterprise meta API to manage users and roles, but you can also use Chronograf to manage users and roles. {{% /note %}}
To interact with Kapacitor, the user or role must have one or both of the following permissions:
{{< tabs-wrapper >}} {{% tabs %}} Create a user Create a role and assign a user {{% /tabs %}}
<!----------------------------- BEGIN user content ---------------------------->{{% tab-content %}}
Use the following request method and endpoint of the InfluxDB Enterprise meta API to create a new InfluxDB Enterprise user:
{{< api-endpoint method="post" endpoint="/user" >}}
Provide the following:
curl --request POST https://172.17.0.2:8091/user \
--user "admin:changeit" \
--data '{
"action":"create",
"user": {
"name":"johndoe",
"password":"pa5sw0Rd"
}
}'
Use the following request method and endpoint of the InfluxDB Enterprise meta API to grant Kapacitor-related permissions to the new user:
{{< api-endpoint method="POST" endpoint="/user" >}}
Provide the following:
$ curl --request POST https://172.17.0.2:8091/user \
--user "username:password" \
--data '{
"action": "add-permissions",
"user":{
"name": "johndoe",
"permissions": {
"":[
"KapacitorAPI",
"KapacitorConfigAPI"
]
}
}
}'
{{% /tab-content %}}
<!------------------------------ END user content -----------------------------> <!----------------------------- BEGIN role content ---------------------------->{{% tab-content %}}
Use the following request method and endpoint of the InfluxDB Enterprise meta API to create a new InfluxDB Enterprise role:
{{< api-endpoint method="post" endpoint="/role" >}}
Provide the following:
curl --request POST https://172.17.0.2:8091/role \
--user "admin:changeit" \
--data '{
"action":"create",
"user": {
"name":"kapacitor",
}
}'
Use the following request method and endpoint of the InfluxDB Enterprise meta API to grant Kapacitor-related permissions to the new role:
{{< api-endpoint method="POST" endpoint="/role" >}}
Provide the following:
$ curl --request POST https://172.17.0.2:8091/user \
--user "username:password" \
--data '{
"action": "add-permissions",
"role":{
"name": "kapacitor",
"permissions": {
"":[
"KapacitorAPI",
"KapacitorConfigAPI"
]
}
}
}'
Use the following request method and endpoint of the InfluxDB Enterprise meta API to create a new InfluxDB Enterprise user:
{{< api-endpoint method="post" endpoint="/user" >}}
Provide the following:
curl --request POST https://172.17.0.2:8091/user \
--user "admin:changeit" \
--data '{
"action":"create",
"user": {
"name":"johndoe",
"password":"pa5sw0Rd"
}
}'
Use the following request method and endpoint of the InfluxDB Enterprise meta API to assign an InfluxDB Enterprise user to the new role:
{{< api-endpoint method="post" endpoint="/role" >}}
Provide the following:
curl --request POST https://172.17.0.2:8091/role \
--user "username:password" \
--data '{
"action": "add-users",
"role": {
"name": "example-role",
"users": [
"johndoe"
]
}
}'
{{% /tab-content %}}
<!------------------------------ END role content ----------------------------->{{< /tabs-wrapper >}}
Enable and configure authentication-related Kapacitor configuration options
in your kapacitor.conf or with environment variables:
{{< code-tabs-wrapper >}} {{% code-tabs %}} kapacitor.conf Environment variables {{% /code-tabs %}} {{% code-tab-content %}}
[http]
# ...
auth-enabled = true
[auth]
enabled = true
cache-expiration = "1h"
bcrypt-cost = 4
meta-addr = " 172.17.0.2:8091"
meta-username = "example-influxdb-username"
meta-password = "example-influxdb-password"
meta-use-tls = true
meta-ca = "/path/to/cert.ca"
meta-cert = "/path/to/cert.cert"
meta-key = "/path/to/cert.key"
meta-insecure-skip-verify = false
# ...
{{% /code-tab-content %}} {{% code-tab-content %}}
export KAPACITOR_HTTP_AUTH_ENABLED=true
export KAPACITOR_AUTH_ENABLED=true
export KAPACITOR_AUTH_CACHE_EXPIRATION=1h
export KAPACITOR_AUTH_BCRYPT_COST=4
export KAPACITOR_AUTH_META_ADDR=172.17.0.2:8091
export KAPACITOR_AUTH_META_USERNAME=example-username
export KAPACITOR_AUTH_META_PASSWORD=example-password
export KAPACITOR_AUTH_META_USE-tls=true
export KAPACITOR_AUTH_META_CA=/path/to/cert.ca
export KAPACITOR_AUTH_META_CERT=/path/to/cert.cert
export KAPACITOR_AUTH_META_KEY=/path/to/cert.key
export KAPACITOR_AUTH_META_INSECURE_SKIP_VERIFY=false
{{% /code-tab-content %}} {{< /code-tabs-wrapper >}}
With authentication enabled, Kapacitor requires valid user credentials for all API requests.
To authenticate with Kapacitor when using the kapacitor CLI,
provide your username and password as part of the Kapacitor -url:
# Syntax
kapacitor -url http://<username>:<password>@localhost:9092
# Example
kapacitor -url http://admin:Pa5sw0Rd@localhost:9092
To authenticate directly with the Kapacitor API, use basic authentication to provide your username and password.
# Syntax
curl --request GET http://localhost:9092/kapacitor/v1/tasks \
-u "<username>:<password>"
# Example
curl --request GET http://localhost:9092/kapacitor/v1/tasks \
-u "johndoe:Pa5sw0Rd"