Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

[DOC] Improve documentation for service account impersonation

未关闭
#2,812 3 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
文档
描述清晰度
基本清楚
活跃度
停滞
技术栈
gcp, nodejs, typescript

调研方向

先从已报告的 gcloud auth application-default login --impersonate-service-account 流程和 application_default_credentials.json 格式入手,然后将其与 initializeAppcertapplicationDefault 示例进行比较。记录一个适用于 firebase-admin v13.0.1 的可正常运行的本地开发示例,包括所需的权限设置以及成功身份验证的表现。

由索引模型根据 Issue 内容生成。

描述

It seems like service account impersonation is the recommended way to authenticate for local development.

But it's not very clear how this is done in practice. Do I need to adapt my code for this?

I've run:
gcloud auth application-default login --impersonate-service-account SERVICE_ACCT_EMAIL
and I have a token in:
cat /Users/myuser/.config/gcloud/application_default_credentials.json

{
  "delegates": [],
  "service_account_impersonation_url": "https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/myserviceaccount@myproject.iam.gserviceaccount.com:generateAccessToken",
  "source_credentials": {
    "account": "",
    "client_id": "removed",
    "client_secret": "removed",
    "refresh_token": "removed",
    "type": "authorized_user",
    "universe_domain": "googleapis.com"
  },
  "type": "impersonated_service_account"
}

I have tried code like this (after having looked at #2800):

initializeApp({
    storageBucket: config.firebase.storageBucket,
    credential: cert(process.env['GOOGLE_APPLICATION_CREDENTIALS']),
    projectId: config.firebase.projectId,
  })

But then I got an error:

FirebaseAppError: Failed to parse service account json file: Error: Service account object must contain a string "project_id" property.

and this, I assumed this would pick up the ADC credentials file, notice its impersonation, and things would just work:

initializeApp({
    storageBucket: config.firebase.storageBucket,
    credential: applicationDefault(),
    projectId: config.firebase.projectId,
  })

But then I got this error:

"Getting metadata from plugin failed with error: Could not refresh access token: PERMISSION_DENIED: unable to impersonate: Permission 'iam.serviceAccounts.getAccessToken' denied on resource (or it may not exist).",

My local user has the Owner role in the GCP project. And has owner permissions on the service account. The service account has the Service Account Token Creator role.

Im using firebase-admin v13.0.1

Some working sample code for this would be very helpful.

主要语言
TypeScript
星标
1.7k
派生
419
平均合并
4 天 20 小时
30 天内合并 PR
16

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

firebase/firebase-admin-node 的其他 Issue

查看 firebase/firebase-admin-node 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。