Forum Discussion
Using Fabric notebook token to access Azure File Share (no SAS / keys)
Hi all,
Sharing something I was able to get working in a Fabric notebook, and I’m curious if others have tried something similar or have any thoughts on it. It’s not an officially documented or supported approach, so I’m also interested in perspectives on how likely this is to remain stable vs. potentially being deprecated in the future.
Goal:
- Access an Azure File Share from a Fabric notebook (Python)
- Avoid SAS tokens or account keys
- Use Fabric/workspace identity where possible
What did work was:
- I ran the notebook in a pipeline using a Fabric/workspace identity connection.
- Retrieving a token using notebookutils.credentials.getToken("https://storage.azure.com/")
- Wrapping that token in a custom TokenCredential
- Passing it into ShareServiceClient
With this approach I was able to:
- List files and directories
- Upload files
- Read files
Here is the full code:
# ---------------------------------------------
# Connecting to Azure File share using Fabric token
# ---------------------------------------------
import notebookutils
import time
from azure.core.credentials import AccessToken
from azure.core.credentials import TokenCredential
from azure.storage.fileshare import ShareServiceClient
# ===== CONFIG =====
storage_account_name = "<yourstorageaccountname>"
file_share_name = "<yourfilesharename>"
directory_path = "" # "" = root
# ==================
# ---------------------------------------------
# Step 1: Get Fabric token
# ---------------------------------------------
raw_token = notebookutils.credentials.getToken(
"https://storage.azure.com/"
)
# ---------------------------------------------
# Step 2: Wrap token in a TokenCredential
# ---------------------------------------------
class FabricTokenCredential(TokenCredential):
def __init__(self, token):
self._token = token
def get_token(self, *scopes, **kwargs):
# Set expiry ~1 hour from now
return AccessToken(self._token, int(time.time()) + 3600)
credential = FabricTokenCredential(raw_token)
# ---------------------------------------------
# Step 3: Create client
# ---------------------------------------------
account_url = f"https://{storage_account_name}.file.core.windows.net"
service_client = ShareServiceClient(
account_url=account_url,
credential=credential,
token_intent="backup"
)
# ---------------------------------------------
# Step 4: List contents
# ---------------------------------------------
share_client = service_client.get_share_client(file_share_name)
directory_client = share_client.get_directory_client(directory_path)
print(f"Listing contents of share '{file_share_name}':\n")
for item in directory_client.list_directories_and_files():
if item['is_directory']:
print(f"[DIR ] {item['name']}")
else:
print(f"[FILE] {item['name']} ({item['size']} bytes)")
3 Replies
- deborshi_nagSuper User
Hello kentross
It's great that you've found a way to use a Workspace Identity for accessing an Azure File Share. While this avoids the need to manage a client secret as you would with a service principal, there are some important points to consider:
Token Lifetime
Fabric tokens last for one hour. If you're running long operations, this could cause issues. It's recommended to add a refresh logic—cache the token and its expiry, and refresh it when needed.
Token Intent
Setting token intent to backup is treated as an admin operation, meaning ACLs are bypassed. This is documented here:
"backup - Specifies requests are intended for backup/admin type operations, meaning that all file/directory ACLs are bypassed and full permissions are granted."
azure.storage.fileshare.ShareServiceClient class | Microsoft Learn
Public endpoints only
If your Azure File Share uses a private endpoint, your Fabric notebook may not connect using the above code. It will work in development with public endpoints, but fail in production if public network access is disabled.
- v-echaithraCommunity Support
Hi kentross ,
Thanks for sharing! This is really valuable for the community, appreciate it. - rizalard0684Resolver IIIThis is a really interesting find kentross.I just want to highlight some caveats / risks that could be of your interest:
- I don't think this is a documented or supported authentication pattern for Fabric notebooks to Azure File Share. Fabric officially documents tokens for Fabric APIs, OneLake, and selected Azure services — not File Shares.
- Token lifetime handling is manual here (hard‑coded expiry). If Fabric changes token TTLs or audiences, this may break.
- The use of token_intent="backup" is currently accepted by the SDK, but this is not guaranteed to remain stable unless explicitly documented for Fabric scenarios.
- Microsoft could tighten token audience or execution‑identity scopes at any point, which would invalidate this pattern without notice.
This works today because Fabric can issue a valid Azure Storage AAD token and the File Share REST API accepts it, but since this path isn’t officially supported by Fabric docs, there could be potential breakage and I suggest to avoid relying on it for production environment.Appreciate if you can 'Kudos' and/or 'Accept as Solution' if this answered your query.