简体   繁体   English

使后端 API 只能通过 Azure API 管理访问

[英]Make back end APIs only accessible via Azure API management

I have multiple Web APIs deployed in Azure without applying authentication, so anyone has access to internet has the access to the Web APIs.我在 Azure 中部署了多个 Web API,但没有应用身份验证,因此可以访问 Internet 的任何人都可以访问 Web API。

Now I would like to apply authentications to the Web APIs, instead of implementing the same authentication logic in different Web APIs, I found Azure API gateway (API management) is a potential solution.现在我想对 Web API 应用身份验证,而不是在不同的 Web API 中实现相同的身份验证逻辑,我发现 Azure API 网关(API 管理)是一个潜在的解决方案。

With Azure API management documentation, I learned I can apply policies like validate-jwt to authenticate requests to back end Web APIs.通过 Azure API 管理文档,我了解到我可以应用validate-jwt等策略来验证对后端 Web API 的请求。 However, endpoints of the back end Web APIs are still available to users.但是,后端 Web API 的端点仍然可供用户使用。

So, how should I hide them?那么,我应该如何隐藏它们? Must I define a sub network or does Azure API management have a feature for this?我必须定义一个子网还是 Azure API 管理有一个功能?

Recently I also had this same problem.最近我也遇到了同样的问题。 Finally I found the solution by using 'IP Restrictions' function.最后我通过使用“IP 限制”功能找到了解决方案。 See the following steps:请参阅以下步骤:

1) Go to your API management Overview page in Azure portal, copy the VIP. 1) 转到 Azure 门户中的 API 管理概述页面,复制 VIP。 API 管理概览页面

2) In your Web APP > Networking 2) 在您的 Web APP > 网络联网

3) Paste in your VIP 3) 粘贴您的 VIP 贴vip

Microsoft's Solution: How to secure back-end services using client certificate authentication in Azure API Management Microsoft 的解决方案: 如何在 Azure API 管理中使用客户端证书身份验证来保护后端服务

Using this approach, any attempt to access a back-end service without the required certificate will result in a 403 - Forbidden response.使用这种方法,任何在没有所需证书的情况下访问后端服务的尝试都将导致403 - Forbidden响应。

You can use a self-signed certificate as opposed to using a trusted CA signed certificate ($$).您可以使用自签名证书,而不是使用受信任的 CA 签名证书 ($$)。 I chose to implement an Azure Key Vault where I generated a new certificate, downloaded it as a *.PFX file, and uploaded it into my API Management instance as described in the article.我选择实现一个 Azure Key Vault,我在其中生成了一个新证书,将其下载为 *.PFX 文件,并将其上传到我的 API 管理实例中,如本文所述。

Here is an answer from @PramodValavala-MSFT这是@PramodValavala-MSFT 的回答
https://github.com/MicrosoftDocs/azure-docs/issues/26312#issuecomment-470105156 https://github.com/MicrosoftDocs/azure-docs/issues/26312#issuecomment-470105156

Here are options:以下是选项:

ps in my case I want with IP restrictions since it allows to keep all of the auth on the API Management Gateway. ps 在我的情况下,我想要 IP 限制,因为它允许在 API 管理网关上保留所有身份验证。

Or you could use:或者你可以使用:

  1. Basic auth基本认证
  2. Mutual certificate auth相互证书认证
  3. VPN虚拟专用网

to secure Azure API Management service communication with your backend service.以保护 Azure API 管理服务与后端服务的通信。

研究在 Azure API 管理上设置 TLS,以便与后端 API 的所有连接都必须通过 API 代理。

Azure API management cannot modify your backend service. Azure API 管理无法修改后端服务。 It's role is limited to being a proxy.它的作用仅限于代理。

You will have to apply authentications to each Web API or configure your firewall to accept requests only from Azure APIM.您必须对每个 Web API 应用身份验证或将防火墙配置为仅接受来自 Azure APIM 的请求。

Is your backend app an Azure Function app or an App Service app?你的后端应用是 Azure Function 应用还是应用服务应用?

If so, Managed Identity may be the simplest way to restrict access.如果是这样,托管身份可能是限制访问的最简单方法。 No need to store client secrets/certificates in the API Management + not as flaky as IP whitelisting method.无需在 API 管理中存储客户端机密/证书 + 不像 IP 白名单方法那样不稳定。

  1. Create an Azure Active Directory Application for the Function App.为函数应用创建 Azure Active Directory 应用程序。
  2. Enable Authentication/Authorization module on the Function App and reference the AAD app from step 1.在 Function App 上启用身份验证/授权模块,并从步骤 1 中引用 AAD 应用程序。
  3. Enable a Managed Identity on the APIM instance.在 APIM 实例上启用托管标识。
  4. Add a <authentication-managed-identity> policy to the APIM and reference the AAD app from step 1.<authentication-managed-identity>策略添加到 APIM 并引用步骤 1 中的 AAD 应用程序。

I've blogged about this approach in more detail in Restrict Azure Functions to API Management with Terraform我在Restrict Azure Functions to API Management with Terraform中更详细地介绍了这种方法

Reference:参考:

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

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