如何获取juicefs使用的IAM/service账号访问GKE中的GCS?

How to get IAM/service account used by juicefs to access GCS in GKE?

我在 GKE 中使用 juicefs-csi。我使用 postgre 作为元存储,使用 GCS 作为存储。对应设置如下:

node:
  # ...
  storageClasses:
    - name: juicefs-sc
      enabled: true
      reclaimPolicy: Retain
      backend:
        name: juicefs
        metaurl: postgres://user:password@my-ec2-where-postgre-installed.ap-southeast-1.compute.amazonaws.com:5432/the-database?sslmode=disable
        storage: gs
        bucket: gs://my-bucket
   # ...

根据 this 文档,我不必指定访问权限 key/secret(就像在 S3 中一样)。

但不幸的是,每当我尝试向已安装的卷(使用 juicefs-sc 存储 class)写入任何内容时,我总是会收到此错误:

AccessDeniedException: 403 Caller does not have storage.objects.create access to the Google Cloud Storage object.

我觉得应该和IAM角色有关。

我的问题是,我怎么知道 juicefs 使用哪个 IAM user/service 帐户访问 GCS,以便我可以为其分配足够的角色?

提前致谢。

编辑

一步一步:

好吧我一开始误会你了

创建 GKE 集群时,您可以指定此集群将使用哪个 GCP Service Account,如下所示:

Default Compute Engine default service account (71025XXXXXX-compute@developer.gserviceaccount.com) 缺少一些云产品权限(如 Cloud Storage,它有 Read Only).这条消息中甚至对此进行了描述。

如果您想检查哪个 Service Account 默认设置为 VM,您可以通过

Compute Engine > VM 实例 > 从该集群中选择一个 VM > 在详细信息中找到 API and identity management

所以你有 3 个选项来解决这个问题:

1.集群创建期间

Node Pools > Security 中,您有 Access scopes 可以在其中添加一些额外的权限。

  • Allow full access to all Cloud APIs 允许访问所有列出的 Cloud API
  • Set access for each API

在您的情况下,您可以只使用 Set access for each API 并将 Storage 更改为 Full

2。使用服务帐户设置权限 您需要创建一个新的 Service Account 并为 Compute EngineStorage 提供适当的权限。有关如何创建 SA 的更多详细信息,您可以在 Creating and managing service accounts.

中找到

3。使用工作负载身份

Workload Identity on your Google Kubernetes Engine (GKE) clusters. Workload Identity allows workloads in your GKE clusters to impersonate Identity and Access Management (IAM) service accounts to access Google Cloud services.

有关更多详细信息,您应该查看 Using Workload Identity

有用的链接