在不同的 GCP 项目中使用工件注册表时,GCP 工件注册表找不到满足要求的版本

GCP artifact registry cannot find a version that satisfies the requirement when using artifact registry in different GCP project

我正在尝试将自定义包添加到 GCP 上的云功能, 我有正确的权限,当我在同一个 GCP 项目中关注 this tutorial 时可以导入包。

我无法从外部 GCP 项目添加工件,即使我手动赋予角色:工件注册表 Reader 到部署云函数的服务帐户。

我还在 google cloud platform issue tracker

我在调查和回答 this question

时用我的发现更新了 Google 问题跟踪器

我会在下面对该答案做一个简短的总结,但请参阅我的答案以了解更多详细信息。

总结

因此,总而言之,对存储库的第一次身份验证是通过您使用的任何 SA 完成的。
愚蠢的是,下载本身是使用 Cloud Build 的内置 SA 从您要将 Cloud Function 部署到的项目中完成的。恕我直言,这应该由与第一个相同的 SA 完成。

请注意,Cloud Build 的内置 SA 格式为 <PROJECT-NUMBER>@cloudbuild.gserviceaccount.com

根据 official documentation.

,我相信这是按预期工作的

If Cloud Functions and Artifact Registry are in different projects, you must grant repository access to the Cloud Build service account.

需要将 Artifact Registry 角色授予 Cloud Build 服务帐户,而不是 Cloud Functions SA。

我知道这不是最直观的做法:)