Code Monkey home page Code Monkey logo

azurefilesfuse's Introduction

Azure Files FUSE Driver

Enables using SAS Tokens for mounting Azure Files shares

Build Status

Motivation

I wanted to be able to use Shared Access Signature (SAS) Tokens for connecting to file shares. Microsoft Azure Files provides CIFS/SMB mounting but, unfortunately, only mounting via Account Key is supported.

But why would I care about mounting via SAS instead of Account Primary/Secondary key?

Azure Storage primary and secondary keys grant full read/write/delete access to that storage account. This means that the machine with the SMB/CIFS mount, if somehow was compromised, the secret present would gain broader access to Azure than the CIFS/SMB mount ever had leveraged. This violates the principle of least privilege. For this reason, I created this project.

Using Azure Files FUSE Driver

Quick Setup (Assumes Ubuntu 16.04 LTS or similar)

sudo apt-get -y install python3 python3-pip fuse
sudo pip3 install -r requirements.txt
/bin/mkdir <mount_point>
sudo python3 azfilesfuse.py <azure_storage_account> <azure_file_share_name> <sas_token> <mount_point>

System Requirements

The system needs Python 3.5 (or greater) and FUSE libraries to run. I expect to start using 3.6 syntax in the future so I suggest using 3.6 or greater, though it isn't strictly required at this time.

NOTE: This is primarily tested agains Ubuntu 16.04 LTS. Other platforms should work with the below steps, but they are not verified frequently.

Ubuntu 16.04 LTS

sudo apt-get -y install python3 python3-pip fuse

RHEL 6.3

Install Python 3 following https://tecadmin.net/install-python-3-6-on-centos/. Verify the latest python release (at the time of writing this, 3.6.2, not 3.6.1, is current)

Install other packages

yum install fuse-libs
yum install zlib-devel
yum install openssl-devel

Python Dependencies

This package leverages a few python packages Some of them in requirements are only needed if you intend to debug or run the unit tests.

Packages needed to run

  • azure
  • fusepy
  • requests
  • python-dateutil

Packages needed to develop

  • vcrpy
  • ptvsd

Example Usage

sudo -H -u username python3 azfilesfuse.py 'crwilcoxteststorage' 'testshare' 'se=2017-07-16T20%3A42%3A33Z&sp=rwdl&sv=2016-05-31&sr=s&sig=C/N0tRE%AlLYaKeyD' 'testmount'

Additional Notes

I am currently using this on Ubuntu 16.04 LTS but it should work on many other Linux platforms. I will try to update the platforms section to reflect platforms I have heard work.

Running Tests

This project contains some tests. Most of these steps will only have to be run once.

  1. Create new Azure Table Storage Account to use for testing. How-to

  2. Create a file share in the Azure Table Storage Account you created. Configure this share to have a quota. A reasonable quota would be 100MB to 1GB. How-to

  3. Create an account SAS token. Take special care to make this off of the account. Some of the tests use the quota property which isn't accessible from the share itself, but is available account-wide. You can restrict this to only have access to the file service. Creating a SAS Token

  4. Now that the necessary Azure components are created, some environment variables need to be set.

    • azfilesfuse_test_accountname is the name of the storage account (step 1)
    • azfilesfuse_test_accountshare is the name of the file share (step 2)
    • azfilesfuse_test_accountsastoken is the sas token created (step 3).
  5. Run the tests: python -m unittest

azurefilesfuse's People

Contributors

crwilcox avatar kieranbrantnermagee avatar microsoft-github-policy-service[bot] avatar rachelgshaffer avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

azurefilesfuse's Issues

du/ls reports 0 size for all folders.

To repro:
Create a folder within mounted folder.
Write data to a file within that folder.
Attempt to du -h or ls -lah the folder. Size will be 0 always.

Attributes for size are likely not being populated or pulled down.

don't call format inside logger calls.

It is bad practice to call str.format() in a logger call because it's a waste of compute if the logger ever gets set so that debug calls are ignored. โ€ฆ

What you can do is in your logging.Formatter() call above is specify you want to use str.format()-style formatting. Then here you could do:
logger.debug("current max size {} is {}", path, max_size)

strip '?' from sas token if provided

Currently, if you get a sas token from certain tools it comes with a '?' at the start, like a query string. Strip this at startup so that easy malformation doesn't cause failure.

Small fixes to make

  1. the minimum level to log, should be reworded to add 'the available levels are'
  2. add parens to if max_size < self.offset + data_length: and file_length < self.offset + data_length: to try and improve readablility (also just store the second half as a var and not calc twice :))
  3. logger.warning('error writing ' + str(e)) could use an exception-logging call which would log the traceback
  4. make if (not last.processing and (last.offset + len(last.data)) == offset and len(last.data) + len(data) < file.FileService.MAX_RANGE_SIZE): easier to read. by assigning some of these to variables

bring back modified time

The current REST API for Azure Files means that getting modified times for files is very expensive. Other Azure Storage APIs provide ways to get this along with file lists, allowing us to batch getting this data for multiple files all at once.

The code is commented out currently in getattr for doing this

Add support to clear cache easily from tests

Currently, there isn't an easy 'clear dir/file caches' when under test. Would be useful when doing multiple operations in a single area and modifying from outside the driver (for setup teardown mostly).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.