Soru

Zorluk: ZorDefine API Management Policies

You are configuring policies in Azure API Management (APIM) to expose an internal backend REST service hosted on Azure App Service. The backend service requires Microsoft Entra ID authentication and expects a token with the audience https://api.contoso.com.

The API gateway must satisfy the following requirements:
1. Authenticate to the backend App Service using the APIM instance's system-assigned managed identity.
2. Limit the incoming request rate to no more than 100 calls per 60 seconds per individual client IP address to prevent denial-of-service attempts.

Which of the following policy configurations correctly meets these requirements?

  1. <policies>
    <inbound>
    <base />
    <rate-limit-by-key calls="100" renewal-period="60" counter-key="@(context.Request.IpAddress)" />
    <authentication-managed-identity resource="https://api.contoso.com" />
    </inbound>
    <backend>
    <base />
    </backend>
    <outbound>
    <base />
    </outbound>
    <on-error>
    <base />
    </on-error>
    </policies>
    Cevap
  2. B
    <policies>
    <inbound>
    <base />
    <rate-limit calls="100" renewal-period="60" />
    <authentication-managed-identity resource="https://api.contoso.com" client-id="3f2504e0-4f89-11d3-9a0c-0305e82c3301" />
    </inbound>
    <backend>
    <base />
    </backend>
    <outbound>
    <base />
    </outbound>
    <on-error>
    <base />
    </on-error>
    </policies>
  3. C
    <policies>
    <inbound>
    <base />
    <rate-limit-by-key calls="100" renewal-period="60" counter-key="@(context.Request.IpAddress)" />
    </inbound>
    <backend>
    <base />
    </backend>
    <outbound>
    <base />
    <authentication-managed-identity resource="https://api.contoso.com" />
    </outbound>
    <on-error>
    <base />
    </on-error>
    </policies>
  4. D
    <policies>
    <inbound>
    <base />
    <authentication-managed-identity resource="https://api.contoso.com" />
    </inbound>
    <backend>
    <base />
    </backend>
    <outbound>
    <base />
    <rate-limit-by-key calls="100" renewal-period="60" counter-key="@(context.Request.IpAddress)" />
    </outbound>
    <on-error>
    <base />
    </on-error>
    </policies>

Cevap

The correct configuration applies both the rate-limit-by-key policy (using the client's IP address) and the authentication-managed-identity policy (omitting client-id to default to system-assigned identity) within the inbound section of the API policy definition.
The correct configuration applies both the rate-limit-by-key policy and the authentication-managed-identity policy in the inbound section. The rate-limit-by-key policy restricts calls per client IP using context.Request.IpAddress, and omitting client-id in authentication-managed-identity ensures the system-assigned managed identity is used.

Adım Adım Çözüm

1
Identify the correct policy tag and key configuration for limiting calls by client IP address.
Use <rate-limit-by-key> with counter-key="@(context.Request.IpAddress)". The standard <rate-limit> policy only restricts calls per subscription, which does not meet the per-IP requirement.
To limit calls by individual client IP, APIM requires the by-key policy with the Request.IpAddress variable as the counter key.
2
Determine the proper configuration for the system-assigned managed identity authentication.
Use <authentication-managed-identity> with the resource attribute set to the audience, and omit any client-id or identity-id attributes.
Omitting the client-id attribute instructs Azure API Management to use its system-assigned managed identity rather than attempting to resolve a user-assigned one.
3
Identify the correct policy sections for both policies.
Place both policies in the <inbound> section of the API management policy.
Both rate-limiting and backend authentication must occur before the gateway forwards the request to the backend service, which requires inbound execution.

Anahtar Kavram

API Management policies must be placed in the appropriate evaluation section (inbound vs outbound), and the correct attributes must be supplied to distinguish between system-assigned managed identity and user-assigned managed identity, as well as subscription-based and IP-based rate limiting.
Bu soruyu puanla