【问题标题】:Terraform auth problem with the google_firebase_project resourcegoogle_firebase_project 资源的 Terraform 身份验证问题
【发布时间】:2021-12-11 07:51:53
【问题描述】:

我已将我的 firebase 项目作为 terraform 资源导入,但在运行 terraform plan 时得到了这个:

│ Error: Error when reading or editing FirebaseProject "projects/myproject": googleapi: Error 403: Your application has authenticated using end user credentials from the Google Cloud SDK or Google Cloud Shell which are not supported by the firebase.googleapis.com. We recommend configuring the billing/quota_project setting in gcloud or using a service account through the auth/impersonate_service_account setting. For more information about service accounts and how to use them in your application, see https://cloud.google.com/docs/authentication/. If you are getting this error with curl or similar tools, you may need to specify 'X-Goog-User-Project' HTTP header for quota and billing purposes. For more information regarding 'X-Goog-User-Project' header, please check https://cloud.google.com/apis/docs/system-parameters.
│ Details:
│ [
│   {
│     "@type": "type.googleapis.com/google.rpc.ErrorInfo",
│     "domain": "googleapis.com",
│     "metadata": {
│       "consumer": "projects/774686551450",
│       "service": "firebase.googleapis.com"
│     },
│     "reason": "SERVICE_DISABLED"
│   }
│ ]
│ 
│   with google_firebase_project.default,
│   on main.tf line 27, in resource "google_firebase_project" "default":
│   27: resource "google_firebase_project" "default" {

如果我将GOOGLE_APPLICATION_CREDENTIALS env var 设置为该项目的服务帐户,它似乎可以工作,但我想避免它,因为每次我更改环境时都需要重新导出该变量.

我已通过我的用户对gcloud 进行了身份验证,该用户是所有相关项目的管理员。

【问题讨论】:

  • 如果您已经为该项目创建了服务帐户,您可以尝试使用gcloud auth activate-service-account service_account_email --key-file=/path/to/your/service/account/keyfile.json 验证 Cloud SDK 更多信息 - cloud.google.com/sdk/gcloud/reference/auth/…
  • @st_rt_dl_8 我想完全避免使用服务帐户,因为每次部署到不同的环境时都需要切换。
  • 你能解决这个问题吗?我面临同样的问题。服务帐户也不适合我

标签: firebase terraform terraform-provider-gcp


【解决方案1】:

作为外部工具,terraform 需要 一些 方法来通过 GCP 进行身份验证。你只有两个选择:

  1. 具有所需权限的服务帐户。
  2. 具有所需权限的 GSuite 用户或组。

一个服务或组或用户帐户可以被授予多个项目的权限,尽管这有安全隐患(主要是爆炸半径),我不推荐这样做。

在处理不同项目时切换帐户可能很烦人,但目前是最好的方法。

如果您使用 GKE,则可以利用他们的工作负载身份功能。我不确定这是如何工作的,但我相信它可以根据工作负载自动切换到正确的服务帐户。最终,仍然需要单独的服务帐户。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-30
    相关资源
    最近更新 更多