%3CLINGO-SUB%20id%3D%22lingo-sub-2121344%22%20slang%3D%22en-US%22%3EMount%20Blob%20storage%20on%20Linux%20VM%20NFS%203.0%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-2121344%22%20slang%3D%22en-US%22%3E%3CP%3EHello%20Folks!%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENot%20so%20long%20ago%20I%20was%20working%20on%20an%20internal%20project%20that%20required%20me%20to%20deploy%20Linux%20VMs%20that%20were%20hosting%20a%20workload%20that%20saved%20a%20copy%20of%20any%20number%20of%20video%20live%20feeds%20to%20blob%20storage%20for%20safeguard%20and%20for%20future%20replays.%26nbsp%3B%26nbsp%3BI%20also%20needed%20it%20to%20be%20mounted%20automatically%20when%20the%20VM%20was%20created.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20know%20that%20are%20several%20ways%20to%20map%20storage%20in%20a%20VM.%20You%20can%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3COL%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Fstorage%2Ffiles%2Fstorage-files-how-to-mount-nfs-shares%3FWT.mc_id%3Dmodinfra-15777-pierrer%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EHow%20to%20mount%20an%20NFS%20file%20share%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Fstorage%2Ffiles%2Fstorage-how-to-use-files-linux%3FWT.mc_id%3Dmodinfra-15777-pierrer%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EUse%20Azure%20Files%20with%20Linux%20over%20SMB%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Fstorage%2Fblobs%2Fstorage-how-to-mount-container-linux%3FWT.mc_id%3Dmodinfra-15777-pierrer%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EHow%20to%20mount%20Blob%20storage%20as%20a%20file%20system%20with%20blobfuse%3C%2FA%3E%3C%2FLI%3E%0A%3CLI%3E%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Fstorage%2Fblobs%2Fnetwork-file-system-protocol-support-how-to%3Ftabs%3Dlinux%26amp%3BWT.mc_id%3Dmodinfra-15777-pierrer%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3EMount%20Blob%20storage%20by%20using%20the%20Network%20File%20System%20(NFS)%203.0%20protocol%20(preview)%3C%2FA%3E%3C%2FLI%3E%0A%3C%2FOL%3E%0A%3CP%3EI%20decided%20to%20give%20the%20NFS%20path%20a%20try.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWhy%20NFS%20you%20may%20ask%3F%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI'm%20not%20sure...%20Could%20be%20because%20NFSv3%20provides%20compatibility%20for%20existing%20applications%2C%20could%20be%20because%20of%20the%20scale%20it%20can%20support%20or%20maybe%20just%20because%20it's%20cost%20effective%20and%20easy%20to%20setup.%3C%2FP%3E%0A%3CP%3EIn%20any%20case%2C%20I%20followed%20the%20documentation%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Fstorage%2Fblobs%2Fnetwork-file-system-protocol-support-how-to%3Ftabs%3Dlinux%26amp%3BWT.mc_id%3Dmodinfra-15777-pierrer%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noreferrer%22%3Ehere%3C%2FA%3E%26nbsp%3B%20to%20create%20the%20virtual%20network%2C%20service%20endpoint%20to%20ensure%20that%20the%20storage%20account%20can%20only%20be%20accessed%20from%20the%20appropriate%20vnet%20and%20subnet%2C%20and%20the%20storage%20account.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20automate%20this%20at%20the%20time%20of%20deployment%20I%20added%20the%20following%20few%20lines%20to%20the%20Custom%20Script%20Extention%20script%20i%20use%20to%20deploy%20the%20workload%20on%20a%20new%20VM%20at%20deployment%20time.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3Eapt%20update%0Aapt%20install%20nfs-common%20-y%0Amkdir%20-p%20%2Fmnt%2Flivefeed%0Amount%20-o%20sec%3Dsys%2Cvers%3D3%2Cnolock%2Cproto%3Dtcp%20%3CSTORAGE-ACCOUNT-NAME%3E.blob.core.windows.net%3A%2F%3CSTORAGE-ACCOUNT-NAME%3E%2F%3CCONTAINER-NAME%3E%20%2Fmnt%2Flivefeed%3C%2FCONTAINER-NAME%3E%3C%2FSTORAGE-ACCOUNT-NAME%3E%3C%2FSTORAGE-ACCOUNT-NAME%3E%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThis%20worked%20great!%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EExcept%20that%20the%20workload%20on%20the%20VM%20could%20not%20write%20to%20the%20blob%20storage.%20I%20realized%20that%20when%20the%20custom%20Script%20extension%20creates%20the%20folder%20livefeed%20in%20%2Fmnt%20it's%20done%20by%20the%20Azure%20Agent%20user%20context%20(Root)%20and%20therefore%20the%20permissions%20on%20that%20folder%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-center%22%20image-alt%3D%22NFS-permissions.png%22%20style%3D%22width%3A%20714px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F254122i0E6573DF8EF9E66E%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22NFS-permissions.png%22%20alt%3D%22NFS-permissions.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EOnly%20provide%20read%20write%20to%20Root.%20For%20my%20test%20I%20added%20the%20following%26nbsp%3Bline%20to%20the%20end%20of%20my%20script%2C%20and%20it%20worked%20like%20a%20charme.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-bash%22%3E%3CCODE%3Echmod%20777%20%2Fmnt%2Flivefeed%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CU%3E%3CSTRONG%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-left%22%20image-alt%3D%22important.jpg%22%20style%3D%22width%3A%20320px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F254127iA686C403D1ACA9A8%2Fimage-size%2Flarge%3Fv%3D1.0%26amp%3Bpx%3D999%22%20role%3D%22button%22%20title%3D%22important.jpg%22%20alt%3D%22important.jpg%22%20%2F%3E%3C%2FSPAN%3E%3C%2FSTRONG%3E%3C%2FU%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CU%3E%3CSTRONG%3EI%20do%20Not%20promote%20giving%20all%20rights%20to%20all%20users%20in%20a%20production%20environment.%3C%2FSTRONG%3E%3C%2FU%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EMy%20next%20step%20is%20to%20create%20a%20group%20that%20include%20the%20user%20context%20which%20the%20workload%20in%20running%20under%20and%20change%20the%20permissions%20so%20only%20the%20account%20needed%20have%20write%20access.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EI%20really%20believe%20in%20the%20Least-Privilege%20Administrative%20Models%20when%20it%20comes%20to%20any%20environments%20(On-Prem%2C%20Hybrid%20and%20cloud%20native).%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIn%20any%20case%2C%20I%20hope%20this%20may%20give%20you%20some%20ideas%20on%20how%20you%20can%20leverage%20Azure%20services%20to%20address%20problems%20in%20your%20environment.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ECheers!%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EPierre%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-2121344%22%20slang%3D%22en-US%22%3E%3CP%3EThis%20article%20will%20give%20you%20a%20quick%20overview%20on%20how%20you%20can%20map%20an%20Azure%20Storage%20account%20in%20a%20Linux%20VM%20at%20deployment%20time.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-2121344%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAzure%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EAzure%20Storage%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ELinux%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPierre%20Roman%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EVirtual%20Machine%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

Hello Folks!

 

Not so long ago I was working on an internal project that required me to deploy Linux VMs that were hosting a workload that saved a copy of any number of video live feeds to blob storage for safeguard and for future replays.  I also needed it to be mounted automatically when the VM was created.

 

I know that are several ways to map storage in a VM. You can:

 

  1. How to mount an NFS file share
  2. Use Azure Files with Linux over SMB
  3. How to mount Blob storage as a file system with blobfuse
  4. Mount Blob storage by using the Network File System (NFS) 3.0 protocol (preview)

I decided to give the NFS path a try.

 

Why NFS you may ask?

 

I'm not sure... Could be because NFSv3 provides compatibility for existing applications, could be because of the scale it can support or maybe just because it's cost effective and easy to setup.

In any case, I followed the documentation here  to create the virtual network, service endpoint to ensure that the storage account can only be accessed from the appropriate vnet and subnet, and the storage account.

 

To automate this at the time of deployment I added the following few lines to the Custom Script Extention script i use to deploy the workload on a new VM at deployment time.

 

 

 

 

 

apt update
apt install nfs-common -y
mkdir -p /mnt/livefeed
mount -o sec=sys,vers=3,nolock,proto=tcp <storage-account-name>.blob.core.windows.net:/<storage-account-name>/<container-name> /mnt/livefeed

 

 

 

 

 

This worked great!

 

Except that the workload on the VM could not write to the blob storage. I realized that when the custom Script extension creates the folder livefeed in /mnt it's done by the Azure Agent user context (Root) and therefore the permissions on that folder

 

NFS-permissions.png

 

Only provide read write to Root. For my test I added the following line to the end of my script, and it worked like a charme.

 

 

 

 

 

chmod 777 /mnt/livefeed

 

 

 

 

important.jpg

 

I do Not promote giving all rights to all users in a production environment.

 

 

My next step is to create a group that include the user context which the workload in running under and change the permissions so only the account needed have write access.

 

I really believe in the Least-Privilege Administrative Models when it comes to any environments (On-Prem, Hybrid and cloud native).

 

In any case, I hope this may give you some ideas on how you can leverage Azure services to address problems in your environment.

 

Cheers!

 

Pierre