Azure / nxtools

Azure Automanage Machine Configuration Linux DSC resources
Other
13 stars 11 forks source link

nxFile - Does not seem possible to set file mode recursively, setting 'X' on directory but not on files within #47

Closed eehret closed 11 months ago

eehret commented 11 months ago

Details of the scenario you tried and the problem that is occurring

Natively linux supports the ability to chmod -R at the directory level, and tell it to set X on the directory but not files within. This is discussed here: https://superuser.com/questions/757806/give-execution-permission-to-directories-but-not-to-files

I've fiddled with nxFiles a bit trying to get it to do this, but no success. Either it isn't possible or it isn't clear enough how to accomplish this, as there are no such examples in the documentation or comments.

To make matters worse, if I specify Type = File and try to use a wildcard in DestinationPath, although at a low level this does fetch the properties of all the files in the directory, one of the higher nx classes seems unable to interpret this and it complains about the type of the file system resource being "File File" instead of "File" , probably because it received an array from one of the lower level classes and it isn't written to handle that scenario.

Verbose logs showing the problem

n/a

Suggested solution to the issue

It would be great if you could specify an nxFile at the directory level (type = Directory), and provide a desired file mode using symbolic notation that supports the uppercase 'X', which is explained in the man pages for chmod.

Without this, I think the 'Recurse' functionality of nxFile is of limited utility.

If that isn't feasible, then maybe fix the code so that it can handle an array of file properties when you try to use a wildcard in the DestinationPath property with Type = File

The DSC configuration that is used to reproduce the issue (as detailed as possible)

I've tried this:

    nxFile sshd_config_d_permissions_set
    {
      Ensure = "Present"
      DestinationPath = "/etc/ssh/sshd_config.d/"
      Type = "Directory"
      Mode = "600"
      Force = $true
      Recurse = $true
      Group = "root"
      Owner = "root"
    }

And this:

    {
      Ensure = "Present"
      DestinationPath = "/etc/ssh/sshd_config.d/*"
      Type = "File"
      Mode = "600"
      Force = $true
      Recurse = $true
      Group = "root"
      Owner = "root"
    }

And variations using symbolic notation also instead of octal notation. So far I've either gotten errors, or the incorrect result.

The operating system the target node is running

Ubuntu 20.04 LTS

Version and build of PowerShell the target node is running

7.3.7

Version of the DSC module that was used

1.2.0

eehret commented 11 months ago

For now I'll use nxScript to achieve what I need. Hoping there will be a way to use nxFile for this scenario in the future though :)

jodi-boone commented 11 months ago

Thanks @eehret for the suggestion - we will look into how we can deliver this and get back to you. Thanks for your active engagement in the repo!

eehret commented 11 months ago

@jodi-boone Happy to help. Thanks for taking a look :)