简体   繁体   English

在 github 上发布 BigQuery 项目而不影响密钥。json

[英]Publishing BigQuery Project on github without compromising on key.json

I have created a bigquery project in GCP and accessed this project using the BQ API in python env (VSCode) and need to submit it as a project to my superiors via github.我在 GCP 中创建了一个 bigquery 项目,并使用 python env(VSCode)中的 BQ API 访问了这个项目,需要通过 ZBF215181B5140522137B3D4F6B7354 将其作为项目提交给我的上级。 I have created a service account in GCP and saved its credentials (key.json file) in the python env (VSCode).我在 GCP 中创建了一个服务帐户,并将其凭据(key.json 文件)保存在 python 环境(VSCode)中。 To reproduce this project, according to my current setup, someone does need a key.json file to access the project.要重现这个项目,根据我目前的设置,确实需要一个 key.json 文件来访问该项目。 On the other hand, the BQ project in GCP console has a huge dataset uploaded in the cloud which is utilized to make queries etc. So how to even consider making the dataset in google Cloud public (?) As I am new to GCP, I would like to know how to publish such BQ project with proper credentials and no compromise on the private key via.py file in github.另一方面,GCP 控制台中的 BQ 项目在云端上传了一个巨大的数据集,用于进行查询等。那么如何考虑将谷歌云中的数据集公开(?)因为我是 GCP 的新手,我想知道如何使用适当的凭据发布这样的 BQ 项目,并且不会损害 github 中的私钥 via.py 文件。 Even service account / assigning roles are quite confusing and not as the tutorials from YT.甚至服务帐户/分配角色也很混乱,不像 YT 的教程。

Any help in this regard will be helpful.在这方面的任何帮助都会有所帮助。 Thanks谢谢

You have several manner to access to GCP resource being authenticated.您可以通过多种方式访问正在验证的 GCP 资源。

  • You can use a service account key file defined directly in your code您可以使用直接在代码中定义的服务帐户密钥文件
  • You can use a service account key file defined in the environment variables您可以使用环境变量中定义的服务帐户密钥文件
  • You can use the Google Cloud metadata server (available with all Google Cloud services)您可以使用 Google Cloud 元数据服务器(适用于所有 Google Cloud 服务)
  • You can use your own user account您可以使用自己的用户帐户

That hierarchy is named ADC (Application Default Credential) and you can leverage it.该层次结构名为ADC (应用程序默认凭据),您可以利用它。

In your use case, you aren't on Google Cloud environment, you can remove the metadata server (but it's very useful when you will deploy your code on Google Cloud, keep that in mind)在您的用例中,您不在 Google Cloud 环境中,您可以删除元数据服务器(但是当您将代码部署在 Google Cloud 上时它非常有用,请记住这一点)

You want to avoid the service account key file for security reason (and you have absolutely right, avoid using them every time you can, and you can almost every time!)出于安全原因,您想避免使用服务帐户密钥文件(您绝对正确,每次可以避免使用它们,而且几乎每次都可以!)

Last option, use your user account.最后一个选项,使用您的用户帐户。 For that, run the command gcloud auth application-default login .为此,运行命令gcloud auth application-default login Like that, you create a local credential, based on your Google account.像这样,您可以根据您的 Google 帐户创建一个本地凭据。 The Google Cloud client libraries in your code know how to leverage that value.您代码中的 Google Cloud 客户端库知道如何利用该价值。 (Don't mix up with the gcloud auth login command that is used only for the gcloud CLI, and not by the client libraries; yes not obvious when you are new) (不要与仅用于 gcloud CLI 而不是客户端库的gcloud auth login命令混淆;是的,当您是新手时不明显)

So, you must have the permission to access the ressources (your email).因此,您必须有权访问资源(您的电子邮件)。 If your boss checkout the code and run it in their environment, they have to be also authenticated and to have access to the resources (don't forget to grant their email on the resources!!)如果您的老板签出代码并在他们的环境中运行它,他们还必须经过身份验证并有权访问资源(不要忘记在资源上授予他们的 email !!)

No credential to share, each environment has their, and it's much more secure without sharing a secret!无需共享凭证,每个环境都有自己的,而且不共享秘密更加安全!

It seems that the easiest method for your use case is to just add your superior as an IAM user to the Google Cloud Project and use IAM user credentials to avoid service accounts altogether.对于您的用例,最简单的方法似乎是将您的上级作为 IAM 用户添加到 Google Cloud 项目,并使用 IAM 用户凭证来完全避免服务帐户。

To do so:为此:

  1. Add your superior as IAM user under the IAM tab in IAM and Admin .IAM 和 AdminIAM选项卡下将您的上级添加为 IAM 用户。

  2. Grant their IAM user the appropriate IAM roles required to run the application (BigQuery permissions etc.)授予他们的 IAM 用户运行应用程序所需的适当 IAM 角色(BigQuery 权限等)

  3. Have your superior clone your Github project.让您的上级克隆您的 Github 项目。

  4. Set ADC credentials by running: gcloud auth application-default login通过运行设置 ADC 凭据: gcloud auth application-default login

Note : This step requires the Cloud SDK to be installed , you can also clone the code and run the gcloud command in Cloud Shell as it will have the pre-reqs installed.注意:此步骤需要安装 Cloud SDK ,您也可以克隆代码并在Cloud Shell中运行gcloud命令,因为它将安装 pre-reqs。

  1. Your superior should now be able to run your application without need of a service account.您的上级现在应该能够在不需要服务帐户的情况下运行您的应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM