Azure documentdb 防火墙阻止了来自 Web 作业的访问

Azure documentdb firewall blocked access from web job

我正在尝试通过启用 "Enable IP Access Control".

来启用 Azure DocumentDB 防火墙

我设法允许来自我的应用服务的连接。但是,驻留在应用服务上的网络作业无权访问 Azure DocumentDB。

有没有办法允许 Web 作业访问 DocumentDB? 谢谢

Is there a way to allow web job access to the DocumentDB?

简而言之,没有。 如果我们要启用防火墙阻止访问策略,我们需要添加允许的 IP 地址列表或 IP 地址 ranges.We 可以从 document 获得更多信息。但 Azure WebApp IP 不是静态的。

all of access to your Azure Cosmos DB database account from machines outside the configured allowed list of IP address ranges are blocked

I managed to allow connections from my App Service

如果这意味着您已打开允许访问 Azure 门户。 如果是这种情况,并不意味着我们可以从Azure其他服务访问DocumentDB,这意味着我们可以从Azure门户对帐户内的集合或文档进行操作。

Without portal access enabled, you will not be able to perform any operations on collections or documents within this account from the portal

总而言之,如果我们想要允许 Web 作业访问 DocumentDB,那么我们需要 关闭 启用 IP 访问控制 。或者我们可以使用 Azure 云服务或虚拟机来代替 WebJob。

编辑:

根据您的评论,如果我们想使用与 WebApp 相同的 IP,我们可以使用出站 IP,我们可以从 azure 资源中获取它们(https://resources.azure.com/),然后将 outboundIpAddresses 添加到 DocumentDB允许的 IP 列表。 然后webjob就可以访问DocumentDB了。

注意: outboundIpAddresses 不是静态ip,当我们重启WebApp或更改WebApp服务计划时,它们可能会改变。