如何获取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,以便我可以为其分配足够的角色?
提前致谢。
编辑
一步一步:
- 下载 juicefs-csi helm chart
- 按照问题中的描述添加值,应用
- 创建一个从具有
juicefs-sc
存储 class 的 PV 挂载的 pod
- 尝试read/write文件到挂载点
好吧我一开始误会你了
创建 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 Engine
和 Storage
提供适当的权限。有关如何创建 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。
有用的链接
- Configuring Velero - Velero 是用于备份和恢复的软件,但是那里提到了步骤 2 和 3。您只需要根据您的情况调整 commands/permissions。
- Authenticating to Google Cloud with service accounts
我在 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,以便我可以为其分配足够的角色?
提前致谢。
编辑
一步一步:
- 下载 juicefs-csi helm chart
- 按照问题中的描述添加值,应用
- 创建一个从具有
juicefs-sc
存储 class 的 PV 挂载的 pod
- 尝试read/write文件到挂载点
好吧我一开始误会你了
创建 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 APISet access for each API
在您的情况下,您可以只使用 Set access for each API
并将 Storage
更改为 Full
。
2。使用服务帐户设置权限
您需要创建一个新的 Service Account
并为 Compute Engine
和 Storage
提供适当的权限。有关如何创建 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。
有用的链接
- Configuring Velero - Velero 是用于备份和恢复的软件,但是那里提到了步骤 2 和 3。您只需要根据您的情况调整 commands/permissions。
- Authenticating to Google Cloud with service accounts