Unable to connect Azure Database for PostgreSQL servers from Azure function app - azure

We have created the Vnet with virtual network gateway for point to site VPN, PostgresDB, Azure function APP.
We are able to establish connections with a point-to-site VPN.
Configuration:
Resources configuration in Azure functions:- Private endpoint and
vnet integration.
Resources configuration in PostgresDB:- Private endpoint and in
connection security set Deny public network access to "Yes"
If in PostgresDB we configured Deny public network to "No" then azure function communicating to Postgres DB and works find.
Issue :
when we are trying to access Azure DB from Private function with hostname its failed to establish the connection but it works if we replace Azure DB hostname with private IP.
Same with VPN connection when we try to connect Postgress DB with server name it doesn't work but works with private endpoint IP.
Error:-
Result: Failure Exception: OperationalError: FATAL: The public network access on this server is disabled. To connect to this server, use the Private Endpoint from inside your virtual network.
we need a solution to create a connection between the azure function to private Postgres DB.

In order to solve the above issue, please check the below points.
Enable private endpoint at Azure Function & DB
If you are denying the public network access to 'Yes' then you need to make allow Azure Service to 'Yes' and add Vnet Rule with function subnet.
Go to the private DNS zones and check vnet(Vnet in which DB & Function created) are added into the private DNS zone.

Related

Azure Private Endpoint for postgresql is not working with multiple Vnet

I have created two vnets (Main APP vnet, Reporting APP vnet both are in same region). My azure postgres database(PAAS) is hosted on main app vnet. I have created two private end point.
First private end point is used for Main App, vnet communication (DB <-> AKS) communication. It's working
Second private end point is created for establishing the database connection to Reporting app vnet. Not working.
I tried also peering the reporting app vnet to main app vnet. peering status showing as connected and second private end point status also in approved status.
But I couldn't able to connect my database using FQDN. I getting the following the error
FATAL: The public network access on this server is disabled. To connect to this server, use the Private Endpoint from inside your virtual network. FATAL: The public network access on this server is disabled. To connect to this server, use the Private Endpoint from inside your virtual network.
I checked nslookup inside reporting app vnet(inside virtual machine)DNS able to resolve. But I couldn't able to connect it via pgadmin or any app.
Not sure what I'm missing. Anyone please advise me on this
As you are using private endpoint for PostgreSQL and disabled public access for the PostgreSQL, you can do below configuration:
Create private endpoint for PostgreSQL in the vnet1 (Main App VNET)
Create peering between vnet1 (Main App VNET) and vnet2 (Reporting App
VNET)
Now, you would be able to access the PostgreSQL using the same private endpoint from both the Main App and the Reporting App.
Note: You cannot access the PostgreSQL using the public endpoint since the public access is disabled.

Unable to connect to Azure SQL through Virtual Network Gateway

I have SQL Azure Database Server (not managed instance). When setup last year, I added Azure Virtual Network Gateway, and I could access the database via the VPN connection, without whitelisting the IP.
We didn't use this connection via gateway since Jan 2020. There was only couple of developers connection but had their IP whitelisted.
Recently, we tried accessing the database using this connection, and it doesn't work. Prompting to whitelist the IP. Has something changed?
It seems that you just enable Azure virtual network service endpoints for your Azure SQL database server (not managed instance) and add this subnet to your SQL network rules. With service endpoint, the traffics go over the Internet but restrict over the network. Service endpoints and Private endpoints are two different things.
To connect to your Azure SQL database via a VPN connection, you could use a private link. Private Link allows you to connect to various PaaS services in Azure via a private endpoint. You could get the detailed steps from https://learn.microsoft.com/en-us/azure/azure-sql/database/private-endpoint-overview
Alternatively, you could try to use a TCP proxy server to forward traffic to the public IP address for SQL Database. Reference: https://argonsys.com/microsoft-cloud/library/using-a-tcp-proxy-to-connect-to-sql-database-over-vpn/

How do I connect to Azure SQL Database using Private Endpoint trough VPN gateway

PROBLEM:
I'm able to connect to the Azure SQL Database using the private link from VM within the virtual network, but not from my pc trough virtual network gateway
In sqlserver1 firewall, I have denied public network access.
From MyVM in the myvnet, I'm able to connect to the sqlserver1 using FQDN. nslookup shows correctly private address 10.0.0.4
I connected my pc to the vnet using the gateway. I'm able to ping MyVM using private adresss 10.0.0.5.
When I try to connect to the sqlserver1 using FQDN, I get error:
An instance-specific error occurred while establishing a connection to
SQL Server. The public network interface on this server is not
accessible. To connect to this server, use the Private Endpoint from
inside your virtual network. (Microsoft SQL Server, Error: 47073)
So it looks like that it's using the public dns record and not the private dns zone that I have created with the private endpoint. How can I connect to the database?
In this case, you can use NSLOOKUP FQDN on the PC to verify if the private DNS zone issue.
You need to correctly configure your DNS settings to resolve the allocated private IP address. You can follow On-premises workloads using a DNS forwarder and this blog about Azure SQL DB Private Link / Private Endpoint - Connectivity Troubleshooting.
It's not recommended to override a zone that is actively in use to
resolve public endpoints. Connections to resources won't be able to
resolve correctly without DNS forwarding to the public DNS. To avoid
issues, create a different domain name or follow the suggested name
for each service below.
To configure properly, you need the following resources:
On-premises network
Virtual network connected to on-premises
DNS forwarder deployed in Azure
Private DNS zones privatelink.database.windows.net with type A record
Private endpoint information (FQDN record name and private IP address)

Unable to connect Azure Function with Azure SQL using private endpoint

I've created a SQL Server and then created a private link with my TESTVNET/SUBNET1 with private IP 10.1.1.4. I've now disabled Public access for the SQL server.
I have an Azure function running on App Service which I've VNET Integrated with VNET/SUBNET2.
Subnet 2 shows it's delegated to server farms. (also if someone can explain what does delegate to means, I found I cannot create any VM in that subnet as well, probably it's just can't be useful for any other purpose)
Now when my azure function tries to connect to DB. it fails with below error:
2020-08-30T15:25:45.216 [Error] Unhandled rejection SequelizeAccessDeniedError: Cannot open server "10.1.1.4" requested by the login. The login failed.
However, if I give the public FQDN it gives me below error.
2020-08-30T15:29:43.654 [Error] Unhandled rejection SequelizeAccessDeniedError: Reason: An instance-specific error occurred while establishing a connection to SQL Server. The public network interface on this server is not accessible. To connect to this server, use the Private Endpoint from inside your virtual network.
Here the Private DNS created by Private endpoint should have been ideally used to get the private IP of the SQL database, but it seems the function is not using the private DNS probably because not running in an isolated environment.
Now in my Azure function Application settings, I've added WEBSITE_VNET_ROUTE_ALL =1 which should mean that all the requests should be routed to VNET. So now If I enable public access internet, and allow Azure services to access DB (I think azure added the public IP by default). The function gets connected to the DB.
Now I want to understand where I'm going wrong and why is the private endpoint connection not working. Any help is appreciated.
In the DB firewall settings, I've allowed traffic from below to subnets:
Network Configuration
TESTVNET: 10.1.0.0/16
SUBNET 1: 10.1.1.0/24
SUBNET 2: 10.1.2.0/24
I've disabled Service endpoint for SQL in both SUBNET 1 and SUBNET 2. My NSG has default settings i.e.
AllowVnetInBound, AllowAzureLoadBalancerInBound, DenyAllInBound
AllowVnetOutBound, AllowInternetOutBound, DenyAllOutBound.
Since my private link has a private IP present in the same VNET I don't think NSG should have any impact.
New to Azure, testing things out. Thank you for your patience.
To make Azure Function connect to a private endpoint you will need to use VNET integration.
After your app integrates with your VNet, it uses the same DNS server that your VNet is configured with. By default, your app won't work with Azure DNS Private Zones. To work with Azure DNS Private Zones you need to add the following app settings:
WEBSITE_DNS_SERVER with value 168.63.129.16
WEBSITE_VNET_ROUTE_ALL with value 1
These settings will send all of your outbound calls from your app into your VNet in addition to enabling your app to use Azure DNS private zones. Reference here.
Then you could set up Private Link for Azure SQL Database. You can create an Azure VM from a new subnet in the same VNet to check connectivity using SQL Server Management Studio (SSMS). If you enable the private endpoint, you should get a client private IP from that Azure VM to connect the Azure SQL database with its FQDN.
For more information, you could read private endpoint VS service endpoint in this blog.

How to connect to Azure MySQL sever from Azure VM via private endpoint

I created a private endpoint to an Azure SQL server and want to connect to it from a VM in the same virtual network. The private endpoint gives me a private IP address 10.0.0.4.
However, when I try to connect to the server on a VM using mysqlsh, it gives the the following error:
MySQL Error 2003 (HY000): Can't connect to MySQL server on '10.0.0.4' (110)
Are there steps that I've missed other than creating the private endpoint (E.g. some kind of firewall configuration)? My impression was that once I have the private endpoint, I could access the server on my VMs via the private IP address.

Resources