Recursive directory management doesn't preserve permissions
OS: Centos 6.3
Example usage:
/opt/elasticsearch:
file.recurse:
- source: salt://dist/elasticsearch/0.19.10
- user: elasticsearch
- group: elasticsearch
- include_empty: True
- require:
- user: elasticsearch
salt://dist/elasticsearch/0.19.10 just contains an unpacked elasticsearch distribution on the master.
On the minion, everything is set to 644 (files) / 755 (dirs) meaning that scripts are no longer executable, and have to be fixed afterwards.
We do not copy the metadata from the master down to the minion, there is another bug report that talks more about this but I am not finding it right now. Any way, I do think that we should be able to set a flag that preservers permissions from the master if set
Thomas,
When will the "preserv permissions from the master" flag be implemented? I ran into a similar issue and would like such a flag available.
This is somewhat more involved and is not currently slated for a release. Basically the file server needs to be able to send some extra keys in the data message sent to the minion which contain the file metadata on the master. Then routines to handle the metedata can be added to the file.managed backend, which is used by file.recurse.
How hard would this be to implement @thatch45?
Fairly difficult. The issue is that we transfer the file down as data, not as a file with all its metadata. So we would have to add logic to the fileserver and fileclient to allow for this metadata to be transferred, and do it in such a way that it wouldn't break backwards compatibility. It's something we'd like to get in, but it's not on our radar at the moment.
I would like to get on it. I'm trying to contribute to the project and this seems like a good and usefull thing to implement. However I'm not very familiarized with the project's code base (I a familiarized with the tool), I've only done a pull request that consisted in some postprocessing of a flag in file.managed. Do you think that this is something someone unfamiliarized with the project structure could be able to tackle efficiently.
Regards, Germán Jaber On Jun 4, 2014 1:29 PM, "Colton Myers" [email protected] wrote:
Fairly difficult. The issue is that we transfer the file down as data, not as a file with all its metadata. So we would have to add logic to the fileserver and fileclient to allow for this metadata to be transferred, and do it in such a way that it wouldn't break backwards compatibility. It's something we'd like to get in, but it's not on our radar at the moment.
Reply to this email directly or view it on GitHub https://github.com/saltstack/salt/issues/2707#issuecomment-45126638.
It will definitely be on the more difficult side, and definitely has some things that would be easy to mess up (backwards compatibility being the big one) -- that said, if you stick with it you could probably get there. You would have to figure out how to add this functionality to the fileserver backends (in salt/fileserver/), and then also extend the fileclient (salt/fileclient.py) to be able to use the new information. But the new fileserver would need to be able to talk to old fileclients and vise versa.
So to answer your question, I would not recommend this as a starting point, it's going to be a difficult one. But it's far from impossible.
Do we have a fix or a workaround for this when using file.recurse ?
@wongster80 Not really. You could use file.directory to change the permissions of subdirectories, and that state supports recursing. So you could lay down all the files with the same permissions using file.recurse and then fix the permissions as needed using file.managed or file.directory.
I just wanted to bump this. After some debugging, I found this. Perhaps a note could be added to the documentation saying "Warning: This command will not preserve file permissions." Personally, I think file.recurse is useless without preserving permissions. Maybe the right answer is to just remove it until it's implemented correctly, so that people know to either manage files independently, or just copy over a tarball and extract it.
We will not be removing file.recurse, it's heavily used in many salt-managed infrastructures. However, we should add a warning.
+1 Do you have an ETA for this feature ?
Unfortunately there is no ETA at this time.
Shame.
@basepi After we review the boron release timelines I would like to consider this one for boron, but we have others that I think are a little higher on the list
As I will be implementing this, I'm going to leave these details so I don't forget them:
- Need to add a
modekey to the payload when returning a payload containing a file from the fileclient. For the VCS backends, this is dependent upon support within the python bindings to get the mode. cp.cache_fileneeds to be updated to check for the mode and write the file to the minion cache with that mode. This needs to be done carefully, as the mode can be updated in a git repo while the hash of the file hasn't changed, so we can't skip checking the mode if the local hash matches.- File states need to be updated to stat the file in the minion cache and ensure that mode is used when deploying the file on the minion.
@thatch45 please let me know if I'm on the right track, or if there is a more elegant solution.
Might want to make it a general "metadata" in case we want to add more later. Make it a dict and put the mode in there. Otherwise sounds good to me.
OK. We won't be able to just dump the stat_result object into the payload because it won't serialize. Again, this information is more for my benefit when I look at this later.
I search a rsync -a like solution to copy some code to the minion. This issue here is popular and has many duplicates. I see above that something was merged in Dec 2015, but the state of the issue is still "open".
... wait ... I found this: https://docs.saltstack.com/en/develop/ref/states/all/salt.states.rsync.html
The question is now: Does file.recurse need improvement at all, since the rsync state exists?
@guettli The rsync from state.rsync refers only to rsync operations on the minion itself, not to the deployment of files from master to minion.
While this can be useful for making backups of directories on the minion to other directories on the minion or wherever the minion has rsync access to, it doesn't solve the problem of lost permissions while copying files from master to minion. That is, unless you give the minion ssh access to your master, or install salt-minion on the master and allow ssh access to the actual minion, or some other hack like that. Even then, those hacks would still not allow to deploy files from a filesystem that rsync has no access to, like gitfs, hgfs and such.