“gcloud auth 应用程序-默认登录"之间的区别和“gcloud 身份验证登录" [英] Difference between "gcloud auth application-default login" and "gcloud auth login"

查看:22
本文介绍了“gcloud auth 应用程序-默认登录"之间的区别和“gcloud 身份验证登录"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

gcloud auth application-default logingcloud auth login 有什么区别?

尽管有以下定义,但仍然很难区分它们.

Despite the definitions below, it is still hard to differentiate them.

gcloud auth 应用程序-默认登录:

  • 获取新的用户凭据以用于应用程序默认凭据

gcloud 身份验证登录:

  • 授权 gcloud 使用 Google 用户凭据访问 Cloud Platform

我什么时候应该使用一个?

When should I use one over the other?

推荐答案

区别在于用例:

作为开发者,我想通过 gcloud 与 GCP 交互.
gcloud 身份验证登录
这会获取您的凭据并将它们存储在 ~/.config/gcloud/ 中.现在您可以从终端运行 gcloud 命令,它会自动找到您的凭据.在这种情况下,任何代码/SDK 都不会自动获取您的凭据.

As a developer, I want to interact with GCP via gcloud.
gcloud auth login
This obtains your credentials and stores them in ~/.config/gcloud/. Now you can run gcloud commands from your terminal and it will find your credentials automatically. Any code/SDK will not automatically pick up your creds in this case.

参考:https://cloud.google.com/sdk/gcloud/参考/授权/登录

作为开发人员,我希望我的代码通过 SDK 与 GCP 交互.
gcloud auth 应用-默认登录
这会通过网络流获取您的凭据,并将它们存储在'应用程序默认凭据的知名位置'.现在,您运行的任何代码/SDK 都将能够自动找到凭据.当您想要在本地测试通常在服务器上运行并使用服务器端凭据文件的代码时,这是一个很好的替代方法.

As a developer, I want my code to interact with GCP via SDK.
gcloud auth application-default login
This obtains your credentials via a web flow and stores them in 'the well-known location for Application Default Credentials'. Now any code/SDK you run will be able to find the credentials automatically. This is a good stand-in when you want to locally test code which would normally run on a server and use a server-side credentials file.

参考:https://cloud.google.com/sdk/gcloud/reference/auth/application-default/login

编辑 (09/19/2019):
正如 Kent 在下面的评论中所贡献的,应用程序默认凭据的众所周知的位置" 是一个名为 application_default_credentials.json 的文件,位于您的本地 ~/.config/gcloud/ 目录.我在下面添加了一个附加链接,指向 Theodore SuiDaniel De Leo 的文章,其中详细介绍了不同的身份验证方法.

Edit (09/19/2019):
As Kent contributed in his comment below, 'the well-known location for Application Default Credentials' is a file named application_default_credentials.json located in your local ~/.config/gcloud/ directory. I've added an additional link below to an article by Theodore Sui and Daniel De Leo which goes into greater detail about the different authentication methods.

文章:https://medium.com/google-cloud/local-remote-authentication-with-google-cloud-platform-afe3aa017b95

这篇关于“gcloud auth 应用程序-默认登录"之间的区别和“gcloud 身份验证登录"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆