Hello Rich S,
Welcome to the Microsoft Q&A and thank you for posting your questions here.
I understand that you would like to securely connect your Next.js application hosted on Azure Static Web Apps to an Azure MySQL Flexible Server, while restricting access to only your application and office IP.
The below are a few options you will need to achieve your goal:
- Make sure that your Static Web App is integrated with the VNet (using VNet integration for Azure Functions if your Static Web App has backend APIs) and configure NSGs and DNS correctly to route traffic through the private endpoint. The best practices is that you should use Azure Private DNS Zones to resolve the private IP of the MySQL server, and your Static Web App has proper permissions and routing to access the private endpoint.
- Use managed identity to securely retrieve database credentials (stored in Key Vault), but pair it with network security methods like private endpoint.
- Add firewall rules for your Static Web App's outbound IP address (found in the Azure portal) and your office IP and make sure you avoid using "Allow Azure services" if you want stricter control. Also, if your IP changes frequently (e.g., office has dynamic IPs), this may require frequent manual updates or automation.
- Integrate Azure Private Link with your MySQL Flexible Server and make sure Static Web App is configured with VNet integration and Private Link can resolve MySQL through DNS.
- Use this feature to manage your connection string securely but combine it with private endpoints or firewall rules for network security.
However, given your requirements, I will advise you to securely connect MySQL and Static Web Apps within a VNet and temporarily use firewall during testing but avoid leaving it as the long-term solution. Then, make sure you combine it with Key Vault and Managed Identity to store and access credentials securely.
I hope this is helpful! Do not hesitate to let me know if you have any other questions.
Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful.