Azure Container App mounted volume - permission denied

Dejan Gjorgjevik 15 Reputation points
2023-11-30T09:46:14.07+00:00

My c# .net core 5 application running in azure container environment as azure container app with azure file mounted as a persistent volume suddenly started to throw UnauthorizedAccessException (see below).

It was all working fine until recently. The azure file is setup in read/write access mode and mounts to the container without any issue. The application reads from the volume but when it tries to write only the file is created and then the exception is thrown.


System.UnauthorizedAccessException: Access to the path '/app/Card/IMPORTINTERNATIONAL/EXP_3_20231129_1.XML' is denied.
 ---> System.IO.IOException: Permission denied
   --- End of inner exception stack trace ---
   at System.IO.FileStream.WriteNative(ReadOnlySpan`1 source)
   at System.IO.FileStream.FlushWriteBuffer()
   at System.IO.FileStream.Dispose(Boolean disposing)
   at System.IO.Stream.Close()
   at System.IO.StreamWriter.CloseStreamFromDispose(Boolean disposing)
   at System.IO.StreamWriter.Dispose(Boolean disposing)
   at System.IO.TextWriter.Dispose()
   at PCES.CardService.Web.Controllers.QPCController.<>c__DisplayClass25_0.
Azure Container Apps
Azure Container Apps
An Azure service that provides a general-purpose, serverless container platform.
694 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Dejan Gjorgjevik 15 Reputation points
    2023-12-05T15:19:49.56+00:00

    The issue has been resolved by changing the file create/update with the following code:

    new FileStream(filename, FileMode.OpenOrCreate, FileAccess.Write, FileShare.None)

    The problem was probably coming from the CIFS mount implementation.

    2 people found this answer helpful.

  2. MikeUrnun 9,777 Reputation points Moderator
    2023-12-01T18:21:52.38+00:00

    Hello @Dejan Gjorgjevik - Regarding the below:

    The azure file is setup in read/write access mode and mounts to the container without any issue.

    Could you elaborate on how it was done? Based on our docs, as far as ACA & Azure Files are concerned for the permission side of things, all that's needed seems to be the following command:

    az containerapp env storage set --name my-env --resource-group my-group \
         --storage-name mystorage \
         --azure-file-account-name <STORAGE_ACCOUNT_NAME> \
         --azure-file-account-key <STORAGE_ACCOUNT_KEY> \
         --azure-file-share-name <STORAGE_SHARE_NAME> \
         --access-mode ReadWrite
    

    This error you're hitting is from the application not having the write permission so please verify that you've run the above, especially given how Read operations are working fine. The following CLI command should show details of your current config:

    az containerapp env storage show --name
                                     --resource-group
                                     --storage-name
    

    Also, could you provide more context on whether your app had worked fine as-is and then started throwing this error? or changes were made and the application started throwing this error?

    I look forward to your reply.


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.