在 Google Cloud dataproc 中使用非默认服务帐户

Using non-default service account in Google Cloud dataproc

我想创建一个 运行 在非默认服务帐户下的数据处理集群。以下适用于计算实例:

gcloud compute instances create instance-1 --machine-type "n1-standard-1" --zone "europe-west1-b" --scopes xxxxxxxx@yyyyyyyy.iam.gserviceaccount.com="https://www.googleapis.com/auth/cloud-platform"

但是相同的 --scopes 参数在创建 dataproc 实例时失败了:

gcloud dataproc clusters create --zone "europe-west1-b" --scopes xxxxxxxx@yyyyyyyy.iam.gserviceaccount.com="https://www.googleapis.com/auth/cloud-platform" testdataproc12345

ERROR: (gcloud.dataproc.clusters.create) Invalid service account scope: 'xxxxxxxxx@yyyyyyyy.iam.gserviceaccount.com=https://www.googleapis.com/auth/cloud-platform'

是否可以在非默认服务帐户下 运行 dataproc?

遗憾的是,目前无法使用正常的 "scopes and metadata" 介导的身份验证设置来指定您的自定义服务帐户。但是,这是一个已知的功能请求,因此它应该会在未来的 Dataproc 更新中可用。

同时,即使您在使用 Dataproc 时无法使用默认 GCE 服务帐户禁用 "storage read/write" 范围的存在,您也可以通过密钥文件让 Hadoop 端使用特定服务帐户使用 IAM & Admin > Service accounts 页面下的 "Create Key" 选项为您的服务帐户获取 JSON 密钥文件,然后做两件事:

  1. 在集群创建时添加以下内容属性:

    --properties core:fs.gs.auth.service.account.json.keyfile=/etc/hadoop/conf/my-service-account.json
    
  2. 使用 init 操作将您的 JSON 密钥文件复制到您的节点;请注意,这仍然意味着您的 JSON 密钥文件必须可以作为 reader 的 GCE 默认服务帐户访问,并且任何有权访问您的 JSON 密钥文件的 GCS 位置的人也有能力现在代表该服务帐户行事,因此您仍需要根据需要确保项目安全。

    #!/bin/bash
    # Save this somewhere as gs://somepath/my-keyfile-setup.sh
    
    gsutil cp gs://path/to/your/json/file/in/gcs/my=service-account.json \
        /etc/hadoop/conf/my-service-account.json
    

    然后应用初始化操作:

    gcloud dataproc clusters create --initialization-actions gs://somepath/my-keyfile-setup.sh ...