我可以传递密钥文件作为参数以使用 gsutil 连接到 Google Cloud Storage 吗?

Can I pass a key file as parameter to connect to Google Cloud Storage using gsutil?

当我使用 gsutil 连接到 Google Cloud Storage 上的存储桶时,我通常使用以下命令:

gcloud auth activate-service-account --key-file="pathKeyFile"

同一台机器上运行的两个脚本同时需要两个不同的Service Account怎么办?

我想使用如下命令:

gsutil ls mybucket --key-file="mykeyspath"

我这样说是因为如果我的脚本是 运行 并且另一个脚本更改了实际上处于活动状态的服务帐户,我的脚本将不再具有访问存储桶的权限。

您可以使用 BOTO file. You can create one as explained in the documentation 来做到这一点。

然后您可以在 运行 您的 gsutil 命令时指定要使用的文件(这里是 linux 中的示例)

# if you have several GSUTIL command to run
export BOTO_CONFIG=/path/to/.botoMyBucket
gsutil ls myBucket

# For only one command, you can define an env var inline like this
BOTO_CONFIG=/path/to/.botoMyBucket2 gsutil ls myBucket2