Share via

Unable to access ADLS Gen2 through Spark while manually running a notebook in Synapse Analytics Studio

Ashwin R 0 Reputation points
2025-07-21T07:35:18.4266667+00:00

I'm trying to read a csv file from my ADLS container through Spark using a linked service but when I run my notebook I'm getting java.nio.file.AccessDeniedException: Operation failed: "This request is not authorized to perform this operation.", 403, HEAD but when I run the same notebook through a pipeline it seems work just fine, so much so that I don't even need to set any spark.conf. My synapse workspace has Blob Storage Data Contributor access and my account has User access to the storage account. My linked service uses System Managed Identity.

I have attached the code below and the error

Py4JJavaError: An error occurred while calling o4538.csv.
: java.nio.file.AccessDeniedException: Operation failed: "This request is not authorized to perform this operation.", 403, HEAD, https://myaccount.dfs.core.windows.net/fsglasdp/?upn=false&action=getAccessControl&timeout=90
from notebookutils.mssparkutils import fs
from notebookutils import mssparkutils
from pyspark.sql import SparkSession


source_full_storage_account_name = "myaccount.dfs.core.windows.net"

linked_service_name = "mylinkedservice"

spark.conf.set(
    f"spark.storage.synapse.{source_full_storage_account_name}.linkedServiceName",
    linked_service_name
)

sc._jsc.hadoopConfiguration().set(
    f"fs.azure.account.oauth.provider.type.{source_full_storage_account_name}",
    "com.microsoft.azure.synapse.tokenlibrary.LinkedServiceBasedTokenProvider"
)


df = spark.read.csv('abfss://<container>@<myaccount>.dfs.core.windows.net/path/to/folder/mycsv.csv') 
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.


1 answer

Sort by: Most helpful
  1. Ashwin R 0 Reputation points
    2026-04-13T06:11:53.47+00:00

    Hey, I know it’s been a while since I posted this question, but I finally had some time to revisit it and found a solution.

    Config:

    My Synapse workspace is not in a Managed VNet, so there shouldn’t be any restriction on outbound network access. I also verified that the “Allow Azure services and resources to access this workspace” option is enabled in the networking tab.

    On my ADLS Gen2 storage account, I enabled “Allow trusted Microsoft services to access this resource” under the networking settings. Additionally, I added my Synapse workspace as a resource instance with access to the storage account. The workspace’s managed identity has Storage Blob Data Owner, Contributor, and Reader roles assigned. I also granted full rwx ACL permissions to this managed identity for the entire container.

    Despite all these configurations, I was still getting the following error when trying to read or write files using Spark from Synapse:

    Operation failed: "This request is not authorized to perform this operation.", 403, HEAD

    What made this confusing was that the issue only occurred when running the notebook interactively (using the managed identity in the Spark session), and not when running it through a pipeline.

    Solution:

    After some investigation, I discovered that adding a private endpoint to the ADLS Gen2 storage account resolves the issue. You can do this from the Synapse Manage tab under the Security → Managed private endpoints section. Once created, make sure to approve the private endpoint in the storage account.

    This solution worked in my case.

    TL;DR: Add a private endpoint from Synapse to your ADLS Gen2 storage account.

    Was this answer helpful?

    0 comments No comments

Your answer

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