ML 引擎无法访问存储桶中的 job_dir 目录

ML-Engine unable to access job_dir directory in bucket

我正在尝试使用 gcloud 提交一份用于 ML-Engine 培训的作业,但 运行 我遇到了一个我无法弄清楚的服务帐户权限错误。模型代码存在于 Compute Engine 实例上,我从中 运行ning gcloud ml-engine jobs submit 作为 bash 脚本的一部分。我已经为 VM 实例上的 gcloud 身份验证创建了一个服务帐户 (ai-platform-developer@....iam.gserviceaccount.com),并为作业和模型数据创建了一个存储桶。服务帐户已被授予存储桶的存储对象查看者和存储对象创建者角色,VM 和存储桶都属于同一个项目。

当我尝试按 this tutorial 提交作业时,将执行以下操作:

time_stamp=`date +"%Y%m%d_%H%M"`
job_name='ObjectDetection_'${time_stamp}

gsutil cp object_detection/samples/configs/faster_rcnn_resnet50.config 
gs://[bucket-name]/training_configs/faster-rcnn-resnet50.${job_name}.config

gcloud ml-engine jobs submit training ${job_name} \
    --project [project-name] \
    --runtime-version 1.12 \
    --job-dir=gs://[bucket-name]/jobs/${job_name} \
    --packages dist/object_detection-0.1.tar.gz,slim/dist/slim-0.1.tar.gz,/tmp/pycocotools/pycocotools-2.0.tar.gz \
    --module-name object_detection.model_main \
    --region us-central1 \
    --config object_detection/training-config.yml \
    -- \
    --model_dir=gs://[bucket-name]/output/${job_name}} \
    --pipeline_config_path=gs://[bucket-name]/training_configs/faster-rcnn-resnet50.${job_name}.config

其中 [bucket-name] 和 [project-name] 是上面创建的存储桶以及它和 VM 所在的项目的占位符。

配置文件已成功上传到存储桶,我可以确认它存在于云控制台中。但是,作业未能提交并出现以下错误:

ERROR: (gcloud.ml-engine.jobs.submit.training) User [ai-platform-developer@....iam.gserviceaccount.com] does not have permission to access project [project-name] (or it may not exist): Field: job_dir Error: You don't have the permission to access the provided directory 'gs://[bucket-name]/jobs/ObjectDetection_20190709_2001'
- '@type': type.googleapis.com/google.rpc.BadRequest
  fieldViolations:
  - description: You don't have the permission to access the provided directory 'gs://[bucket-name]/jobs/ObjectDetection_20190709_2001'
    field: job_dir

如果我查看云控制台,--packages 指定的文件存在于该位置,并且我确保服务帐户 ai-platform-developer@....iam.gserviceaccount.com 已获得存储对象查看器和存储对象创建器存储桶的角色,它设置了存储桶级别的权限。确保服务帐号已激活且默认后,我也可以 运行

gsutil ls gs://[bucket-name]/jobs/ObjectDetection_20190709_2001

成功returns文件夹内容无权限错误。在项目中,存在一个托管服务帐户 service-[project-number]@cloud-ml.google.com.iam.gserviceaccount.com,我还授予此帐户存储对象存储对象查看者和存储对象创建者角色。

为了确认此 VM 能够提交作业,我可以将 gcloud 用户切换到我的个人帐户和脚本 运行s 并提交作业而不会出现任何错误。但是,由于这存在于共享 VM 中,我想依赖服务帐户授权而不是我自己的用户帐户。

您是否尝试查看 Compute Engine 范围? 关闭实例,编辑 Cloud API access scopes 并将其更改为: Allow full access to all Cloud APIs

我遇到了类似的问题,但错误完全相同。

我发现解决这些错误的最简单方法是转到 "Logging" 并搜索 "PERMISSION DENIED" 文本。

在我的案例中,服务帐户缺少权限 "storage.buckets.get"。然后你需要找到一个有这个权限的角色。您可以从 IAM-> 角色执行此操作。在该视图中,您可以按权限名称过滤角色。事实证明,只有以下角色具有所需的权限:

  • 存储管理员
  • 存储旧桶所有者
  • 存储旧存储桶Reader
  • Storage Legacy Bucket Writer

我将 "Storage Legacy Bucket Writer" 角色添加到存储桶中的服务帐户,然后能够提交作业。