Mounting your Azure File Shares on-premises through WebDAV
In last week's post we looked at how we could use Azure Files to run a high-available, distributed FTP Server in Azure. This opens up a few interesting integration opportunities between processes running on-premises and in Azure. Today we'll take this a step further by mounting an Azure File share locally.
Azure Files supports SMB 2.1 which allows you to use native file system APIs and map a share to a drive. The only issue with SMB 2.1 is that it wasn't designed for cloud scenario's, which is one of the reasons why it's only supported within the same region. The only way to access Azure Files from outside that region (on-premises, other regions) would be through the REST API.
But by using an Azure Virtual Machine as a WebDAV gateway we can still map a file share to a mapped drive. WebDAV does not come with the native file system API support we'll find in SMB 2.1 and in addition to that the fact that it runs over HTTP will give you a lot of overhead compared to SMB. But one of the advantages here is that you can map through HTTPS.
Let's get started.
Azure Files Setup
The first thing we'll do is create a new share "corpdocuments" in our storage account "contosodata". This is the share we'll be exposing through the Virtual Machine.
Once the storage account has been created we can go ahead and deploy the WebDAV gateway. For this we'll need a Virtual Machine with IIS and WebDAV publishing. Note that all the traffic will go through this Virtual Machine, so if you really need that bandwidth it would be best not to use an Extra-Small Virtual Machine (bandwidth limited to 5 Mbps).
After installing WebDAV you can open the WebDAV Authoring Rules for the website you'll want to use. In this example I'll just use the Default Web Site.
The WebDAV Authoring Rules page allows you to enable WebDAV. Go ahead and click the Enable WebDAV action.
And now we'll use the same trick as in the previous article: create a new Windows User where the username and password match the credentials of your storage account.
And finally we'll edit the site and have it point to the Azure File Share. Now it's important to change the credentials used for accessing the share. Go to Connect As and fill in a specific user. This is where you'll be using the credentials of your storage account again.
Note: for all of this to work you'll need to make sure that you added the HTTP endpoint to the Virtual Machine (or any other endpoint on which you're running the site).
So that was pretty easy. The only thing left to do now is to mount the share as a mapped drive. Instead of pointing directly to the storage account we'll point to our Virtual Machine running WebDAV. Since we added a local user to the VM with the same credentials as our Storage Account we can just use the same credentials when mounting the drive.
And that's it! Using Windows Explorer, the command line… you can now interact with the contents of your File Share through a Virtual Machine running WebDAV. While it won't be suited for all scenarios since it lacks the native file system support, it will open up scenario's like remote backup, on-premises to cloud synchronization…