Using DEW to Manage Access Credentials in Flink SQL
Scenarios
When AI DataLake writes Flink job output data to a MySQL database or DWS, you must configure sensitive parameters, such as usernames and passwords, in the connector. Storing this information in plaintext poses significant security risks. To safeguard data privacy, encrypt these credentials.
Data Encryption Workshop (DEW) and Cloud Secret Management Service (CSMS) offer a secure, reliable, and easy-to-use solution for encrypting and decrypting sensitive data. By storing database credentials (such as usernames and passwords) as managed secrets, you can securely reference them in Flink jobs. This ensures that sensitive information is retrieved through a secure channel at runtime.
Additionally, CSMS offers comprehensive lifecycle management for credentials, enhancing both security and efficiency. It effectively mitigates risks associated with hardcoding sensitive information or storing it in plaintext configurations, thereby preventing unauthorized access and potential business disruptions.
This section walks you through how to use DEW to manage access credentials for Flink SQL jobs.
Prerequisites
- A shared secret has been created on the DEW console, and its value has been stored. For details, see Creating a Shared Secret.
- Ensure that you have created an agency that allows AI DataLake to access DEW and completed the Flink endpoint authorization. The agency must have the following permissions:
- ShowSecretVersion permission for querying secret versions and secret values in DEW: csms:secretVersion:get
- ListSecretVersions permission for listing secret versions in DEW: csms:secretVersion:list
- Permission to decrypt DEW secrets: kms:dek:decrypt
For agency permission examples, see Creating a Custom Agency and Agency Permission Policies for Common Scenarios.
Syntax
create table tableName(
attr_name attr_type
(',' attr_name attr_type)*
(',' WATERMARK FOR rowtime_column_name AS watermark-strategy_expression)
)
with (
...
'dew.endpoint'='',
'dew.csms.secretName'='',
'dew.csms.decrypt.fields'='',
'dew.projectId'='',
'dew.csms.version'=''
); Parameter Description
| Parameter | Mandatory | Default Value | Data Type | Description |
|---|---|---|---|---|
| dew.endpoint | Yes | None | String | The endpoint of the DEW service to use. For details, see Regions and Endpoints. Configuration example: 'dew.endpoint'='kms.cn-xxxx.myhuaweicloud.com' |
| dew.projectId | No | The project ID of the target Flink job | String | The ID of the project where the DEW service is deployed. For details, see Obtaining a Project ID. |
| dew.csms.secretName | Yes | None | String | The name of the shared secret created in DEW secret management. Configuration example: 'dew.csms.secretName'='secretInfo' |
| dew.csms.decrypt.fields | Yes | None | String | Connector fields with the with attribute that require decryption using DEW CSMS. Separate field attributes with commas, for example, 'dew.csms.decrypt.fields'='field1,field2,field3'. |
| dew.csms.version | No | Latest version | String | The version number (secret version identifier) of the shared secret created in DEW CSMS.
|
Example
This example describes how to use DEW to manage access credentials in Flink SQL. In this example, random data is generated using the DataGen table and written to the MySQL result table.
- Create a shared secret in DEW. For details, see Creating a Shared Secret.
- Secret Name: Enter the name of the secret you want to create. In this example, set the secret name to secretInfo.
- Secret Value: Enter the username and password used to log in to the RDS for MySQL DB instance.
- The key in the first line is MySQLUsername, and the value is the username used to log in to the DB instance.
- The key in the second line is MySQLPassword, and the value is the password used to log in to the DB instance.
Figure 1 Setting the secret values
- Configure DEW to manage access credentials in Flink SQL jobs.
Ensure that you have created an agency that allows AI DataLake to access DEW and completed the corresponding agency authorization. For details, see Creating a Custom Agency and Agency Permission Policies for Common Scenarios.
The following example shows the Flink SQL job configuration:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
create table dataGenSource( user_id string, amount int ) with ( 'connector' = 'datagen', 'rows-per-second' = '1', --Generate one data record per second. 'fields.user_id.kind' = 'random', --Specify a random generator for the user_id field. 'fields.user_id.length' = '3' --Limit the length of user_id to 3 characters. ); CREATE TABLE jdbcSink ( user_id string, amount int ) WITH ( 'connector' = 'jdbc', 'url' = 'jdbc:mysql://MySQLAddress:MySQLPort/flink',--In the URL, flink indicates the name of the MySQL database where the orders table is located. 'table-name' = 'orders', 'username' = 'MySQLUsername', -- Shared secret in DEW with the secret name secretInfo and version v1. Set the key for the shared secret value to MySQLUsername and the value to your sensitive information. 'password' = 'MySQLPassword', -- Shared secret in DEW with the secret name secretInfo and version v1. Set the key for the shared secret value to MySQLPassword and the value to your sensitive information. 'sink.buffer-flush.max-rows' = '1', 'dew.endpoint'='endpoint', --Endpoint information for the DEW service being used 'dew.csms.secretName'='secretInfo', --Name of the shared secret in DEW 'dew.csms.decrypt.fields'='username,password', --The username,password field value must be decrypted and replaced using DEW secret management. 'dew.csms.version'='v1' ); insert into jdbcSink select * from dataGenSource;
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot