I want to restrict access of my azure Kubernetes nginx ingress only for a particular location (api path) , only to be accessed from azure front door.
I have a configuration snippet, but how to apply it to only a particular path
nginx.ingress.kubernetes.io/configuration-snippet: |
if ($http_x_azure_fdid !~* "xxxxx-xxx-xxx-xxxxxx")
{
return 403;
}
To restrict access of your Azure Kubernetes nginx ingress only for a particular location (api path), and only to be accessed from Azure Front Door, you can use the
nginx.ingress.kubernetes.io/configuration-snippetannotation in your ingress YAML file. The snippet you provided is a good start, but you need to modify it to apply only to a particular path. Azure Front Door doesn't automatically add anX-Azure-FDIDheader to requests. You will need to manually configure Azure Front Door to add a custom header to its requests if you want to use a custom header for filtering. Assuming you have configured Azure Front Door to add anX-Azure-FDIDheader to its requests, here is an example of how you can modify the snippet to apply only to the/apipath:This snippet will only apply to requests that match the
/apipath. Requests to other paths will not be affected by this snippet.Ingress:
References: