It looks like the notebook session continues to use the Service Principal (certificate key) authentication and is not switching to the Managed Identity when writing data to ADLS Gen2.
To resolve this, please follow these steps:
Explicitly Configure Spark to Use Managed Identity - Before writing data to ADLS Gen2, ensure your Spark session is set to use the Managed Identity by adding the following configuration:
storage_account_name = "<your_storage_account_name>"
spark.conf.set(f"fs.azure.account.auth.type.{storage_account_name}.dfs.core.windows.net", "OAuth")
spark.conf.set(f"fs.azure.account.oauth.provider.type.{storage_account_name}.dfs.core.windows.net", "org.apache.hadoop.fs.azurebfs.oauth2.MsiTokenProvider")
Replace <your_storage_account_name>
with your actual ADLS Gen2 storage account name.
Verify Managed Identity Permissions on ADLS Gen2 - Ensure that your Synapse workspace’s Managed Identity has the Storage Blob Data Contributor role assigned at the storage account level. You can do this by:
- Navigating to your ADLS Gen2 Storage Account in the Azure Portal.
- Selecting Access Control (IAM) > Add Role Assignment.
- Assigning the Storage Blob Data Contributor role to your Synapse Managed Identity.
For more details refer: Grant permissions to managed identity in Synapse workspace
I hope this information helps.
Kindly consider upvoting the comment if the information provided is helpful. This can assist other community members in resolving similar issues.