MUG4N
MUG4N

Reputation: 19717

Windows Azure Exception: "Access to the path XYZ.exe is denied."

I use local storage on Windows Azure to store temporary files. In there I call an .exe file to make a conversion of several other files in same local storage folder. Problem is I always get the exception "Access to the path XYZ.exe is denied.".

I should mention the following: - I am using a worker role - set in the service definition file

and tried to add permission to the folder I am accessing:

    public static void AddPermission(string absoluteFolderPath)
    {
        DirectoryInfo myDirectoryInfo = new DirectoryInfo(absoluteFolderPath);

        DirectorySecurity myDirectorySecurity = myDirectoryInfo.GetAccessControl();
        myDirectorySecurity.AddAccessRule(new FileSystemAccessRule(
        "NETWORK SERVICE",
        FileSystemRights.FullControl,
        AccessControlType.Allow));
        myDirectoryInfo.SetAccessControl(myDirectorySecurity);
    }

UPDATE: I tried with this code now:

     public static void FixPermissions()
    {
        var tempDirectory = RoleEnvironment.GetLocalResource("localStorage").RootPath;
        Helper.addPermission(tempDirectory);

        var dir = new DirectoryInfo(tempDirectory);
        foreach (var d in dir.GetDirectories())
            Helper.addPermission(d.FullName);
    }

    private  static void addPermission(string path)
    {
        FileSystemAccessRule everyoneFileSystemAccessRule = new FileSystemAccessRule("Everyone", 
                                                                                     FileSystemRights.FullControl,
                                                                                     InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit,
                                                                                     PropagationFlags.None, AccessControlType.Allow);
        DirectoryInfo directoryInfo = new DirectoryInfo(path);
        DirectorySecurity directorySecurity = directoryInfo.GetAccessControl();
        directorySecurity.AddAccessRule(everyoneFileSystemAccessRule);
        directoryInfo.SetAccessControl(directorySecurity);
    }

I get a really strange behaviour of the page. I still get the errors but sometimes some files gets converted by the ffmpeg.exe file.

Can someone help me out here??

Thanks a lot.

SOLUTION:

So seems the problem was that I ran the .exe file within local storage and therefore had the given security issues. Putting the .exe into the application and referring directly solved my issue.

Thx for your help.

Upvotes: 2

Views: 1837

Answers (1)

Jeremy McGee
Jeremy McGee

Reputation: 25210

By default your worker role will most likely not be running with sufficient privilege to allow changes to the access control lists on Azure folders.

There's two possible options:

<WebRole name="WebApplication2">
  <Runtime executionContext="elevated" />
  <Sites>

However, I'd really not recommend that as it's a terrible security hole for something that's running in the public cloud.

Upvotes: 3

Related Questions