-
Notifications
You must be signed in to change notification settings - Fork 2k
umask for non-root users not as expected #1142
Description
The default umask for non-root users is generally 0002, 775 for folders and 664 for files in any ubuntu server but it seems to be 0022 in this docker image, I am not sure if this is intended or a issue.
scenario:
I am using this image to setup a stack for magento. I have installed composer as well as cron inside this image. It's non-production enviroment so I didn't seperate them into own containers to accommodate for limited hardware resources.
I am using the www-data group as sticky bit to share permissions betwen host and container. The issue arises with files/folders created by cron, composer, php or any other process has umask of 0022, 755 for folders and 644 for files so the files/folders are not writable in host unless sudo, root user or acl is used.
what I have found:
On default ubuntu installation the umask for non-root user is set by the pam_umask.so module. It normally reads from login.defs which has a entry called USERGROUPS_ENAB which converts umask to 0002 for non-root user which has same same uid and gid.
The module is generally called from /etc/pam.d/common-session , this image seems to be missing the module call in this file as well.
what I have tried:
-
manually adding
session optional pam_umask.soat end of/etc/pam.d/common-sessionand/etc/pam.d/common-session-noninteractive, this does seems to load the umask value fromlogin.defs, if I change the value it gets reflected but the non-root user umask due toUSERGROUPS_ENABstill does not work. -
manually adding
session optional pam_umask.soat end of/etc/pam.d/common-sessionand/etc/pam.d/common-session-noninteractiveas well as addingumask=0002in www-data/etc/passwdgecos field, this works as desired. I can even load the module inpam.d/cronand cron tasks umask is 0002 now. -
lastly, for docker exec command which I use to run composer as www-data, pam_umask module seems to make no difference, for this adding
umask=0002in www-data user's home.bashrcdoes the job.
what I want to know:
-
why the
USEGROUPS_ENABis failing to set 0002 umask for non-root user www-data, I even created totally new user the umask is still 0022 withUSERGROUPS_ENAB, adding umask to gecos field works here as well. -
why is
docker exec -it -u www-data $container_name /bin/bashnot using pam_umask set value, only.bashrcworks for this or if I manually dosu www-data -s /bin/bashfrom root exec pam_umask value is set correctly as well.
Thank you for reading it, I have done my best to make it brief. I am hoping to get some insights on this.