Azure Function: System.UnauthorizedAccessException Access to the path '/tmp/' is denied

Viewed 39

I have an Azure Function in C#. I regularly get the following error:

System.UnauthorizedAccessException: Access to the path '/tmp/' is denied.
  ?, in void Interop.ThrowExceptionForIoErrno(ErrorInfo errorInfo, string path, bool isDirectory, Func<ErrorInfo, ErrorInfo> errorRewriter)
  ?, in SafeFileHandle SafeFileHandle.Open(string path, OpenFlags flags, int mode) x 2
  ?, in new OSFileStreamStrategy(string path, FileMode mode, FileAccess access, FileShare share, FileOptions options, long preallocationSize)
  ?, in FileStreamStrategy FileStreamHelpers.ChooseStrategy(FileStream fileStream, string path, FileMode mode, FileAccess access, FileShare share, int bufferSize, FileOptions options, long preallocationSize)
  File "/src/azure-functions-host/src/WebJobs.Script.WebHost/Management/LinuxSpecialization/PackageDownloadHandler.cs", line 177, col 24, in async Task PackageDownloadHandler.HttpClientDownload(string filePath, Uri zipUri, bool isWarmupRequest, string token, string downloadMetricName)
  File "/src/azure-functions-host/src/WebJobs.Script.WebHost/Management/LinuxSpecialization/PackageDownloadHandler.cs", line 119, col 17, in async Task<string> PackageDownloadHandler.Download(RunFromPackageContext pkgContext, Uri zipUri, string token)
  File "/src/azure-functions-host/src/WebJobs.Script.WebHost/Management/LinuxSpecialization/PackageDownloadHandler.cs", line 78, col 13, in async Task<string> PackageDownloadHandler.Download(RunFromPackageContext pkgContext)
  File "/src/azure-functions-host/src/WebJobs.Script.WebHost/Management/InstanceManager.cs", line 128, col 38, in async bool InstanceManager.StartAssignment(HostAssignmentContext context)+(?) => { } [0]

My code looks like

 [FunctionName("Receiver")]
    public async Task<IActionResult> Run(
        [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]
        HttpRequest req,
        ILogger log)
    {
        _logger = log;

        var requestBody = await new StreamReader(req.Body).ReadToEndAsync();
        var newsletterEvent = new NewsletterEvent();

        _logger.LogInformation($"{requestBody} received");

    }

Within the function I have no IO or similar access. Does anyone have an idea how I can get rid of the error?

1 Answers

I tried to log the request body in Azure Functions .NET 6 project with the similar code given in the question and received in the console:

Code:

[FunctionName("HttpTrigger1")]
        public static async Task<IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
            ILogger log)
        {
            log.LogInformation("C# HTTP trigger function processed a request.");

            string name = req.Query["name"];

            string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
            dynamic data = JsonConvert.DeserializeObject(requestBody);
            name = name ?? data?.name;

            string responseMessage = string.IsNullOrEmpty(name)
                ? "This HTTP triggered function executed successfully. Pass a name in the query string or in the request body for a personalized response."
                : $"Hello, {name}. This HTTP triggered function executed successfully.";

            log.LogInformation($"{requestBody} received");
            return new OkObjectResult(responseMessage);
        }

Result:

enter image description here

enter image description here

Related