gpt4 book ai didi

azure - 如何限制将 Azure Functions 发布到 API 管理的访问权限?

转载 作者:行者123 更新时间:2023-12-03 05:20:36 37 4
gpt4 key购买 nike

我有一个公共(public) Azure 函数。我只需访问其网址即可看到该应用程序。是否可以限制此功能,以便只有 API 管理服务才能访问此功能?我不想将该函数设为私有(private)(Vnet),因为这样我就需要一个非常昂贵的(高级计划)来进行 API 管理。

最佳答案

我为限制 Function App 访问 Internet 并仅允许来自 APIM 实例的解决方法之一是:

  1. 使用 HTTP 触发器创建 .NET Azure Function App(最少代码) - 来自门户的消费托管计划:
#r "Newtonsoft.Json"
using System.Net;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Primitives;
using Newtonsoft.Json;

public static async Task<IActionResult> Run(HttpRequest req, ILogger log)
{
log.LogInformation("C# HTTP trigger function processed a request.");
string responseMessage = "Hello Krishna, This HTTP triggered function executed successfully.";
return new OkObjectResult(responseMessage);
}
  • 已将此 Function App API 添加到 Azure APIM 实例。
  • 在功能应用程序(门户)> 网络设置 > 访问限制 > 添加了一条仅允许 APIM 公共(public) IP 地址的规则:
  • enter image description here

    测试: enter image description here

    enter image description here

  • 我已将函数授权级别设置为 Function,因此如果 URL 中没有函数键代码,匿名用户将无法访问 Function App URL。
  • 为了更安全地保护 Function App(例如仅接受来自相同 Azure AD 租户资源的访问),您可以在 Function App 中配置身份验证。
  • 请参阅 Microsoft 博客文章 Accepting traffic only from APIM for the Function App .

    关于azure - 如何限制将 Azure Functions 发布到 API 管理的访问权限?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72633969/

    37 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com