-
Notifications
You must be signed in to change notification settings - Fork 23.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Copy module ignores setgid bit on parent directories #46742
Comments
Files identified in the description: If these files are inaccurate, please update the |
So after deeper analysis, the bug is in My understanding is it uses So IMO 2 possible fixes:
# if setgid bit is set on parent directory then chgrp the file to the right group
b_dest_parent_stat = os.stat(os.path.dirname(b_dest))
if b_dest_parent_stat.st_mode & stat.S_ISGID:
os.chown(b_dest, os.geteuid(), b_dest_parent_stat.st_gid) |
Files identified in the description: If these files are incorrect, please update the |
I also have this problem. Here's an excerpt from the playbook I tried to use:
I intentionally set the UID and GID bits because I intend on later copying a file into this directory that should be served by nginx.
Then I tried to create a test file to serve:
I don't use become because my ansible user (the remote_user, "packer") is already the owner of the directory and has mode-7 permissions. I also don't explicitly set a mode because I want to dynamically let the parent permissions propagate. But this is what I get instead:
which means nginx can't serve the file! I understand forcing 600 permissions by default - ok. But there needs to be a special mode keyword, just like we already have "preserve" that means "respect the UID/GID bits and generally let the default permissions be". |
@jantari Note that the setuid bit is useless on directories. Also note that the setgid bit won't give you control over permissions of the created file but only over the group of the created file. I don't get why this issue is not getting any attention. Looks like no one need unix anymore theses days. |
Hello. I think this bug also hit |
Also the copy module does not recurse the setype ( not sure if setype can be recursed though but if chcon is taken as equivalent then it does have -R option ) when non standard directories are created through ansible and accessed via links in allowed directory root.
even with this set on a non root directory,
and group too will not recurse but does not matter. |
Hi, Could we have any update / plan on this please? 🙏 The OP @rdupz suggested 2 approach to fix in 2018. |
EDIT: The unprivileged user issue mentioned below must be coming from elsewhere or perhaps was already fixed because the code affected by this patch has been wrapped in a try/except block to ignore errors from the chown for quite some time. The second possible solution @rdupz suggested for this can't be used as written because it doesn't account for the possibility that the user is not root.
EDIT: The chgrp was necessary (and glad to see it was included in the patch) because this was implemented using move and SETGID does not apply to moves, so it's necessary to change the permissions afterward to get copy semantics. In any case, it's important that this be handled properly for both root and non-root use cases and in cases where we're not root ansible should not be trying to call chgrp (as it does today on setgid directories, which is how I ended up here). I should be able to run ansible.builtin.copy as non-root and ideally leave group unspecified and create a file in a setgid directory without chgrp being invoked because the resulting group doesn't match my own. Worst case scenario I should at least be able to specify group as the value I expect to result from creating the file in said setgid directory and avoid the chgrp that way. Today neither of these work. |
Just FYI because of this issue and similar problems with calling chgrp/chown unconditionally even when running as non-root users, this is canonical ansible code:
|
FWIW, I've rerun the test setup by OP, and as expected the issue is still there:
@ansibot Please change label.
|
This should be working correctly now on devel, and I've opened backports for 2.16 and 2.17 (#83765, #83764). Thanks for all the reports and the good assessment #46742 (comment). |
SUMMARY
The copy module ignores setgid bit.
While touching or scping a file into a directory with a setgid bit, the group of the touched or scped file is the same group as the directory one: this is the purpose of the setgid bit.
But when the file is created by ansible, the group of the created file is the default group of the user who copy the file.
I tried various combination. I also tried to play with the code of some of actions plugins including
chown
calls, but without any result...Not tested with latest ansible 😟.
Affects 2.6.1.
ISSUE TYPE
COMPONENT NAME
ANSIBLE VERSION
CONFIGURATION
OS / ENVIRONMENT
CentOS 7 to CentOS 7
STEPS TO REPRODUCE
EXPECTED RESULTS
The file
file_tst
should be owned byfoo_user:bar_group
instead offoo_user:foo_user
thanks to the setgid bit on/tmp/issue_tst/
.ACTUAL RESULTS
The file
file_tst
is actually owned byfoo_user:foo_user
, ignoring the setgid bit on/tmp/issue_tst/
.The text was updated successfully, but these errors were encountered: