简体   繁体   English

禁止对Cloud中的存储队列进行Azure Function v1访问

[英]Azure Function v1 access forbidden to Storage Queue within the Cloud

I have an Azure Function v1, SDK 1.0.24 trying to access my Storage Queue, which works fine locally and I can see the messages stored properly. 我有一个Azure Function v1,SDK 1.0.24试图访问我的存储队列,该队列在本地运行良好,我可以看到正确存储的消息。 But as soon as I publish it to the cloud it fails with a 403 forbidden and I have run out of clues. 但是,一旦我将其发布到云中,它就会以403被禁止而失败,并且我已经没有足够的线索了。

I checked the connection string several times, I checked the timestamps in request and response which are totally fine. 我多次检查了连接字符串,检查了请求和响应中的时间戳,这完全没问题。 I tried to update several NuGet packages, but in the end why should work locally but not online when they are broken? 我尝试更新几个NuGet软件包,但是最后为什么在损坏时为什么应该在本地工作却不能在线工作? I am not using Application Insights. 我没有使用Application Insights。 In the Host Log I found this error: 在主机日志中,我发现此错误:

2019-01-16T12:38:32.460 [Verbose] Host '44bf8a95b6652eed85464155b2b48df2' failed to acquire host lock lease: Microsoft.WindowsAzure.Storage: The remote server returned an error: (403) Forbidden. 2019-01-16T12:38:32.460 [详细]主机'44bf8a95b6652eed85464155b2b48df2'无法获取主机锁租约:Microsoft.WindowsAzure.Storage:远程服务器返回错误:(403)禁止。

I am suspecting there is a security-related setting within Azure that prevents the access (but I don't have any control about the security features, and the admin has also no idea what the blocking issue could be). 我怀疑Azure中存在与安全相关的设置,阻止了访问(但是我对安全功能没有任何控制权,管理员也不知道可能存在什么阻止问题)。

The issue is happening with a QueueTrigger, so I made a small function with alternative access to reproduce the issue: 这个问题发生在QueueTrigger上,因此我做了一个小功能,提供了替代访问来重现该问题:

public static class TestStorageQueue
    {
        [FunctionName("TestStorageQueue")]
        public static async Task<HttpResponseMessage> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequestMessage req, 
            TraceWriter log)
        {
            log.Info("START");

            try
            {
                var response = new HttpResponseMessage(HttpStatusCode.OK);

                log.Info(ConfigurationManager.ConnectionStrings["soastorage"]?.ConnectionString);
                CloudStorageAccount storeAccount = CloudStorageAccount.Parse(ConfigurationManager.ConnectionStrings["soastorage"]?.ConnectionString);
                CloudQueueClient queueClient = storeAccount.CreateCloudQueueClient();
                CloudQueue queue = queueClient.GetQueueReference("myqueue");


                log.Info("trying to get message from queue");
                var cloudMessage = queue.GetMessage(); // 403 happens here
                log.Info("received message item");

                var message = cloudMessage?.AsBytes;
                var length = message?.Length ?? 0;

                response.Content = new StringContent("received message length: " + length.ToString());

                return response;
            }
            catch(Exception ex)
            {
                var response = new HttpResponseMessage(HttpStatusCode.InternalServerError);
                response.Content = new StringContent(ex.Message);

                return response;
            }
        }
    }

Update It's funny, searched for an answer for 2 days and as soon as I posted it, we found the reason. 更新很有趣,搜索了2天的答案,当我发布答案后,我们就找到了原因。 The issue is the Azure Storage Firewall, even with whitelisting all MS Services it keeps blocking them. 问题是Azure存储防火墙,即使将所有MS服务列入白名单,它也会一直阻止它们。 So the temporary solution was to switch it off, which is not really the solution, so question still pending 因此,临时解决方案是将其关闭,但这并不是真正的解决方案,因此问题仍然悬而未决

Try to configure Storage Firewall with Function app outbound IPs , to conclude: 尝试使用Function应用程序出站IP配置Storage Firewall,得出以下结论:

  1. On Function panel in Azure portal, Platform features> Resource Explorer. 在Azure门户的“功能”面板上,依次单击“平台功能”>“资源浏览器”。

  2. Find outboundIpAddresses and add all of them to Firewall IP list. 查找outboundIpAddresses并将它们全部添加到防火墙IP列表中。

  3. If our functions are on dedicated App service plan(like Basic, Standard and so on), add possibleOutboundIPAddresses if we want to scale the plan to other pricing tiers. 如果我们的功能是基于专用的App服务计划(如Basic,Standard等),则如果我们想将该计划扩展到其他定价层,请添加possibleOutboundIPAddresses OutboundIPAddresses。

  4. If our functions are on Consumption plan, we may have to whitelist the function apps' data center. 如果我们的功能在“消费计划”中,我们可能必须将功能应用程序的数据中心列入白名单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM