Hi @Sunny Chawla,
If I setup azure cosmos Db to accept all networks, is this approach secure?
This is not secure, turning on Allow All Networks
makes your DB open to everyone on the network. If anyone has your connection string, they can access your DB.
This can be used only for development or testing.
Can I get outbound IP address of Azure static web app?
Unlike App service or Function apps, Azure Static Web Apps do not provide a fixed outbound IP address.
Can I restrict access of cosmos Db only to this azure static web app that is publicly accessible?
You can restrict access to Azure Cosmos DBonly from a publicly accessible Azure Static Web App, but this involves a more complex configuration. Since Azure Static Web Apps do not have a fixed outbound IP address, you can't directly restrict Cosmos DB access by IP.
As an alternate you can use Function App or App service.
Check the below steps to configure with Function App:
- Create Azure Cosmos DB with MongoDB API.
Use an Azure Function as a Proxy to Secure Cosmos DB Access.
- Create a sample Azure Function and use the
Managed Identity
to authenticate and connect toAzure Cosmos DB
. - Configure Managed Identity by enabling System-assigned Managed Identity for the Azure Function.
- Assign the
Cosmos DB Operator
role to the Azure Function's Managed Identity so it can access the Cosmos DB.
Refer this MSDoc for more clear steps, it explains configuring Cosmos DB with App service and Function App.
Hope this helps
If the answer is helpful, please click Accept Answer and kindly upvote it. If you have any further questions, please reply back.