Azure DevOps Pipelines 将 Docker 图像推送到 Container Registry 被拒绝

Azure DevOps Pipelines push Docker image to Container Registry Denied

我目前正在尝试使用 Azure Pipelines 构建一个 Docker 映像并将其推送到 Azure 容器注册表。我有一个服务连接设置,但是构建失败并显示 "denied." 我怀疑这是因为我的 Container Registry 设置为仅允许来自 "selected networks" 并且仅限于几个 IP。我通过暂时允许所有网络验证了这一点,然后 build/push 成功了。

有什么方法可以让 Azure Pipelines 成功将 Docker 图像推送到仅允许选定网络的 Container Registry?我以为这就是服务连接的用途?

请确保您的服务连接有 AcrPush permission.

您可以在此处查看或根据需要添加:

(您将在名称 'your-organization-your-project' 下找到您的连接)

恐怕你是对的。可能的原因是你设置为select网络,没有添加DevOps的IP地址放行。据我所知,DevOps的IP地址会随着时间的推移而变化,here是描述:

In some setups, you may need to know the range of IP addresses where agents are deployed. For instance, if you need to grant the hosted agents access through a firewall, you may wish to restrict that access by IP address. Because Azure DevOps uses the Azure global network, IP ranges vary over time.

因此您需要允许一个 IP 范围,而不是单个 IP 地址。这不是一种安全的方式。好吧,根据我的经验,最安全的方法是控制所有人的访问权限,而不是网络。您可以创建多个服务主体并授予他们不同的角色来控制权限。例如使用角色AcrPull,它只有拉取镜像的权限。有关角色的更多详细信息 here. You can even control the permission on the repositories, here 是关于它的更多消息。

对了,防火墙到select网络,我觉得比较适合Azure里面的资源,这个可以用endpoint来实现。