Permission Denied Error (403) When Connecting to Azure OpenAI and Cosmos DB from Azure Synapse Analytics

Sooriya E 10 Reputation points
2025-08-05T09:27:45.66+00:00

Hi Team,
When attempting to connect to Azure OpenAI and Azure Cosmos DB from an Azure Synapse Analytics notebook, a Permission Denied error (code 403) is encountered due to firewall rules or virtual network settings. Both Azure OpenAI and Cosmos DB accounts are configured to allow all networks, not restricted to selected networks, and there are no virtual network or firewall rules applied. Assistance is requested to resolve this issue.

Error received:

PermissionDeniedError: Error code: 403 - {'error': {'code': '403', 'message': 'Access denied due to Virtual Network/Firewall rules.'}}
Azure Synapse Analytics
Azure Synapse Analytics
An Azure analytics service that brings together data integration, enterprise data warehousing, and big data analytics. Previously known as Azure SQL Data Warehouse.
{count} votes

2 answers

Sort by: Most helpful
  1. Sooriya E 10 Reputation points
    2025-08-06T07:43:43.1266667+00:00

    Hi Harish,

    Good Afternoon. I have owner level permission in the resource group level. Yesterday I tried with selecting all networks in Azure OpenAI and got the same issue. So I changed it to selected networks and added my public IP and tried still got the same issue. So I followed this below link:
    https://learn.microsoft.com/en-us/azure/synapse-analytics/security/gateway-ip-addresses

    and ran again the notebook then it got success and got the expected output I will attach that screenshot for your reference. So my concern is in between it worked but again when I tried it is not working. Would need your assistance on this also one more question in selected is there any limit for adding the IP address maybe that could cause any issue?
    User's image

    Thanks,
    Sooriya E


  2. Harish Peddapally 0 Reputation points Microsoft External Staff Moderator
    2025-08-06T08:35:16.0333333+00:00

    Hi Sooriya E ,

    Thank you for the update and for providing those valuable details. It's very helpful to know what you've tried and what you've observed.

    Let me address your findings and your new questions:

    1. Why did adding the Synapse gateway IP addresses work temporarily?

    The Azure Synapse gateway IP addresses are used for certain control plane and management communications. When you added these to your firewall rules, you may have temporarily opened a path that allowed a specific part of the request to succeed. However, this is not a reliable long-term solution for notebook execution.

    The main reason for the inconsistency is that the "Azure Synapse Spark pool's egress traffic does not originate from these fixed gateway IPs". The traffic from the Spark pool, which is running your notebook code, originates from a pool of dynamic IP addresses within the Azure data center, and these are not guaranteed to be consistent. This is why the connection worked once and then failed—the next time the notebook ran, its outbound traffic likely came from a different, unwhitelisted IP address.

    2. Is there a limit to adding IP addresses?

    Yes, there can be a practical limit on the number of IP addresses you can add to a firewall rule for a service like Azure Cosmos DB or Azure OpenAI. The limit varies by service.

    3. The Recommended Solution:

    The temporary success you saw with the gateway IPs reinforces the original recommendation. The most robust, secure, and permanent solution for connecting an Azure Synapse notebook to other Azure services is to use a "Managed Virtual Network and Managed Private Endpoints."

    This architecture is specifically designed to handle this exact scenario. It ensures that all communication between your Synapse Spark pool and resources like Azure OpenAI and Cosmos DB happens over a secure, private network link, bypassing the public internet and any IP-based firewall rules.

    Next Steps what you can is:

    as far as i understand your Synapse workspace was not created with a Managed VNet, the only way to implement this solution is to create a new Synapse workspace and ensure the Managed Virtual Network option is enabled during the creation process. Once the new workspace is created, you can then set up the Managed Private Endpoints to your Azure OpenAI and Cosmos DB accounts.

    This will provide a stable and secure connection that will not be affected by dynamic public IPs, resolving the inconsistency you are experiencing.

    Thank you again for your time. I’m happy to continue supporting you—your experience and insights can also benefit others in the community.

    Please do not forget to "Accept the answer” and “upvote it” wherever the information provided helps you, this can be beneficial to other community members.it would be greatly appreciated and helpful to others.

    Thanks,

    Harish.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.