I am looking to use python code deployed in Azure Cloud (e.g. on an Azure Function), to read files location from a shared/local network drive (on-premise). The network drive requires user based authentication (i.e. different users have access/permissions to different areas).
There is an express route connection established to the local network, and I also have confirmed looking at the firewall there is nothing blocking cloud access to the shared drives.
My question is – what is the best way to read these files from local network (on-premise) to within the Azure function using python? E.g. what packages, should be used and how can user credentials be entered also.
I am unable to access with smbprotocol and can’t see the files (e.g. using the os package), and believe its due to authentication.
2
Answers
Seems to be an XY problem. Why do you want to list onprem files from an Azure function ?
I’m not sure this is even possible. But the real question is, do you really want to expose the whole locale corporate file share ? Even using the express route ?
Azure functions are a serverless Cloud natif deployment, that can connect safely and natively to Azure Blob storage.
My suggestions :
Some related answer :
You can achieve the task with python, and now that we know the connection requires authentication maybe we need to know more about the express route connection, the Azure Function (python) could require server-side and client-side connectors, however if we need to keep the current security, it is always a good idea to keep the same cloud infrastructure, we can implement a type of customer premises equipment (CPE) network connection (2 months ago this feature was still in preview):
Client or local python:
Linux will require Kerberos support: pip install smbprotocol[kerberos]
Once Client or local python has already authenticated the access to the Network Drive, you can manage it as a normal local file to read, and then we should move to the server side (Azure Function), you need to create an Azure Function to be allowed to post a file:
It will be a combination of: Creating your Azure Function to receive a FILE with a POST function and store it on Azure Blob or similar, or process it in the way desired (https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-python?tabs=asgi%2Capplication-level&pivots=python-mode-decorators#sdk-type-bindings-examples)
The function I would use for blob, client side:
The function uploads the file part by part, depending on the bandwidth and internet upload speed you can change it:
Full code (I will test it later because I have to set all the environment in Azure and local):
The CPE option could be easier and keeps the Microsoft EntraID Authentication schema, requires a work or school account and some O365 Licenses (EntraID P1 or P2)