can't create a storage share through kubernetes file.csi.azure.com

Neil Andrews 0 Reputation points
2024-09-16T13:30:49.5233333+00:00

I am trying to create a fileshare through Kubernetes using the file.csi.azure.com storage class here is an example

--

kind: StorageClass

apiVersion: storage.k8s.io/v1

metadata:

name: azurefile-<NAMESPACE>

provisioner: file.csi.azure.com

allowVolumeExpansion: true

reclaimPolicy: Delete

volumeBindingMode: Immediate

mountOptions:

  • dir_mode=0777
  • file_mode=0777
  • uid=0
  • gid=0
  • mfsymlinks
  • cache=none
  • nobrl

parameters:

resourceGroup: <k8-rg>

storageAccount: <k8-storage>

server: <k8-storage>.file.core.windows.net

sharename: share

--

when it trys to provision a share by adding a claim it comes back with an error

failed to provision volume with StorageClass "azurefile-dev1":

rpc error: code = Internal desc = storage.FileSharesClient#Get: Failure

responding to request: StatusCode=403 -- Original Error: autorest/azure:

Service returned an error. Status=403 Code="AuthorizationFailed" Message="The

client 'xxxxxxxxx' with object id

'xxxxxxxx' does not have authorization to perform

action 'Microsoft.Storage/storageAccounts/fileServices/shares/read' over scope

'/subscriptions/xxxxxxx/resourceGroups/DEV/providers/Microsoft.Storage/storageAccounts/devstorage/fileServices/default/shares/share-dev-0'

or the scope is invalid. If access was recently granted, please refresh your.

--

I have given the Kubernetes user contributor (this used to work ) but I have noticed that there isn't a role Microsoft.Storage/storageAccounts/fileServices/shares/read but there is one called Microsoft.Storage/storageAccounts/fileServices/fileshares/read

so if it worked before it looks like the role name has changed but the driver has not reflected that

Azure Files
Azure Files
An Azure service that offers file shares in the cloud.
1,293 questions
Azure Kubernetes Service (AKS)
Azure Kubernetes Service (AKS)
An Azure service that provides serverless Kubernetes, an integrated continuous integration and continuous delivery experience, and enterprise-grade security and governance.
2,127 questions
Microsoft Entra ID
Microsoft Entra ID
A Microsoft Entra identity service that provides identity management and access control capabilities. Replaces Azure Active Directory.
21,904 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Sina Salam 11,206 Reputation points
    2024-09-16T17:31:50.7666667+00:00

    Hello Neil Andrews,

    Welcome to the Microsoft Q&A and thank you for posting your questions here.

    I understand that you are having challenges to create a storage share through kubernetes file.csi.azure.com.

    The error shows that the client does not have the necessary permissions to perform the action Microsoft.Storage/storageAccounts/fileServices/shares/read, this role should be assigned to the user performing the task. You can check and assign roles using the Azure Portal or Azure CLI as shown below.

       az role assignment create --assignee <client-id> --role "Storage File Data SMB Share Reader" --scope "/subscriptions/<subscription-id>/resourceGroups/<resource-group>/providers/Microsoft.Storage/storageAccounts/<storage-account>"
    

    Make sure there is no is no discrepancies in the role names and it's correctly assigned.

    Also check your Storage Class Parameters and ensure you update it, similarly to the below:

       kind: StorageClass
       apiVersion: storage.k8s.io/v1
       metadata:
         name: azurefile-<NAMESPACE>
       provisioner: file.csi.azure.com
       allowVolumeExpansion: true
       reclaimPolicy: Delete
       volumeBindingMode: Immediate
       mountOptions:
         - dir_mode=0777
         - file_mode=0777
         - uid=0
         - gid=0
         - mfsymlinks
         - cache=none
         - nobrl
       parameters:
         resourceGroup: <k8-rg>
         storageAccount: <k8-storage>
         server: <k8-storage>.file.core.windows.net
         shareName: share
    

    For more reading and best practices check out the following links:

    I hope this is helpful! Do not hesitate to let me know if you have any other questions.

    Please don't forget to close up the thread here by upvoting and accept it as an answer if it is helpful.

    0 comments No comments

  2. Sumarigo-MSFT 46,286 Reputation points Microsoft Employee
    2024-09-18T16:54:26.63+00:00

    @Neil Andrews, Adding more information to the above response!

    It looks like you're encountering an authorization error when trying to provision a file share using the file.csi.azure.com storage class in Kubernetes. The error message indicates that the client does not have the necessary permissions to perform the action ( Can you please cross verify the permission again and let us know the statsu) Microsoft.Storage/storageAccounts/fileServices/shares/read.

    Before you begin( Please cross verify below mentioned prerequisite has been met)

    • You need an Azure storage account.
    • Make sure you have Azure CLI version 2.0.59 or later installed and configured. Run az --version to find the version. If you need to install or upgrade, see Install Azure CLI.
    • When choosing between standard and premium file shares, it's important you understand the provisioning model and requirements of the expected usage pattern you plan to run on Azure Files. For more information, see Choosing an Azure Files performance tier based on usage patterns.

    Here are a few things you can try to resolve this issue:

    Check Role Assignments: Ensure that the Kubernetes user has the correct role assignments. The role Microsoft.Storage/storageAccounts/fileServices/fileshares/read should be assigned instead of Microsoft.Storage/storageAccounts/fileServices/shares/read

    Update Role Assignments: If the role name has changed, you may need to update the role assignments to reflect the new role name. This can be done through the Azure portal or using Azure CLI commands.

    Use Azure Files CSI Driver: The Azure Files Container Storage Interface (CSI) driver is a CSI specification-compliant driver used by Azure Kubernetes Service (AKS) to manage the lifecycle of Azure file shares. Ensure that you are using the latest version of the Azure Files CSI driver

    Persistent Volume Configuration: Make sure that your persistent volume (PV) configuration is correct. A PV can be used by one or many pods and can be dynamically or statically provisioned. If multiple pods need concurrent access to the same storage volume, you can use Azure Files to connect by using the Server Message Block (SMB) or NFS protocol

    If you have recently granted access, it might take some time for the changes to propagate. You can try refreshing your credentials or re-authenticating to ensure that the new permissions are applied.

    Option 2:
    Check Scope: Ensure that the scope specified in the error message is correct. The scope should be set to the specific file share or storage account that you are trying to access. You can use the following command to assign the role at the correct scope:

    $FileShareContributorRole = Get-AzRoleDefinition "Storage File Data SMB Share Reader"
    $scope = "/subscriptions/<subscription-id>/resourceGroups/<resource-group>/providers/Microsoft.Storage/storageAccounts/<storage-account>/fileServices/default/fileshares/<share-name>"
    New-AzRoleAssignment -SignInName <user-principal-name> -RoleDefinitionName $FileShareContributorRole.Name -Scope $scope
    

    Use Built-in Roles: Consider using built-in roles such as Storage File Data SMB Share Reader, Storage File Data SMB Share Contributor, or Storage File Data SMB Share Elevated Contributor which provide the necessary permissions for accessing Azure file shares over SMB.

    If access was recently granted, it might take some time for the permissions to propagate. You can try refreshing the permissions by re-assigning the role or waiting for a few minutes and then trying again.

    References

    Use Container Storage Interface (CSI) driver for Azure Files on Azure Kubernetes Service (AKS) - Azure Kubernetes Service | Microsoft Learn

    Assign share-level permissions for Azure file shares

    Use Azure Files Container Storage Interface (CSI) driver in Azure Kubernetes Service (AKS)

    Create and use a volume with Azure Files in Azure Kubernetes Service (AKS)

    Update or rotate the credentials for an Azure Kubernetes Service (AKS) cluster

    Link: https://github.com/kubernetes-sigs/azurefile-csi-driver/tree/master/deploy/example/nfs#prerequisite

    User's image

    Please let us know if you have any further queries. I’m happy to assist you further.    


    Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you this can be beneficial to other community members.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.