尝试 Google API Buckets:特定服务帐户的 testIamPermissions

try Google API Buckets: testIamPermissions for a specific service account

我可以使用 Buckets: testIamPermissions 来测试登录用户对存储桶的权限。

有什么方法可以测试服务帐户吗?

如有任何帮助,我们将不胜感激。谢谢...

Google documentation所述:

To see if a service account has access to a resource, call the getIamPolicy method on the target resource. For example, to view grants for a project, call the projects.getIamPolicy method.

因此,要检查服务帐户是否有权访问存储桶,您必须使用 Buckets: getIamPolicy 指定要检查的存储桶。

再次查看您的问题后,我找到了一种将 Buckets: testIamPermissions 与服务帐户一起使用的方法:

您必须在您的环境中下载 service account’s key.json file(设置 gcloud)并创建一个环境变量:

GOOGLE_APPLICATION_CREDENTIALS=[key.json]

然后,您可以通过以下方式获取此服务帐户的令牌:

gcloud auth application-default print-access-token

最后,您可以 curl testIamPermissions URL 并将该令牌作为授权传递 header:

curl 'https://www.googleapis.com/storage/v1/b/[BUCKET]/iam/testPermissions?permissions=[PERMISSION]'   -H 'Authorization: Bearer [TOKEN]’