Skip to content

Commit 2598d44

Browse files
authored
dm: support customized secret key (#16740)
1 parent b5780fe commit 2598d44

11 files changed

+65
-19
lines changed

TOC.md

+1
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@
446446
- [Binlog Event Filter](/dm/dm-binlog-event-filter.md)
447447
- [Filter DMLs Using SQL Expressions](/dm/feature-expression-filter.md)
448448
- [Online DDL Tool Support](/dm/dm-online-ddl-tool-support.md)
449+
- [Customize a Secret Key for Encryption and Decryption](/dm/dm-customized-secret-key.md)
449450
- Manage a Data Migration Task
450451
- [Precheck a Task](/dm/dm-precheck.md)
451452
- [Create a Task](/dm/dm-create-task.md)

dm/dm-command-line-flags.md

+6-12
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ This document introduces DM's command-line flags.
7575
- The default value is `"http://127.0.0.1:8291"`
7676
- Required flag
7777

78+
### `--secret-key-path`
79+
80+
- The path of the customized secret key for encryption and decryption
81+
- The default value is `""`
82+
- Optional flag
83+
7884
## DM-worker
7985

8086
### `--advertise-addr`
@@ -132,15 +138,3 @@ This document introduces DM's command-line flags.
132138
- The `{advertise-addr}` of any DM-master node in the cluster to be connected by dmctl
133139
- The default value is `""`
134140
- It is a required flag when dmctl interacts with DM-master
135-
136-
### `--encrypt`
137-
138-
- Encrypts the plaintext database password into ciphertext
139-
- The default value is `""`
140-
- When this flag is specified, it is only used to encrypt the plaintext without interacting with the DM-master
141-
142-
### `--decrypt`
143-
144-
- Decrypts ciphertext encrypted with dmctl into plaintext
145-
- The default value is `""`
146-
- When this flag is specified, it is only used to decrypt the ciphertext without interacting with the DM-master

dm/dm-customized-secret-key.md

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
title: Customize a Secret Key for DM Encryption and Decryption
3+
summary: Learn how to customize a secret key to encrypt and decrypt passwords used in the DM(Data Migration)data source and migration task configurations.
4+
---
5+
6+
# Customize a Secret Key for DM Encryption and Decryption
7+
8+
Before v8.0.0, [DM](/dm/dm-overview.md) uses a [fixed AES-256 secret key](https://github.com/pingcap/tiflow/blob/1252979421fc83ffa2a1548d981e505f7fc0b909/dm/pkg/encrypt/encrypt.go#L27) to encrypt and decrypt passwords in the data source and migration task configurations. However, using a fixed secret key might pose security risks, especially in environments where security is crucial. To enhance security, starting from v8.0.0, DM removes the fixed secret key and enables you to customize a secret key.
9+
10+
## Usage
11+
12+
1. Create a custom key file, which must contain a 64-character hexadecimal AES-256 secret key.
13+
2. In the DM-master [command-line flags](/dm/dm-command-line-flags.md) or [configuration file](/dm/dm-master-configuration-file.md), specify `secret-key-path` as the path of your custom key file.
14+
15+
## Upgrade from a version earlier than v8.0.0
16+
17+
Because DM no longer uses the fixed secret key starting from v8.0.0, pay attention to the following when upgrading DM from versions earlier than v8.0.0:
18+
19+
- If plaintext passwords are used in both [data source configurations](/dm/dm-source-configuration-file.md) and [migration task configurations](/dm/task-configuration-file-full.md), no additional steps are required for the upgrade.
20+
- If encrypted passwords are used in [data source configurations](/dm/dm-source-configuration-file.md) and [migration task configurations](/dm/task-configuration-file-full.md) or if you want to use encrypted passwords in the future, you need to do the following:
21+
1. Add the `secret-key-path` parameter to the [DM-master configuration file](/dm/dm-master-configuration-file.md) and specify it as the path of your custom key file. The file must contain a 64-character hexadecimal AES-256 key. If the [fixed AES-256 secret key](https://github.com/pingcap/tiflow/blob/1252979421fc83ffa2a1548d981e505f7fc0b909/dm/pkg/encrypt/encrypt.go#L27) was used for encryption before upgrading, you can copy this secret key to your key file. Make sure all DM-master nodes use the same secret key configuration.
22+
2. Perform a rolling upgrade of DM-master first, followed by a rolling upgrade of DM-worker. For more information, see [Rolling upgrade](/dm/maintain-dm-using-tiup.md#rolling-upgrade).
23+
24+
## Update the secret key for encryption and decryption
25+
26+
To update the secret key used for encryption and decryption, take the following steps:
27+
28+
1. Update `secret-key-path` in the [DM-master configuration file](/dm/dm-master-configuration-file.md).
29+
30+
> **Note:**
31+
>
32+
> - Make sure all DM-master nodes are updated to the same secret key configuration.
33+
> - During the secret key update, do not create new [data source configuration files](/dm/dm-source-configuration-file.md) or [migration task configuration files](/dm/task-configuration-file-full.md).
34+
35+
2. Perform a rolling restart of DM-master.
36+
3. Use the passwords encrypted with `tiup dmctl encrypt` (dmctl version >= v8.0.0) when you create new [data source configuration files](/dm/dm-source-configuration-file.md) and [migration task configuration files](/dm/task-configuration-file-full.md).

dm/dm-export-import-config.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ summary: Learn how to export and import data sources and task configuration of c
99

1010
> **Note:**
1111
>
12-
> For clusters earlier than v2.0.5, you can use dmctl v2.0.5 or later to export and import the data source and task configuration files.
12+
> For clusters earlier than v2.0.5, you can use dmctl (>= v2.0.5 and < v8.0.0) to export and import the data source and task configuration files.
1313
1414
{{< copyable "" >}}
1515

dm/dm-manage-source.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@ This document introduces how to manage data source configurations, including enc
1111

1212
In DM configuration files, it is recommended to use the password encrypted with dmctl. For one original password, the encrypted password is different after each encryption.
1313

14+
> **Note:**
15+
>
16+
> Starting from v8.0.0, you must configure [`secret-key-path`](/dm/dm-master-configuration-file.md) for DM-master before using the `dmctl encrypt` command.
17+
1418
{{< copyable "shell-regular" >}}
1519

1620
```bash
17-
./dmctl -encrypt 'abc!@#123'
21+
./dmctl encrypt 'abc!@#123'
1822
```
1923

2024
```

dm/dm-master-configuration-file.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ join = ""
3434
ssl-ca = "/path/to/ca.pem"
3535
ssl-cert = "/path/to/cert.pem"
3636
ssl-key = "/path/to/key.pem"
37-
cert-allowed-cn = ["dm"]
37+
cert-allowed-cn = ["dm"]
38+
39+
secret-key-path = "/path/to/secret/key"
3840
```
3941

4042
## Configuration parameters
@@ -58,3 +60,4 @@ This section introduces the configuration parameters of DM-master.
5860
| `ssl-cert` | The path of the file that contains X509 certificate in PEM format for DM-master to connect with other components. |
5961
| `ssl-key` | The path of the file that contains X509 key in PEM format for DM-master to connect with other components. |
6062
| `cert-allowed-cn` | Common Name list. |
63+
| `secret-key-path` | The file path of the secret key, which is used to encrypt and decrypt upstream and downstream passwords. The file must contain a 64-character hexadecimal AES-256 secret key. |

dm/dmctl-introduction.md

-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ Available Commands:
4545
binlog-schema manage or show table schema in schema tracker
4646
check-task Checks the configuration file of the task
4747
config manage config operations
48-
decrypt Decrypts cipher text to plain text
4948
encrypt Encrypts plain text to cipher text
5049
help Gets help about any command
5150
list-member Lists member information
@@ -98,7 +97,6 @@ Available Commands:
9897
binlog-schema manage or show table schema in schema tracker
9998
check-task Checks the configuration file of the task
10099
config manage config operations
101-
decrypt Decrypts cipher text to plain text
102100
encrypt Encrypts plain text to cipher text
103101
help Gets help about any command
104102
list-member Lists member information

dm/maintain-dm-using-tiup.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ For example, to scale out a DM-worker node in the `prod-cluster` cluster, take t
183183
>
184184
> Before upgrading, you can use `config export` to export the configuration files of clusters. After upgrading, if you need to downgrade to an earlier version, you can first redeploy the earlier cluster and then use `config import` to import the previous configuration files.
185185
>
186-
> For clusters earlier than v2.0.5, you can use dmctl v2.0.5 or later to export and import the data source and task configuration files.
186+
> For clusters earlier than v2.0.5, you can use dmctl (>= v2.0.5 and < v8.0.0) to export and import the data source and task configuration files.
187187
>
188188
> For clusters later than v2.0.2, currently, it is not supported to automatically import the configuration related to relay worker. You can use `start-relay` command to manually [start relay log](/dm/relay-log.md#enable-and-disable-relay-log).
189189

@@ -193,6 +193,10 @@ The rolling upgrade process is made as transparent as possible to the applicatio
193193

194194
You can run the `tiup dm upgrade` command to upgrade a DM cluster. For example, the following command upgrades the cluster to `${version}`. Modify `${version}` to your needed version before running this command:
195195

196+
> **Note:**
197+
>
198+
> Starting from v8.0.0, DM removes the fixed secret key for encryption and decryption and enables you to customize a secret key for encryption and decryption. If encrypted passwords are used in [data source configurations](/dm/dm-source-configuration-file.md) and [migration task configurations](/dm/task-configuration-file-full.md) before the upgrade, you need to refer to the upgrade steps in [Customize a Secret Key for DM Encryption and Decryption](/dm/dm-customized-secret-key.md) for additional operations.
199+
196200
{{< copyable "shell-regular" >}}
197201

198202
```bash

dm/quick-start-create-source.md

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ A data source contains the information for accessing the upstream migration task
1919

2020
In DM configuration files, it is recommended to use the password encrypted with dmctl. You can follow the example below to obtain the encrypted password of the data source, which can be used to write the configuration file later.
2121

22+
Starting from v8.0.0, you must configure [`secret-key-path`](/dm/dm-master-configuration-file.md) for DM-master before using the `tiup dmctl encrypt` command.
23+
2224
{{< copyable "shell-regular" >}}
2325

2426
```bash

dm/quick-start-create-task.md

+4
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ Before starting a data migration task, you need to configure the MySQL data sour
9797

9898
For safety reasons, it is recommended to configure and use encrypted passwords. You can use dmctl to encrypt the MySQL/TiDB password. Suppose the password is "123456":
9999

100+
> **Note:**
101+
>
102+
> Starting from v8.0.0, you must configure [`secret-key-path`](/dm/dm-master-configuration-file.md) for DM-master before using the `dmctl encrypt` command.
103+
100104
{{< copyable "shell-regular" >}}
101105

102106
```bash

dm/quick-start-with-dm.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ You can use one or multiple MySQL instances as an upstream data source.
4848
from:
4949
host: "127.0.0.1"
5050
user: "root"
51-
password: "fCxfQ9XKCezSzuCD0Wf5dUD+LsKegSg=" # encrypt with `tiup dmctl --encrypt "123456"`
51+
password: "fCxfQ9XKCezSzuCD0Wf5dUD+LsKegSg="
5252
port: 3306
5353
```
5454

0 commit comments

Comments
 (0)