使用google_application_credentials env var with github Actions Secret
我的问题很简单:我想运行取决于google_application_credentials
从github操作秘密正确设置的代码。
问题是Google_application_credentials
期望包含通往服务帐户文件的路径,无论秘密是否包含实际的服务帐户文件内容。
最好的做法是什么?
编辑
本质上,我运行了一个NodeJS脚本,该脚本使用客户端库(PubSub,BigQuery等)连接到多个GCP资源。据我了解,如果google_application_credentials
env var是正确定义的,它们最容易工作。
My problem is simple: I want to run code that depends on GOOGLE_APPLICATION_CREDENTIALS
being set up correctly from a GitHub Actions secret.
The problem is that GOOGLE_APPLICATION_CREDENTIALS
is expect to contain a path to a service account file, whether the secret contain the actual service account file content.
What's the best practice for that?
EDIT
Essentially I run a NodeJS script which connect to multiple GCP resources using client libraries (PubSub, BigQuery, etc). To my understanding, they can most easily work if GOOGLE_APPLICATION_CREDENTIALS
env var is correctly defined.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
没有一个。环境变量必须指向一个文件,该文件是服务帐户JSON密钥的位置。您可以将内容写入工件,但这很危险。还有其他方法,但是您的问题没有提供有关您的GitHub操作或运行命令的详细信息。但是,我仍然不会使用这些方法。
正确的解决方案是使用Google Cloud Workload Identity Federation。这既是解决方案又是最佳实践解决方案。
Github提供了OAuth身份提供商。 Google支持从一个OAuth提供商到另一个OAuth提供商的凭据。
从GitHub Actions
google-github-actions/auth
There isn't one. The environment variable must point to a file which is the location for a service account JSON key. You could write the contents to an artifact, but that is dangerous. There are other methods, but your question does not provide details on what your GitHub action does or the commands it runs. However, I still would not use those methods.
The correct solution is to use Google Cloud Workload Identity Federation. That is both the solution and the best practice solution.
GitHub provides an OAuth identity provider. Google supports federating credentials from one OAuth provider to another.
Enabling keyless authentication from GitHub Actions
google-github-actions/auth
您可以使用 this github操作要登录。几乎您必须使用服务帐户的内容创建一个秘密,并将其指定为输入:
You can use this GitHub action to log in. Pretty much you have to create a secret with the content of the service account and specified it as input:
这是Python中可能的解决方法:
简而言之
Here's a possible workaround in Python:
In short, use env variables to create temp credentials in JSON