在GCP云功能中添加跨项目服务帐户

发布于 2025-01-11 08:21:18 字数 449 浏览 3 评论 0 原文

在 GCP 中从项目 A项目 B 添加了一个 IAM 服务帐户,并具有云函数管理员权限

我们已 现在尝试使用相同的服务帐户项目B中创建云函数。

但在创建云函数时,下拉菜单中未列出服务帐户。只有本地创建的服务帐户在下拉菜单中可见。

输入图片此处描述

对于在云功能中使用跨服务帐户有什么建议吗?

We have added a IAM service account from Project A to project B in GCP with Cloud function Admin permissions

We are now trying to create a cloud function in project B using the same service account .

But the service account is not listed in the drop down menu during creation of Cloud functions. Only the service accounts which are locally created are visible in the drop down menu.

enter image description here

Any suggestion to use cross service accounts in cloud functions ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

冷情妓 2025-01-18 08:21:18

您无法使用外部项目中的服务帐户作为云功能的运行时 SA,这就是您在下拉菜单中看不到服务帐户的原因。

当您向项目 B 中的项目 A 的服务帐户授予权限时,您只需执行此操作即可授予权限。请记住,SA 仍然是项目 A 的一部分,而不是项目 B

这与Cloud Scheduler的工作方式相同:

服务帐户必须与创建 Cloud Scheduler 作业的项目属于同一项目。

此处的步骤建议执行此操作可能的方法是使用项目 B 的服务帐户来模拟项目 A 的服务帐户,但您会注意到,实际上您附加了来自同一项目的帐户,功能是。

如果您需要从项目 B 访问项目 A 中的资源,请在您的函数中使用同一项目中的 SA,并在 中添加该 SA 所需的权限项目 A 或使用模拟方法(如果您愿意)。

You cannot use Service Accounts from external projects as a runtime SA for a Cloud Function, this is why you don't see the service account in the dropdown menu.

When you grant permissions to the Service Account from Project A in Project B you only do that, grant permissions. Keep in mind that the SA continues being part of project A and not project B.

This works in the same way as Cloud Scheduler:

The service account must belong to the same project as the one in which the Cloud Scheduler jobs are created.

What the steps here suggest to make this possible is to impersonate a the Service Account from project A using a service account of project B but you will notice that actually you attach an account from the same project were the function is.

If you need to access to resources in project A from project B then use in your function a SA from the same project and add the needed permissions for that SA in project A or use the impersonation approach if you prefer.

A君 2025-01-18 08:21:18

我很困惑:-(

我使用 gcloud 尝试过此操作,但无法使其工作。

我尝试在所需的(远程)服务帐户,但我继续得到:

ERROR: (gcloud.beta.functions.deploy) PERMISSION_DENIED:
Permission 'iam.serviceaccounts.actAs' denied on service account
${ACCOUNT}@${OTHER-PROJECT}.iam.gserviceaccount.com

也许远程帐户也需要云功能部署权限?

I'm flummoxed :-(

I tried this using gcloud and am unable to get it work.

I tried granting the Cloud Functions project's Compute Engine service account roles/serviceAccountUser on the desired (remote) Service Account but I continue to get:

ERROR: (gcloud.beta.functions.deploy) PERMISSION_DENIED:
Permission 'iam.serviceaccounts.actAs' denied on service account
${ACCOUNT}@${OTHER-PROJECT}.iam.gserviceaccount.com

Perhaps the remote account need Cloud Functions deploy permissions too?

和我恋爱吧 2025-01-18 08:21:18

是的,可以跨项目使用服务帐户来部署云功能。

请点击下面提到的链接来授予必要的权限。

https://cloud.google.com/functions/docs/secure/ function-identity#gcloud_2


如果服务帐号和函数在不同的项目中,则从服务帐号所在的项目中:

配置服务帐号跨项目工作。
将服务帐户令牌创建者角色 (roles/iam.serviceAccountTokenCreator) 授予以下两个 Google 管理的服务帐户:

App Engine 默认服务帐户 ([电子邮件受保护])
Cloud Functions 服务代理 ([电子邮件受保护])
这些 Google 帐户管理您的服务帐户的跨项目访问。

授予服务帐户对资源的访问权限。执行此操作的方法取决于资源类型。

将服务帐户与您的功能连接起来。您可以在部署时或通过更新以前部署的函数来执行此操作。


使用上述指导,我们仍然无法跨项目查看新的 SA,但能够通过 CLI 部署相同的 SA。

示例 CLI 如下

gcloud 函数部署 FUNCTION_NAME
--trigger-topic TOPIC_NAME --region REGION_NAME --runtime RUNTIME --entry-point ENTRY_POINT --service-account SERVICE_ACCOUNT_EMAIL

请注意:使用 CLI 部署 CF 时,您需要位于 main.py 和其他文件所在的工作目录中位于。

Yes it possible to use service account across projects to deploy Cloud Function.

Please follow below mentioned link to grant the necessary permissions.

https://cloud.google.com/functions/docs/securing/function-identity#gcloud_2


If the service account and the function are in different projects, from the project where the service account is located:

Configure the service account to work across projects.
Grant the Service Account Token Creator role (roles/iam.serviceAccountTokenCreator) to both of these Google-managed service accounts:

App Engine default service account ([email protected])
Cloud Functions Service Agent ([email protected])
These Google accounts manage cross-project access for your service account.

Grant the service account access to the resource. The method for doing this depends on the resource type.

Connect the service account with your function. You can do this either at deployment time or by updating a previously deployed function.


Using the above guidance we are still not able to view the new SA across the projects but able to deploy the same via CLI.

Sample CLI is as below

gcloud functions deploy FUNCTION_NAME
--trigger-topic TOPIC_NAME --region REGION_NAME --runtime RUNTIME --entry-point ENTRY_POINT --service-account SERVICE_ACCOUNT_EMAIL

Please note: While deploying the CF using CLI, you need to be in working directory where main.py and other files are located.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文