Linux: Force different set of directory/file permissions

linuxpermissions

Using CentOS 4.6:

Scenario:
I have a dameon running as root that is constantly creating files and folders in lets say directory /some/directory. Since the files are being created by root, the permissions of those folders and files are determined by the root's umask, which is the default 644 for files and 755 for folders.

I have an application that accesses these files via samba and needs to be able to copy and delete the files. The samba username the application is using is mapped to a user let say 'app_user' which is unable to delete the files because of the permissions. I have added 'app_user' to the group 'app_group'

This is what I would Like to do:

I am hoping there is some way to configure the directory /some/directory so that all files and folders created are owned by the group 'app_group' and have write permissions for that group.

I do not have the option to run the dameon under a different username and I do not want to mess with the umask for root. I would prefer a solution that does not involve running a script to change the permissions. I just want my application to be able to copy and delete these files.

Thanks

Best Answer

I'd go the POSIX ACLs. I'm a big fan of them and I don't find them all that difficult to use. The only think you really need to make sure is that your backup software can restore them.

The steps should be:

1) Edit fstab and add ",acl" to the options for the partition(s) you want to use ACLS on

2) Run the following to remount the partition with the new acl option

mount <relevant_partion> -oremount

3) Run the following to apply the default acl to the directory and it's child dirs:

setfacl -R -dm u:app_user:755 /some/directory

4) Run the following to check the default acl has appeared:

getfacl /some/directory 

Further testing create a file and a dir in /some/directory and make sure they end up with the acl and in the case of the dir, the default acl,. so that file created inside it will also get the acl