It sounds like you're facing a challenge with securing Azure Cosmos DB while ensuring access from Azure Functions and Azure Static Web Apps, given the lack of static outbound IP addresses.
1.Use Private Endpoints for Cosmos DB
Since you want to keep the database private, setting up Azure Private Link for Cosmos DB ensures that traffic stays within Azure’s network. You’ll need to:
-Create a private endpoint for Cosmos DB.
-Integrate Azure Functions and Static Web Apps with a VNet that has access to the private endpoint.
-Configure DNS settings to resolve Cosmos DB’s hostname to its private IP.
2.Use Managed Identity for Authentication: Instead of relying on IP whitelisting, you can use Azure Managed Identity to authenticate Azure Functions and Static Web Apps with Cosmos DB. This eliminates the need for static IPs and allows secure access.
3.Consider Using Azure API Management as a Proxy:If direct access is problematic, you can introduce Azure API Management as an intermediary between your web app and Cosmos DB. This allows you to control access and apply security policies
4.Check Cosmos DB Role Assignments: Since you mentioned the Built-in Data Contributor role is missing, ensure that your Azure Functions and Static Web Apps have the correct RBAC permissions to access Cosmos DB.
5.If cost is a concern, consider using Azure App Service with VNet integration instead of Static Web Apps, as it provides more flexibility with networking.
I hope this information helps. Please do let us know if you have any further queries.