이 페이지에서는 Cloud KMS에서 암호화 키를 사용하여 Google에서 제공하는 템플릿 파라미터의 민감한 정보를 암호화하는 방법을 설명합니다.
개요
Google에서 제공하는 일부 템플릿을 사용하면 사용자 이름, 비밀번호, JDBC 연결 문자열, API 키와 같은 템플릿 파라미터의 민감한 정보를 암호화할 수 있습니다. 지원되는 경우 이러한 템플릿에는 다음과 같은 Cloud KMS 암호화 키를 지정하는 파라미터가 포함됩니다.
작업을 실행하면 작업 로그에 다음과 유사한 PERMISSION_DENIED 오류가 표시됩니다.
PERMISSION_DENIED: Permission cloudkms.cryptoKeyVersions.useToDecrypt denied on
resource RESOURCE_PATH (or it may not exist)
데이터를 복호화하려면 Dataflow 작업자 서비스 계정에 암호화 키에 대한 cloudkms.cryptoKeyVersions.useToDecrypt 권한이 필요합니다. 작업자 서비스 계정에 Cloud KMS CryptoKey 복호화 역할이 있는지 확인합니다. 자세한 내용은 Dataflow 보안 및 권한을 참조하세요.
[[["이해하기 쉬움","easyToUnderstand","thumb-up"],["문제가 해결됨","solvedMyProblem","thumb-up"],["기타","otherUp","thumb-up"]],[["이해하기 어려움","hardToUnderstand","thumb-down"],["잘못된 정보 또는 샘플 코드","incorrectInformationOrSampleCode","thumb-down"],["필요한 정보/샘플이 없음","missingTheInformationSamplesINeed","thumb-down"],["번역 문제","translationIssue","thumb-down"],["기타","otherDown","thumb-down"]],["최종 업데이트: 2025-09-04(UTC)"],[[["\u003cp\u003eThis page guides users on encrypting sensitive data in Google-provided template parameters using Cloud KMS encryption keys.\u003c/p\u003e\n"],["\u003cp\u003eDataflow worker service accounts require the \u003cstrong\u003eCloud KMS CryptoKey Decrypter\u003c/strong\u003e role to decrypt the data.\u003c/p\u003e\n"],["\u003cp\u003eTo encrypt data, users must create an encryption key, encrypt the data, base64-encode it, and then specify the key and encrypted values when running the template.\u003c/p\u003e\n"],["\u003cp\u003eIf an encryption key is specified, all parameters supporting encryption must be encrypted.\u003c/p\u003e\n"],["\u003cp\u003eA troubleshooting section is included to address common issues such as \u003ccode\u003ePERMISSION_DENIED\u003c/code\u003e errors encountered when running the job, which is caused by a lack of the proper permissions for the Dataflow worker service account.\u003c/p\u003e\n"]]],[],null,["# Encrypt template parameters by using Cloud KMS\n\nThis page explains how to encrypt sensitive data in Google-provided template\nparameters, by using encryption keys with Cloud KMS.\n\nOverview\n--------\n\nSome Google-provided templates enable you to encrypt sensitive data in the\ntemplate parameters, such as usernames, passwords, JDBC connection strings, and\nAPI keys. When supported, these templates include a parameter to specify the\nCloud KMS encryption key, such as:\n\n- `KMSEncryptionKey`\n- `tokenKMSEncryptionKey`\n- `apiKeyKMSEncryptionKey`\n\nTo use Cloud KMS encryption keys with these templates, perform the\nfollowing steps:\n\n1. Grant the Dataflow [worker service account](/dataflow/docs/concepts/security-and-permissions#worker-service-account) the [**Cloud KMS CryptoKey Decrypter**](/kms/docs/reference/permissions-and-roles#predefined) role.\n2. [Create an encryption key](/kms/docs/create-encryption-keys).\n3. Use the key to encrypt the data.\n4. Base64-encode the encrypted data.\n5. When you run the template, specify the encryption key and use the encrypted parameter values.\n\nIf you specify an encryption key, you must encrypt all of the parameters that\nsupport encryption. To understand which parameters can be encrypted, see the\ndocumentation for the specific template.\n\nExample\n-------\n\nThe following example uses the\n[MySQL to BigQuery](/dataflow/docs/guides/templates/provided/mysql-to-bigquery)\ntemplate.\n\n1. Create a key ring.\n\n gcloud kms keyrings create \"\u003cvar translate=\"no\"\u003eKEY_RING_NAME\u003c/var\u003e\" \\\n --location \"global\"\n\n2. Create an encryption key.\n\n gcloud kms keys create \"\u003cvar translate=\"no\"\u003eKEY_NAME\u003c/var\u003e\" \\\n --location \"global\" \\\n --keyring \"\u003cvar translate=\"no\"\u003eKEY_RING_NAME\u003c/var\u003e\" \\\n --purpose \"encryption\"\n\n3. Encrypt and base64-encode the username, password, and JDBC connection string.\n\n export USER_NAME=`echo -n \"\u003cvar translate=\"no\"\u003eUSER_NAME\u003c/var\u003e\" \\\n | gcloud kms encrypt --key=quickstart --keyring=test --location=global --plaintext-file=- --ciphertext-file=- \\\n | base64 -w 0`\n export PASSWORD=`echo -n \"\u003cvar translate=\"no\"\u003ePASSWORD\u003c/var\u003e\" \\\n | gcloud kms encrypt --key=quickstart --keyring=test --location=global --plaintext-file=- --ciphertext-file=- \\\n | base64 -w 0`\n export CONNECTION_STRING=`echo -n \"\u003cvar translate=\"no\"\u003eCONNECTION_STRING\u003c/var\u003e\" \\\n | gcloud kms encrypt --key=quickstart --keyring=test --location=global --plaintext-file=- --ciphertext-file=- \\\n | base64 -w 0`\n\n4. Run the template.\n\n gcloud dataflow flex-template run mysql-job \\\n --project=\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e \\\n --region=us-central1 \\\n --template-file-gcs-location=gs://dataflow-templates-us-central1/latest/flex/MySQL_to_BigQuery \\\n --parameters \\\n connectionURL=\"$CONNECTION_STRING\",\\\n query=\"\u003cvar translate=\"no\"\u003eSOURCE_SQL_QUERY\u003c/var\u003e\",\\\n outputTable=\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e:\u003cvar translate=\"no\"\u003eDATASET\u003c/var\u003e.\u003cvar translate=\"no\"\u003eTABLE_NAME\u003c/var\u003e,\\\n bigQueryLoadingTemporaryDirectory=\u003cvar translate=\"no\"\u003eCLOUD_STORAGE_PATH\u003c/var\u003e,\\\n username=\"$USER_NAME\",\\\n password=\"$PASSWORD\",\\\n KMSEncryptionKey=projects/\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e/locations/global/keyRings/\u003cvar translate=\"no\"\u003eKEY_RING_NAME\u003c/var\u003e/cryptoKeys/\u003cvar translate=\"no\"\u003eKEY_NAME\u003c/var\u003e\n\nTroubleshooting\n---------------\n\nThis section contains troubleshooting information for encrypting template\nparameters.\n\n### Permission denied\n\nWhen you run the job, you see a `PERMISSION_DENIED` error in the job logs,\nsimilar to the following: \n\n PERMISSION_DENIED: Permission cloudkms.cryptoKeyVersions.useToDecrypt denied on\n resource \u003cvar translate=\"no\"\u003eRESOURCE_PATH\u003c/var\u003e (or it may not exist)\n\nTo decrypt the data, the Dataflow worker service account needs\nthe **cloudkms.cryptoKeyVersions.useToDecrypt** permission for the encryption\nkey. Make sure the worker service account has the\n**Cloud KMS CryptoKey Decrypter** role. For more information, see\n[Dataflow security and permissions](/dataflow/docs/concepts/security-and-permissions).\n\nWhat's next\n-----------\n\n- Learn more about [Cloud Key Management Service](/kms/docs/key-management-service).\n- See the list of [Google-provided templates](/dataflow/docs/guides/templates/provided-templates)."]]