BlogPostPage

Retour aux articles

Azure Application Gateway and Api Management: Preserve client IP address

 Azure Application Gateway and Api Management: Preserve client IP address

When using a Front with Azure Api Management, the IP address returned is that of the front, not the client. With the implementation of an Application Gateway, it is the IP (v6) of the app gateway which is transmitted to API Management.

What's the problem? A problem arises if we wish to restrict IP at the API management level.

Solution :
Application Gateway
Propagate the client IP from the APP Gateway to API Management using a redirect.
Add this rule in Rewrites / Rewrite rule:
image

Pay attention to the naming of the variable "var_client_ip"

Api Management
Modify the ip-filter filter rule with a check-header rule:

<set-header name="X-Forwarded-For" exists-action="override">
		<value>@{
				string xForward = context.Request.Headers.GetValueOrDefault("X-Forwarded-For");
				return xForward.Contains(",") ? xForward.Split(',')[0] : xForward;
				}</value>
</set-header>
<check-header name="x-forwarded-for" failed-check-httpcode="403" failed-check-error-message="Unauthorized" ignore-case="true">
		<value>ipX</value>
		<value>ipY</value>
</check-header>

Commentaires (0)

Aucun commentaire pour le moment. Soyez le premier à commenter !

Laisser un commentaire

Votre email ne sera pas publié.

© 2025 Pierre-Henri

Tous droits réservés.

Projects
Privacy Policy

Développé avec et .NET

An unhandled error has occurred. Reload 🗙

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please reload the page.