2019-10-17 20:36:51 +00:00
|
|
|
---
|
2019-10-22 21:56:22 +00:00
|
|
|
title: Enable TLS encryption
|
|
|
|
seotitle: Enable TLS/SSL encryption
|
2019-10-17 20:36:51 +00:00
|
|
|
description: >
|
2019-10-21 22:54:30 +00:00
|
|
|
Enable Transport Layer Security (TLS) and use the HTTPS protocol to secure communication between clients and InfluxDB.
|
2019-10-21 22:51:09 +00:00
|
|
|
weight: 101
|
2019-10-17 20:36:51 +00:00
|
|
|
menu:
|
|
|
|
v2_0:
|
|
|
|
parent: Security & authorization
|
2019-10-21 22:51:09 +00:00
|
|
|
v2.0/tags: [security, authentication, tls, https, ssl]
|
2019-10-17 20:36:51 +00:00
|
|
|
---
|
|
|
|
|
|
|
|
Enabling HTTPS encrypts the communication between clients and the InfluxDB server.
|
|
|
|
When configured with a signed certificate, HTTPS can also verify the authenticity of the InfluxDB server to connecting clients.
|
|
|
|
|
2019-10-21 17:17:39 +00:00
|
|
|
{{% warn %}}
|
2019-11-04 17:24:29 +00:00
|
|
|
InfluxData **strongly recommends** enabling HTTPS, especially if you plan on sending requests to InfluxDB over a network.
|
2019-10-21 17:17:39 +00:00
|
|
|
{{% /warn %}}
|
2019-10-17 20:36:51 +00:00
|
|
|
|
|
|
|
## Requirements
|
|
|
|
|
2019-10-21 22:54:30 +00:00
|
|
|
To enable HTTPS with InfluxDB, you need a Transport Layer Security (TLS) certificate (also known as a Secured Sockets Layer (SSL) certificate).
|
2019-10-17 20:36:51 +00:00
|
|
|
InfluxDB supports three types of TLS certificates:
|
|
|
|
|
2019-10-21 22:54:30 +00:00
|
|
|
### Single domain certificates signed by a Certificate Authority
|
2019-10-17 20:36:51 +00:00
|
|
|
|
2019-10-21 22:54:30 +00:00
|
|
|
Single domain certificates provide cryptographic security to HTTPS requests and allow clients to verify the identity of the InfluxDB server.
|
2019-10-22 17:59:09 +00:00
|
|
|
These certificates are signed and issued by a trusted, third-party Certificate Authority (CA).
|
2019-10-21 22:54:30 +00:00
|
|
|
With this certificate option, every InfluxDB instance requires a unique single domain certificate.
|
2019-10-17 20:36:51 +00:00
|
|
|
|
2019-10-21 22:54:30 +00:00
|
|
|
### Wildcard certificates signed by a Certificate Authority
|
2019-10-17 20:36:51 +00:00
|
|
|
|
2019-10-21 22:54:30 +00:00
|
|
|
Wildcard certificates provide cryptographic security to HTTPS requests and allow clients to verify the identity of the InfluxDB server.
|
|
|
|
Wildcard certificates can be used across multiple InfluxDB instances on different servers.
|
2019-10-17 20:36:51 +00:00
|
|
|
|
2019-10-21 22:54:30 +00:00
|
|
|
### Self-signed certificates
|
2019-10-17 20:36:51 +00:00
|
|
|
|
2019-10-22 17:59:09 +00:00
|
|
|
Self-signed certificates are _not_ signed by a trusted, third-party CA.
|
2019-10-21 22:54:30 +00:00
|
|
|
Unlike CA-signed certificates, self-signed certificates only provide cryptographic security to HTTPS requests.
|
|
|
|
They do not allow clients to verify the identity of the InfluxDB server.
|
|
|
|
With this certificate option, every InfluxDB instance requires a unique self-signed certificate.
|
|
|
|
You can generate a self-signed certificate on your own machine.
|
2019-10-17 20:36:51 +00:00
|
|
|
|
2019-10-18 16:59:43 +00:00
|
|
|
<!-- InfluxDB supports certificates composed of a private key file (`.key`) and a signed certificate file (`.crt`) file pair, -->
|
|
|
|
<!-- as well as certificates that combine the private key file and the signed certificate file into a single bundled file (`.pem`). -->
|
2019-10-17 20:36:51 +00:00
|
|
|
|
2019-10-22 17:59:09 +00:00
|
|
|
## Enable HTTPS with a CA-signed certificate
|
2019-10-17 20:36:51 +00:00
|
|
|
|
2019-10-17 20:42:47 +00:00
|
|
|
1. **Install the certificate**
|
2019-10-17 20:36:51 +00:00
|
|
|
|
2019-10-18 16:59:43 +00:00
|
|
|
Place the private key file (`.key`) and the signed certificate file (`.crt`) in the `/etc/ssl/` directory.
|
2019-10-22 17:59:09 +00:00
|
|
|
(Other paths will also work.)
|
2019-10-17 20:36:51 +00:00
|
|
|
|
2019-10-17 20:42:47 +00:00
|
|
|
2. **Set certificate file permissions**
|
2019-10-17 20:36:51 +00:00
|
|
|
|
2019-10-21 22:54:30 +00:00
|
|
|
The user running InfluxDB must have read permissions on the TLS certificate.
|
2019-10-17 20:36:51 +00:00
|
|
|
|
2019-10-17 20:58:47 +00:00
|
|
|
{{% note %}}You may opt to set up multiple users, groups, and permissions.
|
|
|
|
Ultimately, make sure all users running InfluxDB have read permissions for the TLS certificate.
|
|
|
|
{{% /note %}}
|
2019-10-17 20:36:51 +00:00
|
|
|
|
2019-10-17 20:42:47 +00:00
|
|
|
Run the following command to give InfluxDB read and write permissions on the certificate files.
|
2019-10-17 20:36:51 +00:00
|
|
|
|
2019-10-17 20:42:47 +00:00
|
|
|
```bash
|
|
|
|
sudo chmod 644 /etc/ssl/<CA-certificate-file>
|
|
|
|
sudo chmod 600 /etc/ssl/<private-key-file>
|
|
|
|
```
|
2019-10-17 20:36:51 +00:00
|
|
|
|
2019-10-18 16:59:43 +00:00
|
|
|
3. **Run `influxd` with TLS flags**
|
2019-10-17 20:36:51 +00:00
|
|
|
|
2019-10-18 20:28:03 +00:00
|
|
|
Start InfluxDB with TLS command line flags:
|
|
|
|
|
|
|
|
```bash
|
2019-10-18 21:26:59 +00:00
|
|
|
influxd \
|
2019-10-22 17:59:09 +00:00
|
|
|
--tls-cert "/etc/ssl/influxdb-selfsigned.crt" \
|
2019-10-18 21:26:59 +00:00
|
|
|
--tls-key "/etc/ssl/influxdb-selfsigned.key"
|
2019-10-18 20:28:03 +00:00
|
|
|
```
|
2019-10-17 20:36:51 +00:00
|
|
|
|
2019-10-22 17:59:09 +00:00
|
|
|
4. **Verify TLS connection**
|
2019-10-22 16:18:50 +00:00
|
|
|
|
|
|
|
Ensure you can connect over HTTPS by running
|
|
|
|
|
|
|
|
```
|
|
|
|
curl -v https://influxdb:9999/api/v2/ping
|
|
|
|
```
|
|
|
|
|
2019-10-22 17:59:09 +00:00
|
|
|
With this command, you should see output confirming a succussful TLS handshake.
|
2019-10-17 20:36:51 +00:00
|
|
|
|
2019-10-22 17:59:09 +00:00
|
|
|
## Enable HTTPS with a self-signed certificate
|
2019-10-17 20:36:51 +00:00
|
|
|
|
2019-10-18 16:59:43 +00:00
|
|
|
1. **Generate a self-signed certificate**
|
2019-10-17 20:36:51 +00:00
|
|
|
|
2019-10-22 16:22:06 +00:00
|
|
|
Use the `openssl` utility (preinstalled on many OSes) to create a certificate.
|
2019-10-17 20:42:47 +00:00
|
|
|
The following command generates a private key file (`.key`) and a self-signed
|
|
|
|
certificate file (`.crt`) which remain valid for the specified `NUMBER_OF_DAYS`.
|
2019-10-18 16:59:43 +00:00
|
|
|
It outputs those files to `/etc/ssl/` and gives them the required permissions.
|
2019-10-22 17:59:09 +00:00
|
|
|
(Other paths will also work.)
|
2019-10-17 20:36:51 +00:00
|
|
|
|
2019-10-17 20:42:47 +00:00
|
|
|
```bash
|
2019-10-18 21:26:59 +00:00
|
|
|
sudo openssl req -x509 -nodes -newkey rsa:2048 \
|
|
|
|
-keyout /etc/ssl/influxdb-selfsigned.key \
|
|
|
|
-out /etc/ssl/influxdb-selfsigned.crt \
|
|
|
|
-days <NUMBER_OF_DAYS>
|
2019-10-17 20:42:47 +00:00
|
|
|
```
|
2019-10-17 20:36:51 +00:00
|
|
|
|
2019-10-17 20:42:47 +00:00
|
|
|
When you execute the command, it will prompt you for more information.
|
2019-10-18 16:59:43 +00:00
|
|
|
You can choose to fill out that information or leave it blank; both actions generate valid certificate files.
|
2019-10-18 20:28:03 +00:00
|
|
|
|
2019-10-18 16:59:43 +00:00
|
|
|
2. **Run `influxd` with TLS flags**
|
2019-10-18 20:28:03 +00:00
|
|
|
|
2019-10-18 21:37:28 +00:00
|
|
|
Start InfluxDB with TLS command line flags:
|
2019-10-17 20:36:51 +00:00
|
|
|
|
2019-10-17 20:42:47 +00:00
|
|
|
```bash
|
2019-10-18 21:37:28 +00:00
|
|
|
influxd \
|
|
|
|
--tls-cert "/etc/ssl/influxdb-selfsigned.crt" \
|
|
|
|
--tls-key "/etc/ssl/influxdb-selfsigned.key"
|
2019-10-17 20:42:47 +00:00
|
|
|
```
|
2019-10-17 20:36:51 +00:00
|
|
|
|
2019-10-22 17:59:09 +00:00
|
|
|
3. **Verify TLS connection**
|
2019-10-22 16:18:50 +00:00
|
|
|
|
|
|
|
Ensure you can connect over HTTPS by running
|
|
|
|
|
|
|
|
```
|
|
|
|
curl -vk https://influxdb:9999/api/v2/ping
|
|
|
|
```
|
|
|
|
|
2019-10-22 17:59:09 +00:00
|
|
|
With this command, you should see output confirming a succussful TLS handshake.
|
2019-10-17 20:36:51 +00:00
|
|
|
|
|
|
|
## Connect Telegraf to a secured InfluxDB instance
|
|
|
|
|
2019-10-22 17:40:28 +00:00
|
|
|
To connect [Telegraf](/telegraf/latest/) to an InfluxDB 2.0 instance with TLS enabled,
|
|
|
|
update the following `influxdb_v2` output settings in your Telegraf configuration file:
|
2019-10-17 20:36:51 +00:00
|
|
|
|
2019-10-22 17:40:28 +00:00
|
|
|
- Update urls to use https instead of http.
|
|
|
|
- If using a self-signed certificate, uncomment and set `insecure_skip_verify` to true.
|
|
|
|
|
|
|
|
### Example configuration
|
2019-10-17 20:36:51 +00:00
|
|
|
|
|
|
|
```toml
|
2019-10-21 22:54:30 +00:00
|
|
|
###############################################################################
|
|
|
|
# OUTPUT PLUGINS #
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
# Configuration for sending metrics to InfluxDB
|
|
|
|
[[outputs.influxdb_v2]]
|
|
|
|
## The URLs of the InfluxDB cluster nodes.
|
|
|
|
##
|
|
|
|
## Multiple URLs can be specified for a single cluster, only ONE of the
|
|
|
|
## urls will be written to each interval.
|
2019-10-22 17:40:28 +00:00
|
|
|
urls = ["https://127.0.0.1:9999"]
|
2019-10-21 22:54:30 +00:00
|
|
|
|
|
|
|
[...]
|
|
|
|
|
|
|
|
## Optional TLS Config for use on HTTP connections.
|
|
|
|
[...]
|
|
|
|
## Use TLS but skip chain & host verification
|
|
|
|
insecure_skip_verify = true
|
2019-10-17 20:36:51 +00:00
|
|
|
```
|
|
|
|
|
2019-10-21 22:54:30 +00:00
|
|
|
Restart Telegraf using the updated configuration file.
|