Hello Gianpaolo Tessitore,
Could you kindly try using the role Storage File Data SMB Share Contributor Role ID. This should grant read, write, and delete permissions over SMB and via the SDK.
Create a storage account and file share
$resourceGroup = "arkorg"
$location = "eastus"
$storageAccount = "arkfilestorage9300"
$fileShare = "testshare"
az storage account create `
--name $storageAccount `
--resource-group $resourceGroup `
--location $location `
--sku Standard_LRS `
--kind StorageV2 `
--enable-large-file-share
az storage share-rm create `
--resource-group $resourceGroup `
--storage-account $storageAccount `
--name $fileShare

Create a user-assigned managed identity
$uamiName = "vmfileuami"
az identity create `
--name $uamiName `
--resource-group $resourceGroup `
--location $location
$uamiClientId = az identity show --name $uamiName --resource-group $resourceGroup --query clientId -o tsv
$uamiPrincipalId = az identity show --name $uamiName --resource-group $resourceGroup --query principalId -o tsv
$uamiResourceId = az identity show --name $uamiName --resource-group $resourceGroup --query id -o tsv

Create an Ubuntu VM with the UAMI attached
$vmName = "filevm"
az vm create `
--name $vmName `
--resource-group $resourceGroup `
--image Ubuntu2204 `
--admin-username azureuser `
--generate-ssh-keys `
--assign-identity $uamiResourceId `
--location $location
az vm open-port --resource-group $resourceGroup --name $vmName --port 22

Assign the correct role
$storageId = az storage account show `
--name $storageAccount `
--resource-group $resourceGroup `
--query id -o tsv
az role assignment create `
--assignee-object-id $uamiPrincipalId `
--assignee-principal-type ServicePrincipal `
--role "123456-987651-12345-87654-860001c3d" `
--scope $storageId
From the Ubuntu VM: Use Azure SDK to access the file share
Install .NET 8.0 SDK
sudo apt update
sudo apt install -y dotnet-sdk-8.0
Create and run the test app
mkdir azfilesdk && cd azfilesdk
dotnet new console
Replace Program.cs
with
using System;
using System.IO;
using System.Threading.Tasks;
using Azure.Identity;
using Azure.Storage.Files.Shares;
class Program
{
static async Task Main()
{
string storageAccount = "arkfilestorage9300";
string shareName = "testshare";
string fileName = "test.txt";
var uri = new Uri($"https://{storageAccount}.file.core.windows.net/{shareName}");
var credential = new ManagedIdentityCredential("12345-6788-4231-abcd-efgh");
var shareClient = new ShareClient(uri, credential);
var rootDir = shareClient.GetRootDirectoryClient();
await rootDir.CreateIfNotExistsAsync();
var fileClient = rootDir.GetFileClient(fileName);
byte[] content = System.Text.Encoding.UTF8.GetBytes("Hello from UAMI!");
using var stream = new MemoryStream(content);
await fileClient.CreateAsync(content.Length);
await fileClient.UploadAsync(stream);
Console.WriteLine("File uploaded successfully.");
}
}
Add NuGet packages
dotnet add package Azure.Identity
dotnet add package Azure.Storage.Files.Shares
Now run the app, it should show- File uploaded successfully. Try it out and let me know how it goes. Thanks