为什么导出GOOGLE_APPLICATION_CREDENTIALS时不适用于`bq`? [英] Why does exporting GOOGLE_APPLICATION_CREDENTIALS not work with `bq`?
问题描述
google文档表示导出env var GOOGLE_APPLICATION_CREDENTIALS
与服务帐户的JSON密钥的路径,gcloud将使用它。
我的命令是:
GOOGLE_APPLICATION_CREDENTIALS = / home / ubuntu / .config / google-creds.json bq ls
这只是带来了一个错误:
您目前没有选择活动账户。请运行:
$ gcloud auth login
获取新凭据,或者如果您已经登录
不同的帐户:
$ gcloud config set account ACCOUNT
选择一个已经过身份验证的帐户
gcloud -v
给出:
Google Cloud SDK 92.0.0
bq 2.0.18
bq-nix 2.0.18
core 2016.01.12
core-nix 2015.11.24
gcloud
gsutil 4.16
gsutil-nix 4.15
我做错了什么,我该如何解决这个问题?我需要 gsutil
和 bq
来使用此文件。我正在处理多个项目,因此无法激活任何特定项目。 解决方案
您是否尝试过 gcloud auth activate-service-account
?:
gcloud auth activate-service-account --key-file google-creds.json
(看起来命令行工具并没有停留在整个凭证发现链上,因为gcloud在执行时)
如果您有多种配置(例如auth,project id),您需要要使用,您可以设置配置。例如,如果您有两个服务帐户凭证,请将它们称为 sa1.json
和 sa2.json
- 您可以执行以下操作:
$ gcloud配置配置创建proj1
$ gcloud配置配置激活proj1
$ gcloud auth激活服务帐户--key-file sa1.json
$ gcloud配置配置创建proj2
$ gcloud配置配置激活proj2
$ gcloud auth激活服务帐户 - 密钥文件sa2.json
现在,您可以使用 gcloud config configurations activate
命令设置您想要使用的配置,或设置 CLOUDSDK_ACTIVE_CONFIG_NAME
环境变量以指定您想要运行命令的配置。即运行 bq ls
使用 sa1.json
cred:
$ CLOUDSDK_ACTIVE_CONFIG_NAME = proj1 bq ls
sa2.json
cred:
$ CLOUDSDK_ACTIVE_CONFIG_NAME = proj2 bq ls
The google docs say to export the env var GOOGLE_APPLICATION_CREDENTIALS
with the path to a service account's JSON key, and gcloud will use it. I can't get it to work.
My command is:
GOOGLE_APPLICATION_CREDENTIALS=/home/ubuntu/.config/google-creds.json bq ls
This just brings up an error:
You do not currently have an active account selected. Please run:
$ gcloud auth login
to obtain new credentials, or if you have already logged in with a different account:
$ gcloud config set account ACCOUNT
to select an already authenticated account to use.
gcloud -v
gives:
Google Cloud SDK 92.0.0
bq 2.0.18
bq-nix 2.0.18
core 2016.01.12
core-nix 2015.11.24
gcloud
gsutil 4.16
gsutil-nix 4.15
What am I doing wrong, and how can I fix this? I need gsutil
and bq
to use this file. I'm working with multiple projects so can't activate any one in particular.
Have you tried gcloud auth activate-service-account
?:
gcloud auth activate-service-account --key-file google-creds.json
(It seems the command-line tools don't go down the whole credential discovery chain, as gcloud does when it's being used as a library in code.)
If you have several configurations (eg auth, project ids) that you need to use, you can set up configurations. For example, if you have two service account credentials you'd like to use - call them sa1.json
and sa2.json
- you can do something like:
$ gcloud config configurations create proj1
$ gcloud config configurations activate proj1
$ gcloud auth activate-service-account --key-file sa1.json
$ gcloud config configurations create proj2
$ gcloud config configurations activate proj2
$ gcloud auth activate-service-account --key-file sa2.json
Now, you can either use the gcloud config configurations activate
command to set the configuration you'd like to use, or set the CLOUDSDK_ACTIVE_CONFIG_NAME
environment variable to specify under which configuration you'd like to run a command. ie to run bq ls
using the sa1.json
cred:
$ CLOUDSDK_ACTIVE_CONFIG_NAME=proj1 bq ls
and for the sa2.json
cred:
$ CLOUDSDK_ACTIVE_CONFIG_NAME=proj2 bq ls
这篇关于为什么导出GOOGLE_APPLICATION_CREDENTIALS时不适用于`bq`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!