Azure URL app service not working in vnet with private endpoint - azure

Hi currently I have setup a VNET.
Inside this vnet I made a VM and I added an App-Service in the subnet with an private-endpoint.
The private-endpoint of the App-Service is also automatically added to a privatelink DNS zone. (Azure created this automatically for me) It also points correctly to the right internal ip address.
Now from within my VM I try to access my AppService using curl and using the created .privatelink.azurewebsites.net link to the AppService. But it keeps returning 404.
How is this possible. My knowledge of DNS is limited.
If I do a NSLOOKUP inside the VM, it nicely resolves the privatelink DNS Name and finds the private-endpoint ip address
What am I missing?
Update
When I keep using the original azurewebsites.net xxxxxxx.azurewebsites.net (not the privatelink) URL I can access the appservice from within the VNET.
If I am on the VM, and I do a lookup of the original URL I get this.
Non-authoritative answer:
xxxxxxxxx.azurewebsites.net canonical name = xxxxxxxxx.privatelink.azurewebsites.net.
Name: xxxxxxxx.privatelink.azurewebsites.net
Address: 10.1.1.4
So there is some magic behind the scenes?

When you create a public Azure App Service "xxxxxxxxx", beside provisioning the app service environment also a DNS entry for this new service will be created in one of Microsoft's authoritative DNS servers (they are usually named like ns1-xxx.azure-dns.com) ultimately pointing to the public IP address of the server where your your app service is hosted.
If you add a private endpoint for your app service, the DNS entry in these servers won't be removed. Instead what's happening is that internet access to your web app is cut off using firewall rules.
This means if you type in "xxxxxxxxxx.azurewebsites.net" in your browser outside the VNet, a DNS query is sent and the public IP address of the server is returned. Your browser sends a HTTP query to that IP address but will get a HTTP status code 403 indicating that public traffic is blocked.
Inside your VNet the situation is different. As you described you got a private DNS zone "privatelink.azurewebsites.net" which is linked to the VNet (you can see that in the "Virtual network links" section)
If you now type "xxxxxxxxxx.azurewebsites.net" in a browser in your VM which is placed in the same VNet as xxxxxxxxxx.azurewebsites.net, the DNS server associated with the network adapters (by default accessible in your VM through 168.63.129.16) will use the entries placed in the private DNS zones. If a zone named "privatelink.azurewebsites.net" exists, all queries for the domain "azurewebsites.net" will be resolved using this private DNS zone. For example, if there is an A record entry for "xxxxxxxxxx" for 172.16.0.5...
...this is exactly the IP you'll get when you resolve xxxxxxxxxx.azurewebsites.net in your Azure VM:
C:\Users\vm>nslookup xxxxxxxxxx.azurewebsites.net
Server: UnKnown
Address: 168.63.129.16
Non-authoritative answer:
Name: xxxxxxxxxx.privatelink.azurewebsites.net
Address: 172.16.0.5
Aliases: xxxxxxxxxx.azurewebsites.net
If you delete your private DNS zone, the DNS server will resolve back to ns1-xxx.azure-dns.com which in turn will give you the public IP of the service:
C:\Users\vm>nslookup xxxxxxxxxx.azurewebsites.net
Server: UnKnown
Address: 168.63.129.16
Non-authoritative answer:
Name: waws-prod-am2-459-d21a.westeurope.cloudapp.azure.com
Address: 20.50.2.66
But since the app service still has firewall rules applied that block all traffic coming from outside the VNet, you will get a HTTP status code of 403 if you try to access the service over a browser.
See also: https://learn.microsoft.com/en-us/azure/app-service/networking/private-endpoint#conceptual-overview

Related

Azure Virtual Machine cannot resolve DNS entry of Application Gateway

I have the following situation:
If I deploy an application (Deployment, Service and Ingress) in my kubernetes cluster, my ingress deployment is being automatically added to my application gateway (I am using the Azure Application Gateway Ingress Controller; https://azure.github.io/application-gateway-kubernetes-ingress/annotations/ ). So far so good.
That means that my application can be reached via my application gateway via https://my-app-gateway-public-ip/myAppPath/. Also, I have an additional private DNS zone which makes my app accessible via https://dns-name/myAppPath.
Additionally, we have an AADDS in combination with a Bastion Service. Deployed some virtual machines and the virtual machines use the DNS resolver of the AADDS (for authentication against the AAD).
The problem is: If I am outside of the cloud, I can nslookup the dns or can access the site via the ip, but I cannot do that with my virtual machines. My DNS server (within the AADDS) is unable to resolve the dns or accessing the ip. I am wondering what the issue is.
The bastion and AADDS are in different subscriptions and therefore different virtual networks. I established already a peering between those virtual networks (or the authentication between the AADDS and the VMs wouldn't work).
The kubernetes cluster and the application gateway are also in a different subscription, but no peering has been done so far.
Are there any hints what I could be missing?
Kind regards
• Since, you are using a Bastion gateway server to connect to the VMs hosted in your subscription, the Bastion gateway server must be having a public IP address through which then the registered underlying VMs can be connected to via private links created in the private DNS zones associated with a particular virtual network in a subnet and an assigned private IP address and a FQDN accordingly. Thus, if you want to access the application website hosted behind the application gateway, then you will have to create a conditional forwarder in the DNS zone in AADDS to redirect the internal requests from the VMs hosted within a virtual network to the public IP address of the website hosted behind the application gateway
• Thus, a conditional forwarder forwards the DNS resolution requests for a particular resource hosted on the public internet for which the DNS host resolution is not found or done in that DNS zone which usually serves or fulfils the requests related to internal environment. As a result, when a VM configured with a private IP is registered as a host in the internal DNS zone queries the public IP or FQDN associated with the application’s website, the DNS requests are forwarded to the public internet through the conditional forwarder and then the results are displayed in the VM’s browser for the application’s webpage. Thus, the VMs don’t need to have internet access but the DNS server should have or should forward the requests through the Internet proxy server accordingly to reach the internet.
For more information on creating conditional forwarder in AADDS, kindly refer to the below link: -
https://learn.microsoft.com/en-us/azure/active-directory-domain-services/manage-dns#create-conditional-forwarders

App Service Private Endpoint with Custom Domains gives Error 403 - Forbidden

I'm on the last stage of my journey to try and lock down public access to app. After a bunch of research I decided on using "Private Endpoints" so that only when on work VPN can we access apps. I did manage to get this to work however when I setup custom domains in the VNet it no longer works. I've looked at countless resources and even hit second page of Google a few times...
Basic Setup
I have setup a VM and an out of the box Node App Service in Azure. Both are accessible publicly. I have setup Private endpoints for the appservice and put both on the same VNet. The VM can reach the app nicely, and publicly I can't (yay!)
Here's what I see:
here's my VNet DNS settings
here's the app working on a VM on the VNet.
When it doesn't work
So the above works - but I want to supply my own DNS servers so I can resolve stuff on our internal network which is peered to the VNet. All I do is update the DNS settings to include my custom ones and the Amazon one (just in case)
Now I get a 403 - Forbidden as if I'm accessing it externally:
Several of the tutorials mentioned updating the host file as a test (vs updating internal DNS). I believe I did this like they were showing - but same result
I'm near giving up and using a separate VNet for Inbound/Outbound since I only need the custom DNS on the outbound.
Random Resources
https://www.youtube.com/watch?v=8Zof54j8qWk&ab_channel=WintellectNOW
https://learn.microsoft.com/en-us/azure/private-link/create-private-endpoint-portal#create-a-private-endpoint
https://learn.microsoft.com/en-us/azure/app-service/networking-features#private-endpoint
https://learn.microsoft.com/en-us/azure/app-service/networking/private-endpoint
https://learn.microsoft.com/en-us/answers/questions/264747/azure-app-service-with-private-endpoint-throws-403.html
https://learn.microsoft.com/en-us/answers/questions/11844/403-forbidden-access-is-denied.html
After azure publish my domain gives 403 error
Azure App Service Deploy returns (403) Forbidden with IP restriction
WebApp private endpoint azure vpn
Azure API Management with custom domain getting HTTP 403 error
Periodically getting 403 IP Forbidden on App Service with private endpoint
Your internal DNS should forward .azurewebsites.net zone to DNS Forwarder in Azure which then would resolve to private endpoint IP address using default Azure DNS address - 168.63.129.16.
Private Links can only be resolved from Azure (via Virtual Network Link between private DNS zone and virtual network) so without conditional DNS forwarder configured for your internal DNS, it resolves address using public DNS and that's why it doesn't work.
Take a look here at the second example (with own internal DNS server) - https://learn.microsoft.com/en-us/azure/private-link/private-endpoint-dns#on-premises-workloads-using-a-dns-forwarder

How to set up endpoints within a Azure Virtual Machine

I'm trying to set up MailTrain (a newsletter application) on an Azure VM. I created a resource group with the virtual machine, a virtual network, a network interface, a network security group, a public ip adress and a private DNS zone.
MailTrain expects three URL endpoints which all point to the same IP adress. For testing purposes I would like to create internal endpoints which all point to the VM. I played around with DNS entries in the DNS zone, but it doesn't work as I expected.
The name of the private DNS zone is equal to the DNS name of the VM's public IP adress. The private DNS zone and the VM are linked with the virtual network link and auto registration is enabled. The virtual network contains a default subnet. I created an A entry for "lists" pointing to the VM's internal IP adress and a CNAME entry for "sbox" pointing to the DNS name of the public IP adress. Inbound rules for the ports 80 and 443 were added to the netwwork security group.
The console shows me the following message while running the installation script:
Domain: lists.xxx.cloudapp.azure.com
Type: None
Detail: DNS problem: NXDOMAIN looking up A for
lists.xxx.cloudapp.azure.com - check that
a DNS record exists for this domain
Domain: sbox.xxx.cloudapp.azure.com
Type: None
Detail: DNS problem: NXDOMAIN looking up A for
sbox.xxx.cloudapp.azure.com - check that a
DNS record exists for this domain
Domain: xxx.cloudapp.azure.com
Type: unauthorized
Detail: Invalid response from
https://xxx.cloudapp.azure.com/.well-known/acme->challenge/VIjYMd-Uic_T2lQBl4vSyy9Va46-yVxmTA8SSE3f8J8
[xxx.xxx.xxx]: "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML
2.0//EN\">\n<html><head>\n<title>503 Service
Unavailable</title>\n</head><body>\n<h1>Service"
Followed that quick start, you just need to create three DNS records in your public domain DNS zone.
Please note that there is public DNS and private DNS in Azure. In this case, I assume you have created a private DNS zone for internal endpoints. To resolve the records of a private DNS zone from your virtual network, you must link the virtual network with the zone. Additionally, you can also enable autoregistration on a virtual network link. If you enable auto registration on a virtual network link, the DNS records for the virtual machines on that virtual network are registered in the private zone. Or, you can manually create an A record to map to your VM's private IP address in the zone and create other CNAME records to map to the other internal endpoints.
As a best practice, do not use a .local domain for your private DNS zone. Not all operating systems support this.
In addition, you need to add inbound ports 80, 443 in your network security group that associated with the Azure VM subnet or NIC.
Update
For an internal test, you can use a private DNS zone because the DNS records in a private Zone can only be resolved in a virtual network it can not be resolved over the Internet, you could select the local installation in this scenario.
For example, I create a private DNS zone named contoso.com,
After local install, you can access the website via the trusted endpoint http://localhost:3000, then you should access the other endpoints in the VNet instead of access external.
However, if you want to use it for public access, you could select to install a public website secured by SSL. In this case, you need to purchase a domain and add the related DNS records to the DNS zone in the respective DNS provider. Azure DNS zone supports host your public domain zones in Azure.

Azure DNS zone record not resolving to specified IP from App service to Virtual Machine

I followed the documentation guide here to configure an Azure DNS zone for a virtual network.
I then created a virtual machine on that virtual network and provisioned a virtual network gateway to allow my Azure web apps to communicate with the virtual machine using VNet integration. My web apps are then able to resolve against the virtual machines private IP as expected.
I then created an 'A' type record set within the DNS zone resolving a service name against the private IP of the virtual machine just like here.
However, when I then attempt to access the DNS configured service name that should resolve against the private IP address of the virtual machine, I get the following error:
curl: (6) Could not resolve host: xxxx.local
Am I missing something obvious here?
I can not reproduce this error following your steps:
Create an Azure VNet with a DNS private zone like private.test.com.
Create a VM and a VPN gateway on that VNet.
Enable VNet integration with my Azure web app service.
My web apps are able to resolve against the virtual machines private IP as expected. This could verify the Azure private DNS zone should work. Then I also create an A record for a custom name against the VM private IP address. Both scenarios work.
You could check if an A record is something like below picture in the private DNS zone.
Then you could verify if curl with http:// or without that, or without the specific port 9200, the error is still the same.
I suggest using SET WEBSITE_DNS_ command. This command will output the current DNS server that is being used by the web app. If the error Environment variable WEBSITE_DNS_ not defined is received, no custom DNS servers are configured for the web app. See more details about networking Related Commands for Azure App Services.

exposing Azure DNS servers

I have an Azure virtual machine with multiple web sites on it that I would like to expose to the Internet. The VM has Active Directory and DNS installed on it. I created the forward zone (xxx.cloudapp.net) on my server, and added the two web site names to the zone. On the Networks in the Management Portal, I added a DNS server(xxx.cloudapp.net) and gave it the public IP for my server.
So when I try a nslookup from outside of the VM, the names will not resolve. I set the server in nslookup to either the public IP or the name, and it does not resolve. I have logging turned on in the DNS server, but it does not seem to show any requests from my computer.
I must be doing something wrong. Any suggestions? This server is for a demo next week, and worst case, I can buy a couple of domain names.
Try the instance level public-ip address, you will get an ip address per virtual server: https://azure.microsoft.com/documentation/articles/virtual-networks-instance-level-public-ip/

Resources