Google Cloud Platform - Dataflow 不会使用 KMS 密钥解密数据



我有一个使用Apache Beam编写的Dataflow作业。它看起来类似于这个模板,但它将数据从JDBC保存到云存储:

https://github.com/GoogleCloudPlatform/DataflowTemplates/blob/master/src/main/java/com/google/cloud/teleport/templates/JdbcToBigQuery.java

我的问题是,每个人都可以在Dataflow UI中看到数据库凭据。所以我找到了文章

https://medium.com/google-cloud/using-google-cloud-key-management-service-with-dataflow-templates-71924f0f841f

社区展示如何加密这些数据。我做了与本文中类似的一切,但我的Dataflow工作不想在给定KMS密钥的情况下解密凭据(当我使用Cloud Function运行它时(。

所以我试着在Cloud Shell 中运行它

gcloud dataflow jobs run JOB_NAME 
--region=us-west1 
--gcs-location=TEMPLATE_LOCATION 
--dataflow-kms-key=projects/PROJECT_ID/locations/us-west1/keyRings/KEY_RING/cryptoKeys/KEY_NAME 
--parameters=...,KMSEncryptionKey=projects/PROJECT_ID/locations/us-west1/keyRings/KEY_RING/cryptoKeys/KEY_NAME,...

但是我有一个错误

Error message from worker: java.lang.RuntimeException: org.apache.beam.sdk.util.UserCodeException: com.google.api.gax.rpc.PermissionDeniedException: io.grpc.StatusRuntimeException: PERMISSION_DENIED: Permission 'cloudkms.cryptoKeyVersions.useToDecrypt' denied on resource 'projects/PROJECT_ID/locations/us-west1/keyRings/KEY_RING/cryptoKeys/KEY_NAME' (or it may not exist).

我完全被卡住了。有没有人遇到过同样的问题,可以提供帮助?

您需要确保已将Cloud KMS CryptoKey Encrypter/Decryptor角色分配给Dataflow服务帐户以及计算引擎服务帐户。

请参阅本文档,带有Dataflow 的云密钥管理服务(Cloud KMS(加密密钥

如果使用云功能,可能还需要向谷歌云功能服务代理服务帐户分配使用KMS加密和解密的权限。

确保调用加密和解密方法的用户具有cl将Cloud KMS CryptoKey Encrypter/Decryptor角色分配给数据流服务帐户.oudkms.cryptoKeyVersions.useToEncrypt和cloudkms.cryptoKeyVersions.useToDecrypt对用于加密或解密。

允许用户加密或解密的一种方法是将用户添加到角色/cloudkms.cryptoKeyEncrypter,roles/cloudkms.cryptoKeyDecryptor,或roles/cloudkms.cryptoKeyEncrypterDecryptor

还要确保传递的参数是正确的;

PYTHON

python -m apache_beam.examples.wordcount 
--input gs://dataflow-samples/shakespeare/kinglear.txt 
--output gs://STORAGE_BUCKET/counts 
--runner DataflowRunner 
--project PROJECT_ID 
--temp_location gs://STORAGE_BUCKET/tmp/ 
--dataflow_kms_key=KMS_KEY

JAVA

mvn compile exec:java -Dexec.mainClass=org.apache.beam.examples.WordCount 
-Dexec.args="--inputFile=gs://dataflow-samples/shakespeare/kinglear.txt 
--output=gs://STORAGE_BUCKET/counts 
--runner=DataflowRunner --project=PROJECT_ID 
--gcpTempLocation=gs://STORAGE_BUCKET/tmp 
--dataflowKmsKey=KMS_KEY"
-Pdataflow-runner

指定管道执行参数

最新更新