External Facing ASE behind WAF - azure-web-app-service

I have created the External facing ASE with a single Web App. Trying to place a WAF enabled Application Gateway.
I have configure the Application gateway subnet and frontend to Public facing.
To interconnect the WAF with ASE(APP), i have set the target of the App hostname (FQDN) in the Backend pool. After mapping the target, i have verified the backendpool health which states Healthy.
Now i tried to access the Frontend IP and FQDN of Application gateway, i'm getting the below error
"The resource you are looking for has been removed, had its name changed, or is temporarily unavailable."
action taken - Tried without NSG and also allowing NSG in ASE subnet
Need your help, I'm in middle of the Environment setup.
Suspect the hostname resolution is missig and not sure how to overcome this block

"The resource you are looking for has been removed, had its name changed, or is temporarily unavailable."
Every Azure Web App has a collection of host names. A request will be transfer to the dedicated server instance depends on the host name in HTTP request message. If the host name doesn't match one of the host names which configured in Azure portal. The Azure Web App can't be reached.
You could view the default host name in Azure portal.
Since you accessed your Web App by Frontend IP or FQDN of Application gateway, their host names will not match the host name of your Web App.
There are 2 ways to fix it.
To simple test your Application gateway, you could be able to use something like ModHeader Chrome extension to open the public IP address/hostname of the Application Gateway in the browser, and pass in the host name of your Web App you configured on the Web App as a Host Header and the website should come up.
Register a custom domain(For example, abcd.com) in a domain provider(For example, Godaddy). In the DNS setting of your domain, add A record to the IP address of your Application gateway.
After that, you also need to add host name by click add host name button in Azure portal.

Related

Azure: Application gateway listeners based routing. A communication error occurred: "Operation timed out"

We have configured Listeners and add the rules and upload the SSL certificate on Azure portal
But the server is not hitting the URL. Suggest me if there any settings i missed to configure to enable the listeners based routing settings
When you access a host name via the App gateway, the DNS resolves that host name to the public IP address of the App gateway (which should be configured as a CNAME in your DNS or local host files) and then the app gateway uses that host header to find the associated listener. Once it finds the correct listener, it checks the associated rule and use the configured http settings to direct the traffic to the configured backend service.
Without the CNAME mapping in your DNS, the application gateway will not be aware of the host name/domain name that you are using to access the site.
If you have not created a CNAME mapping to your Application gateway's IP in your DNS, you can also make use of host files in your local machine for the name resolution as part of testing.
Reference : https://learn.microsoft.com/en-us/azure/application-gateway/create-multiple-sites-portal#edit-your-hosts-file-for-name-resolution

Azure App Service behind Azure Application Gateway

I'm trying to serve multiple Azure App Services behind an Application Gateway. These services should only be reachable through the application gateway endpoint. To achieve this, I've done the following:
Added a VNet
Added a subnet, and added all app services to it
Added an application gateway with appropriate rules for pointing to the app service
Added access restrictions to the app service to only allow the subnet of the application gateway, and the public IP of the application gateway
The health probe of the application gateway indicates the service is healthy (and thus reachable), but when I try to make a request to the service trough the gateway using Postman, I get a 403 IP forbidden error. However, when I add my local IP as an allowed IP address to the app service, the request comes through just fine
From what I've read online, adding the public IP of the gateway should be sufficient for allowing access through the gateway, but it seems that requests from my local machine are blocked. Am I getting something fundamentally wrong here?
Edit: I also tried assigning a front-end private IP address to the gateway and adding access for that in the app service, but that also did not work
Edit 2: My configuration
Access restrictions for app service:
access restrictions
Backend pool:
Backend pool
HTTP settings:
HTTP settings
Listener:
Listener
Rule:
Rule
From your description "Added a subnet, and added all app services to it", I assume that you are meaning integrating app with Azure VNet or enable the service endpoint with Microsoft.Web for the subnet. If so, you could remove them. Both are useless in this scenario.
To restrict the access through the gateway, you only need to add the frontend IP address to the Azure App Service access restrictions. For more details, you could refer to this blog https://www.cloudmanav.com/azure/restricting-appservice-accessible-via-appgateway/#
If you have NSG associated with the subnets, you could follow the prerequisites here
https://learn.microsoft.com/en-us/azure/application-gateway/configuration-overview#network-security-groups-on-the-application-gateway-subnet
Edit
You may have redirection configured on your app service or have Azure Active Directory authentication, which causes the redirection. So when redirection happens, the client makes the request directly to app service URL Path contoso.azurewebsites.net/xxx instead of going through the application gateway URL path contoso.com/xxx.
To fix it, you could use a custom domain name to pass the same host name that the application gateway receives to the app service as well, instead of doing a host override. Get more details about this solution here.

Is it possible to create the equivalent of a hosts file in an azure web app

I'm migrating asp.net services that used to exist on a physical server on-premise to Azure. However they need to reach some web-services (SOAP) that will not be migrated to azure yet. These have a public IP but I need to set the hostname in order for IIS to properly redirect the requests to the correct service as there are several on the same server. Is there any way to create some sort of DNS-server in azure that is only available for the services created in azure that can resolve to the public IP-address outside of azure? (We have used the hosts file on the servers to achieve this previously)
I tried using the private DNS Zones, but as I've understood it they can only point to other azure services within the same vnet (correct me if I'm wrong). I've also tried creating a dnsmasq docker container. However, as this is running in a Linux container, it seems that I cannot put it in the same vnet as the asp.net app services. Thus I am unable to retrieve a private IP-address that these services can use to reach the DNS server.
In my understanding it is now possible to use Azure DNS Private Zones if you want.
You would need to use regional vnet integration to point your app's traffic to a vnet that is connected to the Private Zone. You need the following settings as well, which mean that all outbound traffic from the Web App is routed through the integrated vnet first, and that the Azure default DNS server is used for DNS.
WEBSITE_DNS_SERVER with value 168.63.129.16
WEBSITE_VNET_ROUTE_ALL with value 1
https://learn.microsoft.com/en-us/azure/app-service/web-sites-integrate-with-vnet#azure-dns-private-zones
If you don't want to use Azure DNS Private Zones, I think you can achieve similar results by directing the Web App to use a specific DNS server. This can be done using WEBSITE_DNS_SERVER and WEBSITE_DNS_ALT_SERVER app settings (the values are the IP addresses of the servers you want to use).
This is the most authoritative public statement I can find about using these settings.
Go to the web app->settings->Application Settings-> App Settings
section
Add the following: (WEBSITE_NODE_DEFAULT) should already be
there.
a. WEBSITE_DNS_SERVER with value having the IP address of the
primary DNS server.
b. WEBSITE_ALT_DNS_SERVER (optional), with value
having the IP address of a second DNS server.
Then save the settings & restart webapp in portal.
Double check the web app can actually
connect to the DNS server: a. In kudu console, run: Nameresolver.exe
[hostname-to-lookup] [dns-server-to-use]
First argument should be the
hostname you are trying to look up, second argument is one of the DNS
servers from step 1) If this times out, there is an issue with how
your DNS servers are configured (firewalls, etc.)
https://github.com/MicrosoftDocs/azure-docs/issues/13927#issuecomment-416382230
If using these settings with a DNS server that is only accessible via private IP, you would need to use regional vnet integration again to connect to a vnet. If the DNS server is on-prem, you have to connect through the integrated vnet over VPN or ExpressRoute.
It's possible but not using the private DNS Zone.
According to Name resolution for resources in Azure virtual networks. For the scenario Name resolution from App Service Web Apps in one virtual network to VMs in a different virtual network, you need to use your own DNS servers forwarding queries between virtual networks for resolution by Azure (DNS proxy). See Name resolution using your own DNS server.
In this case, you only allow this azure web service could resolve the public IP address outside of Azure. You could enable virtual network integration for your web app, this restricts your web app access in a private network. Then you could deploy a DNS server in the same Vnet as the web app integrated VNet. You could create an A type record in your DNS zone to point to your service Public IP, then add the DNS server's IP address into the DNS server of the Integrated web app Vnet in the portal. If so, the web app could resolve this public IP via a custom DNS server.
Hope this could help you.

URL rewrite configuration on Azure

I have WAF, Application Gateway and a VM in place in Azure cloud. I have deployed an application in VM, which is running on tomcate and on port 8280.
I have domain name www.abc.com. In DNS entry, www.abc.com is pointing to my Azure App Gateway on port 80.
I am able to access the my application using IP and port. for example:-
http://X.X.X.X:8280/MyApps/page1 and http://X.X.X.X:8280/MyApps/page2.
I am trying to configure App Gateway, so that when I try to open using domain name. My requirement is when I hit www.abc.com, it should redirect to URL www.abc.com/page1. I tried to setup the listener with basic type and also path based. But no success. When I try to hit www.abc.com, it throws error:
502 - Web server received an invalid response while acting as a gateway or proxy server.
The 502 error always shows that there is a firewall restiction from your application gateway instance to your backend VM. You can verify if there are blocking the traffics in the NSG associated with your application gateway subnet or VM subnet. Also, this might be caused by inproperly configuring the custom health probe. You also can get more reasons from this doc.
Moreover, you can confirm you have set the url-based path correctly. Pay attention to the path and port.

Error 502 while using Application Gateway with App Service Environment

I have setup Application Service environment and trying to access WebApps inside App service environment through Application gateway. Below are the steps I followed to create required setup however I am getting "502 - Web server received an invalid response while acting as a gateway or proxy server" error when I hit the URL that is mapped with application gateway public URL
Created Vnet and created App Service environment inside separate subnet, used subdomain name as dev.xyz.com. I used ILB wild card certificate here issued to *.xyz.com
Created app inside App service environment and named it as "dev-web.dev.xyz.com" and added externally accessible DNS name in the custom domain as "dev-web.xyz.com"
Created Application gateway, added Internal IP address of ILB ( App Service Environment) as back end pool
Created App Gateway-HTTP Settings using port 80 and mapped it with custom probe
Created App Gateway-CustomProbe, host name used here is extenally accessible DNS name which is "dev-web.xyz.com"
Created App Gateway-Listner using host name as extenally accessible DNS name which is "dev-web.xyz.com"
Added a basic rule and mapped above resources with each other
I am still not able to access my Web App after acessing dev-web.xyz.com
I am not sure about how port number used to create listner affect the setup or if I am missing anything.
I also want to implement SSL once I am done with above testing, I would appretiate inputs on how to implement that for above setup.
Created App Gateway-Listner using host name as extenally accessible DNS name which is "dev-web.xyz.com"
After created your App Gateway, a default listener is created to bind the front end IP and port 80 for you. The listener means the App Gateway will monitor the requests which were send to the IP address and port and forwarding the requests to the backend resources. Since you add a host name 'dev-web.xyz.com' as its listener. The App Gateway will also monitor the requests which were send to the host. It will cause a infinite loop forwarding due to the listener host is also marked as the backend host.
To fix the error, you need to remove the App Gateway-Listener record which you added.
I was able to resolve the issue by mapping correct port for the listener. Listener won't harm if you have correct rule setup in the configuration.

Resources