Using DEW to Acquire Access Credentials for OBS Read and Write in SparkJob Endpoints
What Is a Temporary Credential?
Temporary security credentials grant temporary access permissions. They include a temporary access key ID and secret access key (AK/SK) and a security token, which must be used together.
For details, see Temporary Security Credentials.
Scenarios
When a SparkJob endpoint accesses an OBS bucket, you must configure the AK/SK. To ensure AK/SK data security, we recommend using Cloud Secret Management Service (CSMS), a sub-service of Data Encryption Workshop (DEW), to centrally manage AKs/SKs. This prevents sensitive information leakage caused by hardcoding or plaintext configuration and security risks resulting from unauthorized access.
This section uses obtaining AK/SK to access OBS as an example to explain how to use DEW to acquire access credentials that a SparkJob endpoint needs to read and write OBS data.
Notes and Constraints
- You have configured an agency that allows AI DataLake to access DEW in the job and completed agency authorization. For details about how to create and configure a custom agency, see Creating a Custom Agency. The agency must be granted the following permissions:
Table 1 Permission description Permission
Description
csms:secretVersion:get
Permission to call the ShowSecretVersion API to retrieve the secret version and its value in DEW
csms:secretVersion:list
Permission to call the ListSecretVersions API to retrieve the list of secret versions in DEW
kms:dek:decrypt
Permission to decrypt secrets in DEW
- To use this function, you must configure the AK/SK for all OBS buckets involved. For details about how to obtain the AK/SK, see Access Keys.
- A shared secret has been created on the DEW console and the secret value has been stored. For details, see Creating a Shared Secret.
Syntax
On the job editing page of the SparkJob endpoint, set the following Spark parameters.
Different OBS buckets use different AK/SK authentication information. You can use the following configuration method to specify the AK/SK for each bucket. For details about the parameters, see Table 2.
1 2 3 4 5 6 7 8 9 10 | spark_config: { spark.hadoop.fs.obs.bucket.USER_BUCKET_NAME.dew.access.key: USER_AK_CSMS_KEY spark.hadoop.fs.obs.bucket.USER_BUCKET_NAME.dew.secret.key: USER_SK_CSMS_KEY spark.hadoop.fs.obs.security.provider: com.huawei.spark.provider.UserBasicCredentialProvider spark.hadoop.fs.dew.csms.secretName: CredentialName spark.hadoop.fs.dew.endpoint: ENDPOINT spark.hadoop.fs.dew.csms.version: VERSION_ID spark.hadoop.fs.dew.csms.cache.time.second: CACHE_TIME spark.hadoop.fs.dew.projectId: ProjectID } |
Parameter Description
| Parameter | Mandatory | Default Value | Data Type | Description |
|---|---|---|---|---|
| spark.hadoop.fs.obs.bucket.USER_BUCKET_NAME.dew.access.key | Yes | None | String | USER_BUCKET_NAME indicates the bucket name. Replace it with the actual OBS bucket name. The value of this parameter is the key you define in the CSMS shared secret. The corresponding value is your access key ID (AK). You must have permissions to access the OBS bucket. |
| spark.hadoop.fs.obs.bucket.USER_BUCKET_NAME.dew.secret.key | Yes | None | String | USER_BUCKET_NAME indicates the bucket name. Replace it with the actual OBS bucket name. The value of this parameter is the key you defined in the CSMS shared secret. The value corresponding to the key is your secret access key (SK). You must have the permission to access the specified OBS bucket. |
| spark.hadoop.fs.obs.security.provider | Yes | None | String | The OBS AK/SK authentication mechanism, which uses the secret management of CSMS, a sub-service of DEW, to obtain the AK and SK for accessing OBS. The default value is com.huawei.spark.provider.UserBasicCredentialProvider. |
| spark.hadoop.fs.dew.csms.secretName | Yes | None | String | The name of the shared secret created in DEW secret management. For details, see Creating a Shared Secret. Configuration example: spark.hadoop.fs.dew.csms.secretName: secretInfo |
| spark.hadoop.fs.dew.endpoint | Yes | None | String | The endpoint of the DEW service to use. For details, see Regions and Endpoints. Configuration example: spark.hadoop.fs.dew.endpoint: kms.cn-xxxx.myhuaweicloud.com |
| spark.hadoop.fs.dew.csms.version | Yes | Latest version | String | The version number (secret version identifier) of the shared secret created in DEW CSMS. If you do not specify the latest version number (secret version identifier), the system cannot directly retrieve the most recent version of the secret. This may lead to application access failures or the use of outdated secrets, thereby compromising data security and service stability. View the secret version information on the DEW console and set this parameter to the latest version number to ensure that applications can securely and reliably access the necessary data. Configuration example: spark.hadoop.fs.dew.csms.version: v1 |
| spark.hadoop.fs.dew.csms.cache.time.second | No | 3600 | Long | The cache duration after a Spark job obtains a CSMS shared secret. The unit is seconds. The default value is 3600 seconds. After the cache duration expires, the secret is obtained again. This behavior is different from expiration. |
| spark.hadoop.fs.dew.projectId | No | Yes | String | The ID of the project where DEW is deployed. The default value is the ID of the project where the Spark job is located. For details, see Obtaining a Project ID. |
Configuration Example
This section provides a Java code example to demonstrate how to process DataGen data and write it to OBS. Modify the parameter settings based on your actual environment.
- Create an agency for AI DataLake to access DEW, and complete the agency authorization.
For details, see Creating a Custom Agency.
- Create a shared secret in DEW. For details, see Creating a Shared Secret.
- Set job parameters on the AI DataLake Spark JAR job editing page.
Spark parameters:
spark.hadoop.fs.obs.bucket.USER_BUCKET_NAME.dew.access.key:USER_AK_CSMS_KEY spark.hadoop.fs.obs.bucket.USER_BUCKET_NAME.dew.secret.key: USER_SK_CSMS_KEY spark.hadoop.fs.obs.security.provider :com.huawei.spark.provider.UserBasicCredentialProvider spark.hadoop.fs.dew.csms.secretName:secretInfo-test spark.hadoop.fs.dew.endpoint:https://kms.cn-north-7.myhuaweicloud.com spark.hadoop.fs.dew.csms.version:v1 spark.hadoop.fs.dew.csms.cache.time.second:3600 spark.hadoop.fs.dew.projectId:4cf650fd46704908aa071b4df******
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