Introduction

In most production environments, sensitive configuration items such as passwords are required to be encrypted and cannot be stored in plain text, SeaTunnel provides a convenient one-stop solution for this.

How to use

SeaTunnel comes with the function of base64 encryption and decryption, but it is not recommended for production use, it is recommended that users implement custom encryption and decryption logic. You can refer to this chapter How to implement user-defined encryption and decryption get more details about it.

Base64 encryption support encrypt the following parameters:

  • username
  • password
  • auth

Next, I’ll show how to quickly use SeaTunnel’s own base64 encryption:

  1. And a new option shade.identifier in env block of config file, this option indicate what the encryption method that you want to use, in this example, we should add shade.identifier = base64 in config as the following shown:

    1. #
    2. # Licensed to the Apache Software Foundation (ASF) under one or more
    3. # contributor license agreements. See the NOTICE file distributed with
    4. # this work for additional information regarding copyright ownership.
    5. # The ASF licenses this file to You under the Apache License, Version 2.0
    6. # (the "License"); you may not use this file except in compliance with
    7. # the License. You may obtain a copy of the License at
    8. #
    9. # http://www.apache.org/licenses/LICENSE-2.0
    10. #
    11. # Unless required by applicable law or agreed to in writing, software
    12. # distributed under the License is distributed on an "AS IS" BASIS,
    13. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14. # See the License for the specific language governing permissions and
    15. # limitations under the License.
    16. #
    17. env {
    18. parallelism = 1
    19. shade.identifier = "base64"
    20. }
    21. source {
    22. MySQL-CDC {
    23. result_table_name = "fake"
    24. parallelism = 1
    25. server-id = 5656
    26. port = 56725
    27. hostname = "127.0.0.1"
    28. username = "seatunnel"
    29. password = "seatunnel_password"
    30. database-name = "inventory_vwyw0n"
    31. table-name = "products"
    32. base-url = "jdbc:mysql://localhost:56725"
    33. }
    34. }
    35. transform {
    36. }
    37. sink {
    38. # choose stdout output plugin to output data to console
    39. Clickhouse {
    40. host = "localhost:8123"
    41. database = "default"
    42. table = "fake_all"
    43. username = "seatunnel"
    44. password = "seatunnel_password"
    45. # cdc options
    46. primary_key = "id"
    47. support_upsert = true
    48. }
    49. }
  2. Using the shell based on different calculate engine to encrypt config file, in this example we use zeta:

    1. ${SEATUNNEL_HOME}/bin/seatunnel.sh --config config/v2.batch.template --encrypt

    Then you can see the encrypted configuration file in the terminal:

    1. 2023-02-20 17:50:58,319 INFO org.apache.seatunnel.core.starter.command.ConfEncryptCommand - Encrypt config:
    2. {
    3. "env" : {
    4. "parallelism" : 1,
    5. "shade.identifier" : "base64"
    6. },
    7. "source" : [
    8. {
    9. "base-url" : "jdbc:mysql://localhost:56725",
    10. "hostname" : "127.0.0.1",
    11. "password" : "c2VhdHVubmVsX3Bhc3N3b3Jk",
    12. "port" : 56725,
    13. "database-name" : "inventory_vwyw0n",
    14. "parallelism" : 1,
    15. "result_table_name" : "fake",
    16. "table-name" : "products",
    17. "plugin_name" : "MySQL-CDC",
    18. "server-id" : 5656,
    19. "username" : "c2VhdHVubmVs"
    20. }
    21. ],
    22. "transform" : [],
    23. "sink" : [
    24. {
    25. "database" : "default",
    26. "password" : "c2VhdHVubmVsX3Bhc3N3b3Jk",
    27. "support_upsert" : true,
    28. "host" : "localhost:8123",
    29. "plugin_name" : "Clickhouse",
    30. "primary_key" : "id",
    31. "table" : "fake_all",
    32. "username" : "c2VhdHVubmVs"
    33. }
    34. ]
    35. }
  3. Of course, not only encrypted configuration files are supported, but if the user wants to see the decrypted configuration file, you can execute this command:

    1. ${SEATUNNEL_HOME}/bin/seatunnel.sh --config config/v2.batch.template --decrypt

How to implement user-defined encryption and decryption

If you want to customize the encryption method and the configuration of the encryption, this section will help you to solve the problem.

  1. Create a java maven project

  2. Add seatunnel-api module in dependencies like the following shown:

    1. <dependency>
    2. <groupId>org.apache.seatunnel</groupId>
    3. <artifactId>seatunnel-api</artifactId>
    4. <version>${seatunnel.version}</version>
    5. </dependency>
  3. Create a new class and implement interface ConfigShade, this interface has the following methods:

    1. /**
    2. * The interface that provides the ability to encrypt and decrypt {@link
    3. * org.apache.seatunnel.shade.com.typesafe.config.Config}
    4. */
    5. public interface ConfigShade {
    6. /**
    7. * The unique identifier of the current interface, used it to select the correct {@link
    8. * ConfigShade}
    9. */
    10. String getIdentifier();
    11. /**
    12. * Encrypt the content
    13. *
    14. * @param content The content to encrypt
    15. */
    16. String encrypt(String content);
    17. /**
    18. * Decrypt the content
    19. *
    20. * @param content The content to decrypt
    21. */
    22. String decrypt(String content);
    23. /** To expand the options that user want to encrypt */
    24. default String[] sensitiveOptions() {
    25. return new String[0];
    26. }
    27. }
  4. Add org.apache.seatunnel.api.configuration.ConfigShade in resources/META-INF/services
  5. Package it to jar and add jar to ${SEATUNNEL_HOME}/lib
  6. Change the option shade.identifier to the value that you defined in ConfigShade#getIdentifierof you config file, please enjoy it \^_\^