Ubuntu – Change www directory mode only from web application

Apache2cgipermissionsserver

I am using Apache web server in ubuntu, Linux. I am writing Web Application using CGI. There are the paths of my works.

WWW Dir -> /var/myproj/www/
Data Dir -> /var/myproj/data/
App Dir -> /usr/lib/cgi-bin/

Proj Dir -> /home/$USER/myproj/www/

Sometimes I will copy a file from Data Dir to WWW Dir through my CGI application. I will read, write and update data located in Data Dir from my CGI Application.
My query is, I should read and write files located in WWW Dir and Data Dir only by CGI Application. Even an any of local user shouldn't read and write those file located in Data and WWW directories.

But I use grunt application to update my WWW Directory from my Proj Directory. Only My CGI application and Grunt Application can update the WWW and Data Directories.

To do this, What Ownership and access mode should I give?

Best Answer

Use a dedicated user and group.

You can make "data" be owned by the "CGI app user" and set it to "700" for directories and "600" for files. Nobody other than the admin and that user will be able to even enter the directory. Nor can they read the files.

For grunt: you could add that user to the same group as your "CGI app user".

For writing into the "www" directory add those 2 users to the group that owns "www".

Related Question