Microsoft Docs

Secure your API with IP Filtering in Azure API Management

IP filtering is a security feature in Azure API Management that allows you to control access to your APIs based on the IP addresses or IP address ranges that are allowed to call them. This is a crucial step in protecting your APIs from unauthorized access and potential threats.

What is IP Filtering?

IP filtering operates at the network level. When configured, API Management will inspect the incoming request's source IP address. If the IP address is not present in the allowed list (or is present in a denied list, depending on the configuration), the request will be rejected with an appropriate error response (typically an HTTP 403 Forbidden).

How to Configure IP Filtering

IP filtering can be configured at different scopes within API Management:

The most common and recommended approach is to configure IP filtering at the API or product level. Here's how you can do it using the Azure portal:

  1. Navigate to your Azure API Management instance in the Azure portal.
  2. In the left-hand menu, under the "Security" section, select Network.
  3. Choose the scope for your IP filter:
    • For global filtering, select IP Filters.
    • For product or API specific filtering, navigate to Products or APIs respectively, select the desired item, and then find the Network tab.
  4. Click the Add IP filter button.
  5. Enter the IP address or CIDR notation for the range you want to allow. For example:
    • A single IP address: 192.168.1.100
    • An IP address range: 192.168.1.0/24
    • IPv6 addresses are also supported.
  6. (Optional) Add a Description for the filter for clarity.
  7. Click Add to save the IP filter rule.
  8. Repeat the process to add more IP addresses or ranges as needed.
  9. Ensure that your desired IPs are added. If you have no IP filters configured, all IPs are implicitly allowed. Once you add your first IP filter, only the specified IPs will be allowed.
Tip: When configuring IP filters, it's often best practice to start with an allowlist of trusted IPs. Avoid using a deny list unless absolutely necessary, as it can be harder to manage and may inadvertently block legitimate traffic.

Using CIDR Notation

CIDR (Classless Inter-Domain Routing) notation is a compact way to represent a range of IP addresses. For example:

Azure API Management supports both IPv4 and IPv6 CIDR notation.

Testing Your IP Filter

After configuring your IP filters, it's essential to test them:

Note: If you are accessing your API from within a virtual network that has restrictions, ensure that the necessary outbound rules are in place to allow traffic to the Azure API Management endpoint.

IP Filtering via Management API or ARM Templates

For automated deployments and infrastructure-as-code, you can also configure IP filters using:

Here's an example of how you might represent an IP filter in an ARM template (within the ipFilterRules property of a product or API resource):


{
  "properties": {
    "displayName": "Allow specific IPs",
    "format": "ipv4",
    "address": "192.168.1.0/24",
    "mask": null
  }
}
            
JSON

Best Practices

By implementing IP filtering, you add a vital layer of defense to your Azure API Management deployment, significantly enhancing the security posture of your APIs.

Back to API Management Security