【发布时间】:2019-12-25 03:09:43
【问题描述】:
TLDR;我在为服务帐号分配 IAM 权限时遇到问题。
我正在构建一个测试,其中涉及使用 firebase Auth 铸造自定义令牌。当我击中时:
const token = await admin.auth().createCustomToken('test', {
isAdmin: true,
})
抛出以下错误
Permission iam.serviceAccounts.signBlob is required to perform
this operation on service account
projects/-/serviceAccounts/dashboard@appspot.gserviceaccount.com.;
Please refer to
https://firebase.google.com/docs/auth/admin/create-custom-tokens
for more details on how to use and troubleshoot this feature
在referenced documentation 中,它表示将Service Account Token Creator 角色添加到服务帐户。我已添加该角色(以及尝试服务帐户管理员无济于事。
当我运行时,我可以验证我的权限是否设置正确
gcloud projects get-iam-policy project我可以看到我的服务帐户附加到所需的角色
- members:
- serviceAccount:dashboard@appspot.gserviceaccount.com
role: roles/iam.serviceAccountTokenCreator
但是,如果我查看该特定服务帐户,它似乎显示为空,这符合我的错误:
gcloud iam service-accounts get-iam-policy dashboard@appspot.gserviceaccount.com
etag: ACAB
- 为什么这两个命令和云控制台会显示不同的信息?
我认为导致我的服务帐户权限显示为空白的原因是罪魁祸首,但我不确定在哪里进一步调试。在我看来,唯一的区别是一个命令被调用,其中包含一个项目,但我使用项目 ID 初始化了我的 firebase 应用程序,并使用(firebase-admin).apps[0].options 对其进行了验证,所以这似乎是一个死胡同。
【问题讨论】:
标签: google-cloud-platform firebase-authentication google-iam google-cloud-iam