IBM Cloud Code Engine:构建在步骤“step-build-and-push”中失败,错误为 UNAUTHORIZED

问题描述

我有一个之前运行过的现有 IBM Cloud Code Engine 项目。我提交了一个新的构建运行,但它失败了。根据错误消息,这是由于私有映像注册表 (IBM Cloud Container Registry) 的权限所致。 IAM API 密钥有效并且适用于其他任务。没有配额问题。

ibmcloud ce buildrun submit --build mybuild

检查它显示的状态失败。进入日志,这些是问题所在:

myproject-build-run-n9xm6-xxx-pod-yyy/step-build-and-push: 错误 检查推送权限——确保您输入了正确的标签 名称,并且您已通过正确身份验证,然后重试: 检查“us.icr.io/henrik/myproject:latest”的推送权限: 为 us.icr.io 创建推送检查传输失败:GET https://us.icr.io/oauth/token?scope=repository%3Ahenrik%myproject%3Apush%2Cpull&service=registry: UNAUTHORIZED:登录凭证无效,或者您的 IBM Cloud 帐户未激活。登录凭据无效,或者您的 IBM Cloud 帐户未激活。

无论我使用 CLI 还是浏览器控制台,错误都是一样的。

解决方法

事实证明,我为容器注册表启用了 enforced private endpoint access,这是一项安全最佳实践。但是,我需要正确的 credentials in Code Engine to access the container registry。使用 IBM Cloud Container Registry,在代码引擎中我需要

  • 为注册服务器创建注册凭据private..icr.io,例如,private.us.icr.io
  • 也将图像名称设置为具有私有端点,例如 private.us.icr.io/henrik/myproject

凭据和图像名称都具有匹配的服务器名称,我成功了,错误消失了。