-
Notifications
You must be signed in to change notification settings - Fork 709
*: update the recent improvements about tls/security #2491
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
b7efc18
update security
toutdesuite 3cc95d7
minor changes
toutdesuite 7169fe9
Update enable-tls-between-components.md
toutdesuite dabd6a2
Update enable-tls-clients.md
toutdesuite 70448b4
Merge branch 'master' into update-security
toutdesuite 35067aa
fix dead link
toutdesuite 13b744c
Merge branch 'master' into update-security
toutdesuite 1c62919
Update how-to/secure/enable-tls-between-components.md
TomShawn a5c2fad
Update enable-tls-clients.md
toutdesuite 75ed09d
Update how-to/secure/enable-tls-between-components.md
toutdesuite aa2d976
Update how-to/secure/enable-tls-between-components.md
toutdesuite b3abcea
address comments
toutdesuite a35d9fb
add ALTER INSTANCE to TOC
toutdesuite 49db34f
resolve comments
toutdesuite 535927d
Update reference/sql/statements/alter-instance.md
toutdesuite b86aa43
Update reference/tools/tidb-control.md
toutdesuite 31b509a
Update reference/tools/tidb-control.md
toutdesuite c347cc4
Update reference/tools/tidb-control.md
toutdesuite bcb9a7e
Update reference/sql/statements/alter-instance.md
toutdesuite 3c973a2
Update reference/sql/statements/alter-instance.md
toutdesuite e9bef47
Update reference/sql/statements/alter-instance.md
toutdesuite 9719c23
Merge branch 'master' into update-security
sre-bot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,86 +1,180 @@ | ||
| --- | ||
| title: Enable TLS Authentication | ||
| summary: Learn how to enable TLS authentication in a TiDB cluster. | ||
| title: Enable TLS Authentication and Encrypt the Stored Data | ||
| summary: Learn how to enable TLS authentication and encrypt the stored data in a TiDB cluster. | ||
| category: how-to | ||
| --- | ||
|
|
||
| # Enable TLS Authentication | ||
| # Enable TLS Authentication and Encrypt the Stored Data | ||
|
|
||
| ## Overview | ||
| This document introduces how to enable TLS authentication and encrypt the stored data in a TiDB cluster. | ||
|
|
||
| This document describes how to enable TLS authentication in the TiDB cluster. The TLS authentication includes the following two conditions: | ||
| ## Enable TLS Authentication | ||
|
|
||
| - The mutual authentication between TiDB components, including the authentication among TiDB, TiKV and PD, between TiKV Control and TiKV, between PD Control and PD, between TiKV peers, and between PD peers. Once enabled, the mutual authentication applies to all components, and it does not support applying to only part of the components. | ||
| - The one-way and mutual authentication between the TiDB server and the MySQL Client. | ||
| This section describes how to enable TLS authentication in a TiDB cluster. TLS authentication can be applied to the following scenarios: | ||
|
|
||
| - The **mutual authentication** between TiDB components, including the authentication among TiDB, TiKV, and PD; the authentication between TiDB Control and TiDB, between TiKV Control and TiKV, between PD Control and PD; the authentication between TiKV peers, and between PD peers. Once enabled, the mutual authentication applies to all components, rather than to part of the components. | ||
| - The **one-way** and **mutual authentication** between the TiDB server and the MySQL Client. | ||
|
|
||
| > **Note:** | ||
| > | ||
| > The authentication between the MySQL Client and the TiDB server uses one set of certificates, while the authentication among TiDB components uses another set of certificates. | ||
|
|
||
| ## Enable mutual TLS authentication among TiDB components | ||
|
|
||
| ### Prepare certificates | ||
| 1. Prepare certificates. | ||
|
|
||
| It is recommended to prepare a server certificate for TiDB, TiKV, and PD separately. Make sure that these components can authenticate each other. The clients of TiDB, TiKV, and PD share one client certificate. | ||
|
|
||
| You can use tools like `openssl`, `easy-rsa` and `cfssl` to generate self-signed certificates. | ||
|
|
||
| If you choose `cfssl`, you can refer to [generating self-signed certificates](/how-to/secure/generate-self-signed-certificates.md). | ||
|
|
||
| 2. Configure certificates. | ||
|
|
||
| To enable mutual authentication among TiDB components, configure the certificates of TiDB, TiKV, and PD as follows. | ||
|
|
||
| - TiDB | ||
|
|
||
| Configure in the configuration file or command line arguments: | ||
|
|
||
| ```toml | ||
| [security] | ||
| # Path of file that contains list of trusted SSL CAs for connection with cluster components. | ||
| cluster-ssl-ca = "/path/to/ca.pem" | ||
| # Path of file that contains X509 certificate in PEM format for connection with cluster components. | ||
| cluster-ssl-cert = "/path/to/tidb-server.pem" | ||
| # Path of file that contains X509 key in PEM format for connection with cluster components. | ||
| cluster-ssl-key = "/path/to/tidb-server-key.pem" | ||
| ``` | ||
|
|
||
| - TiKV | ||
|
|
||
| Configure in the configuration file or command line arguments, and set the corresponding URL to https: | ||
|
|
||
| ```toml | ||
| [security] | ||
| # set the path for certificates. Empty string means disabling secure connections. | ||
| ca-path = "/path/to/ca.pem" | ||
| cert-path = "/path/to/tikv-server.pem" | ||
| key-path = "/path/to/tikv-server-key.pem" | ||
| ``` | ||
|
|
||
| - PD | ||
|
|
||
| Configure in the configuration file or command line arguments, and set the corresponding URL to https: | ||
|
|
||
| ```toml | ||
| [security] | ||
| # Path of file that contains list of trusted SSL CAs. If set, following four settings shouldn't be empty | ||
| cacert-path = "/path/to/ca.pem" | ||
| # Path of file that contains X509 certificate in PEM format. | ||
| cert-path = "/path/to/pd-server.pem" | ||
| # Path of file that contains X509 key in PEM format. | ||
| key-path = "/path/to/pd-server-key.pem" | ||
| ``` | ||
|
|
||
| After certificates are configured as above, mutual authentication among TiDB components is enabled. | ||
|
|
||
| > **Note:** | ||
| > | ||
| > If you have enabled TLS in a TiDB cluster when you connect to the cluster using tidb-ctl, tikv-ctl, or pd-ctl, you need to specify the client certificate. For example: | ||
|
|
||
| It is recommended to prepare a separate server certificate for TiDB, TiKV and PD, and make sure that they can authenticate each other. The clients of TiDB, TiKV and PD share one client certificate. | ||
| {{< copyable "shell-regular" >}} | ||
|
|
||
| You can use multiple tools to generate self-signed certificates, such as `openssl`, `easy-rsa` and `cfssl`. | ||
| ```bash | ||
| ./tidb-ctl -u https://127.0.0.1:10080 --ca /path/to/ca.pem --ssl-cert /path/to/client.pem --ssl-key /path/to/client-key.pem | ||
| ``` | ||
|
|
||
| See an example of [generating self-signed certificates](/how-to/secure/generate-self-signed-certificates.md) using `cfssl`. | ||
| {{< copyable "shell-regular" >}} | ||
|
|
||
| ### Configure certificates | ||
| ```bash | ||
| ./pd-ctl -u https://127.0.0.1:2379 --cacert /path/to/ca.pem --cert /path/to/client.pem --key /path/to/client-key.pem | ||
| ``` | ||
|
|
||
| To enable mutual authentication among TiDB components, configure the certificates of TiDB, TiKV and PD as follows. | ||
| {{< copyable "shell-regular" >}} | ||
|
|
||
| #### TiDB | ||
| ```bash | ||
| ./tikv-ctl --host="127.0.0.1:20160" --ca-path="/path/to/ca.pem" --cert-path="/path/to/client.pem" --key-path="/path/to/clinet-key.pem" | ||
| ``` | ||
|
|
||
| Configure in the configuration file or command line arguments: | ||
| 3. Configure Common Name. | ||
|
|
||
| ```toml | ||
| [security] | ||
| # Path of file that contains list of trusted SSL CAs for connection with cluster components. | ||
| cluster-ssl-ca = "/path/to/ca.pem" | ||
| # Path of file that contains X509 certificate in PEM format for connection with cluster components. | ||
| cluster-ssl-cert = "/path/to/tidb-server.pem" | ||
| # Path of file that contains X509 key in PEM format for connection with cluster components. | ||
| cluster-ssl-key = "/path/to/tidb-server-key.pem" | ||
| ``` | ||
| The Common Name is used for caller verification. In general, the callee needs to verify the caller's identity, in addition to verifying the key, the certificates, and the CA provided by the caller. For example, TiKV can only be accessed by TiDB, and other visitors are blocked even though they have legitimate certificates. It is recommended to mark the certificate user identity using `Common Name` when generating the certificate, and to check the caller's identity by configuring the `Common Name` list for the callee. | ||
|
|
||
| #### TiKV | ||
| - TiDB | ||
|
|
||
| Configure in the configuration file or command line arguments, and set the corresponding URL to https: | ||
| Configure in the configuration file or command line arguments: | ||
|
|
||
| ```toml | ||
| [security] | ||
| # set the path for certificates. Empty string means disabling secure connections. | ||
| ca-path = "/path/to/ca.pem" | ||
| cert-path = "/path/to/tikv-server.pem" | ||
| key-path = "/path/to/tikv-server-key.pem" | ||
| ``` | ||
| ```toml | ||
| [security] | ||
| cluster-verify-cn = [ | ||
| "TiDB-Server", | ||
| "TiKV-Control", | ||
| ] | ||
| ``` | ||
|
|
||
| #### PD | ||
| - TiKV | ||
|
|
||
| Configure in the configuration file or command line arguments, and set the corresponding URL to https: | ||
| Configure in the configuration file or command line arguments: | ||
|
|
||
| ```toml | ||
| [security] | ||
| # Path of file that contains list of trusted SSL CAs. If set, following four settings shouldn't be empty | ||
| cacert-path = "/path/to/ca.pem" | ||
| # Path of file that contains X509 certificate in PEM format. | ||
| cert-path = "/path/to/pd-server.pem" | ||
| # Path of file that contains X509 key in PEM format. | ||
| key-path = "/path/to/pd-server-key.pem" | ||
| ``` | ||
| ```toml | ||
| [security] | ||
| cert-allowed-cn = [ | ||
| "TiDB-Server", "PD-Server", "TiKV-Control", "RawKvClient1", | ||
| ] | ||
| ``` | ||
|
|
||
| Now mutual authentication among TiDB components is enabled. | ||
| - PD | ||
|
|
||
| When you connect the server using the client, it is required to specify the client certificate. For example: | ||
| Configure in the configuration file or command line arguments: | ||
|
|
||
| ```bash | ||
| ./pd-ctl -u https://127.0.0.1:2379 --cacert /path/to/ca.pem --cert /path/to/client.pem --key /path/to/client-key.pem | ||
| ```toml | ||
| [security] | ||
| cert-allowed-cn = ["TiKV-Server", "TiDB-Server", "PD-Control"] | ||
| ``` | ||
|
|
||
| ./tikv-ctl --host="127.0.0.1:20160" --ca-path="/path/to/ca.pem" --cert-path="/path/to/client.pem" --key-path="/path/to/clinet-key.pem" | ||
| ``` | ||
| 4. Reload certificates. | ||
|
|
||
| To reload the certificates and the keys, TiDB, PD, and TiKV reread the current certificates and the key files each time a new connection is created. Currently, you cannot reload the CA certificate. | ||
|
|
||
| ## Enable TLS authentication between the MySQL client and TiDB server | ||
|
|
||
| See [Use Encrypted Connections](/how-to/secure/enable-tls-clients.md). | ||
| Refer to [Use Encrypted Connections](/how-to/secure/enable-tls-clients.md). | ||
|
|
||
| ## Encrypt stored data | ||
|
|
||
| In a TiDB cluster, user data is stored in TiKV. Once you configure the encrypted storage feature in TiKV, the TiDB cluster encrypts this data. This section introduces how to configure the data encryption feature in TiKV. | ||
|
|
||
| 1. Generate the token file. | ||
|
|
||
| The token file stores the keys used to encrypt the user data and to decrypt the encrypted data. | ||
|
|
||
| {{< copyable "shell-regular" >}} | ||
|
|
||
| ```bash | ||
| ./tikv-ctl random-hex --len 256 > cipher-file-256 | ||
| ``` | ||
|
|
||
| > **Note:** | ||
| > | ||
| > You can only use the hex-formatted token file. The file length must be 2 to the power of N, and is less than or equal to 1024. | ||
|
|
||
| 2. Configure TiKV as follows. | ||
|
|
||
| ```toml | ||
| [security] | ||
| # Storage path of the Cipher file. | ||
| cipher-file = "/path/to/cipher-file-256" | ||
| ``` | ||
|
|
||
| > **Note:** | ||
| > | ||
| > When you import data into a cluster using [TiDB Lightning](/reference/tools/tidb-lightning/overview.md), if the storage encryption feature is enabled in the target cluster, the SST files generated by TiDB Lightning must be encrypted. | ||
|
|
||
| ### Limitations | ||
|
|
||
| The limitations of the storage encryption feature are as follows: | ||
|
|
||
| - If the feature has not been enabled in the cluster before, you cannot enable this feature. | ||
| - If the feature is enabled in the cluster, you cannot disable this feature. | ||
| - You cannot enable the feature for some TiKV instances while disabling it for other instances in one cluster. You can only enable or disable this feature for all TiKV instances. This is because if you enable the encrypted storage feature, data are encrypted during data migration. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.