FYI:
mydir/ userA:mygroup rwxrwxr-x
mydir/test.py userA:mygroup rwxr-xr-x
userB gid=xxx(mygroup)
In test.py:
uid = pwd.getpwnam('mysql')[2]
os.setuid(uid)
os.system('id')
os.system('touch myfile')
Log in as userA, execute:
> cd mydir/
> sudo ./test.py
uid=xxxx(userB) gid=0(root) groups=xxxx(mygroup),0(root)
touch: cannot touch 'myfile': Permission denied
It seems setuid is done, but still cannot create file in mydir/ with group-writable permission. Could you tell me why?
To be more precise, I would like to simulate mysqld or nginx. A 'user' can be specified in their conf file. The service can be started by sudo service mysql start
, but runs under account 'mysql'.
EDITED: I found the problem. In test.py, setgid should be also be called, otherwise current group is root which has no permission to write into mydir/