我想在Docker容器中使用gsutil。我创建了一个O2Auth服务帐户JSON文件。
如何设置gsutil auth以使用JSON配置文件并在不提示的情况下执行命令?
目前我得到的是这样的:
$ gsutil config -e
It looks like you are trying to run "/.../google-cloud-sdk/bin/bootstrapping/gsutil.py config".
The "config" command is no longer needed with the Cloud SDK.
To authenticate, run: gcloud auth login
Really run this command? (y/N) y
This command will create a boto config file at /.../.boto
containing your credentials, based on your responses to the following questions.
What is the full path to your private key file?
我必须使用哪些命令/参数/设置来环境提示?
答案 0 :(得分:9)
执行:
解决了这个问题gcloud auth activate-service-account --key-file=/opt/gcloud/auth.json
可以在此处找到整个示例和完成的容器:blacklabelops/gcloud
答案 1 :(得分:0)
如果您只想要gsutil并绕过提示,可以使用expect脚本轻松完成:
#!/usr/bin/expect
spawn gsutil config -e
expect "What is the full path to your private key file?" { send "/path/your.key\r" }
expect "Would you like gsutil to change the file permissions for you? (y/N)" { send "y\r" }
expect "What is your project-id?" { send "your-projet-42\r" }
interact
答案 2 :(得分:0)
仅使用gsutil:
首先运行此命令以手动配置身份验证
gsutil config -a
这将使用所需的凭据创建/root/.boto文件。 将该路径/文件复制到docker镜像中。
gsutil现在可以使用这些凭据。
答案 3 :(得分:0)
-o Credentials:gs_service_key_file=<path to JSON file>
使用 https://cloud.google.com/storage/docs/gsutil/addlhelp/TopLevelCommandLineOptions 中记录的 boto 配置覆盖参数做得很好
$ gsutil -v
gsutil version: 4.57
$ gsutil -o Credentials:gs_service_key_file=key.json ls -al gs://bucket/filename
79948 2021-05-24T02:12:25Z gs://bucket/filename#1111111145678393 metageneration=2