saltstack / salt

Software to automate the management and configuration of any infrastructure or application at scale. Install Salt from the Salt package repositories here:
https://docs.saltproject.io/salt/install-guide/en/latest/
Apache License 2.0
14.17k stars 5.48k forks source link

Unexpected Error in archive.extracted - Archive does not have a single top-level directory. #44632

Closed cruscio closed 6 years ago

cruscio commented 6 years ago

Description of Issue/Question

Error extracting an archive. It contains a single top level directory, but state.apply raises an error indicating it doesn't

state.apply return:

----------
          ID: winlogbeat archive
    Function: archive.extracted
        Name: c:/salt/SupportOne/
      Result: False
     Comment: Archive does not have a single top-level directory. To allow this archive to be extracted, set 'enforce_toplevel' to Fals
e. To avoid a 'zip-bomb' it may also be advisable to set a top-level directory by adding it to the 'name' value (for example, setting '
name' to c:/myproject\some_dir instead of c:/myproject).
     Started: 13:31:39.214000
    Duration: 281.0 ms
     Changes:

Note: also tried both -name: c:/myproject/winlogbeat and -name: c:/myproject/winlogbeat/ with similar results

Setup

init.sls file

archive.extracted:                               
  - name: c:/myproject/                    
  - source: salt://mystate/files/winlogbeat.zip
  - force: True                                  
  - overwrite: True                              

zip file

$ unzip -l /srv/salt/mystate/files/winlogbeat.zip                               
Archive:  /srv/salt/mystate/files/winlogbeat.zip                                                            
  Length      Date    Time    Name                                                                            
---------  ---------- -----   ----                                                                            
        0  2017-11-21 13:24   winlogbeat/                                                                     
    29305  2017-11-21 13:24   winlogbeat/winlogbeat.reference.yml                                             
   178664  2017-11-21 13:24   winlogbeat/NOTICE.txt                                                           
     4838  2017-11-21 13:24   winlogbeat/winlogbeat.yml                                                       
      188  2017-11-21 13:24   winlogbeat/uninstall-service-winlogbeat.ps1                                     
       41  2017-11-21 13:24   winlogbeat/.build_hash.txt                                                      
    11271  2017-11-21 13:24   winlogbeat/fields.yml                                                           
      583  2017-11-21 13:24   winlogbeat/LICENSE.txt                                                          
      569  2017-11-21 13:24   winlogbeat/install-service-winlogbeat.ps1                                       
 30427136  2017-11-21 13:24   winlogbeat/winlogbeat.exe                                                       
      817  2017-11-21 13:24   winlogbeat/README.md                                                            
        0  2017-11-21 13:24   winlogbeat/kibana/                                                              
        0  2017-11-21 13:24   winlogbeat/kibana/default/                                                      
        0  2017-11-21 13:24   winlogbeat/kibana/default/index-pattern/                                        
    11189  2017-11-21 13:24   winlogbeat/kibana/default/index-pattern/winlogbeat.json                         
        0  2017-11-21 13:24   winlogbeat/kibana/default/dashboard/
     6331  2017-11-21 13:24   winlogbeat/kibana/default/dashboard/Winlogbeat-overview.json                    
        0  2017-11-21 13:24   winlogbeat/kibana/5.x/                                                          
        0  2017-11-21 13:24   winlogbeat/kibana/5.x/index-pattern/                                            
    10995  2017-11-21 13:24   winlogbeat/kibana/5.x/index-pattern/winlogbeat.json                             
        0  2017-11-21 13:24   winlogbeat/kibana/5.x/search/                                                   
      792  2017-11-21 13:24   winlogbeat/kibana/5.x/search/Winlogbeat-Search.json                             
        0  2017-11-21 13:24   winlogbeat/kibana/5.x/visualization/                                            
      767  2017-11-21 13:24   winlogbeat/kibana/5.x/visualization/Errors-count-over-time.json
      440  2017-11-21 13:24   winlogbeat/kibana/5.x/visualization/Number-of-Events.json
      884  2017-11-21 13:24   winlogbeat/kibana/5.x/visualization/Top-Event-IDs.json                          
      856  2017-11-21 13:24   winlogbeat/kibana/5.x/visualization/Event-Levels.json                           
      960  2017-11-21 13:24   winlogbeat/kibana/5.x/visualization/Evolution-of-the-CPU-times-per-process.json 
      718  2017-11-21 13:24   winlogbeat/kibana/5.x/visualization/Sources.json                                
     1394  2017-11-21 13:24   winlogbeat/kibana/5.x/visualization/Number-of-Events-Over-Time-By-Event-Log.json
        0  2017-11-21 13:24   winlogbeat/kibana/5.x/dashboard/                                                
      962  2017-11-21 13:24   winlogbeat/kibana/5.x/dashboard/Winlogbeat-Dashboard.json                       
---------                     -------                                                                         
 30689700                     32 files                                                                        

contents available here: https://www.elastic.co/downloads/beats/winlogbeat I just repackaged them in a folder without the version number, using command line zip on Ubuntu 16.04

zip --version                             
Copyright (c) 1990-2008 Info-ZIP - Type 'zip "-L"' for software license.
This is Zip 3.0 (July 5th 2008), by Info-ZIP.                           

Steps to Reproduce Issue

salt '*' state.apply mystate

Versions Report

Master

Salt Version:
           Salt: 2017.7.2

Dependency Versions:
           cffi: Not Installed
       cherrypy: Not Installed
       dateutil: 2.4.2
      docker-py: Not Installed
          gitdb: 0.6.4
      gitpython: 1.0.1
          ioflo: Not Installed
         Jinja2: 2.8
        libgit2: Not Installed
        libnacl: Not Installed
       M2Crypto: Not Installed
           Mako: 1.0.3
   msgpack-pure: Not Installed
 msgpack-python: 0.4.6
   mysql-python: Not Installed
      pycparser: Not Installed
       pycrypto: 2.6.1
   pycryptodome: Not Installed
         pygit2: Not Installed
         Python: 2.7.12 (default, Nov 19 2016, 06:48:10)
   python-gnupg: Not Installed
         PyYAML: 3.11
          PyZMQ: 15.2.0
           RAET: Not Installed
          smmap: 0.9.0
        timelib: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.1.4

System Versions:
           dist: Ubuntu 16.04 xenial
         locale: UTF-8
        machine: x86_64
        release: 4.4.0-98-generic
         system: Linux
        version: Ubuntu 16.04 xenial

Minion

UH4FC21.uh1adcv1.eclptsc.eclipsnet.com:
    Salt Version:
               Salt: 2017.7.2

    Dependency Versions:
               cffi: 1.10.0
           cherrypy: 10.2.1
           dateutil: 2.6.0
          docker-py: Not Installed
              gitdb: 2.0.3
          gitpython: 2.1.3
              ioflo: Not Installed
             Jinja2: 2.9.6
            libgit2: Not Installed
            libnacl: Not Installed
           M2Crypto: Not Installed
               Mako: 1.0.6
       msgpack-pure: Not Installed
     msgpack-python: 0.4.8
       mysql-python: Not Installed
          pycparser: 2.17
           pycrypto: 2.6.1
       pycryptodome: Not Installed
             pygit2: Not Installed
             Python: 2.7.13 (v2.7.13:a06454b1afa1, Dec 17 2016, 20:53:40) [MSC v.1500 64 bit (AMD64)]
       python-gnupg: 0.4.0
             PyYAML: 3.11
              PyZMQ: 16.0.2
               RAET: Not Installed
              smmap: 2.0.3
            timelib: 0.2.4
            Tornado: 4.5.1
                ZMQ: 4.1.6

    System Versions:
               dist:
             locale: cp1252
            machine: AMD64
            release: 2012ServerR2
             system: Windows
            version: 2012ServerR2 6.3.9600  Multiprocessor Free
cruscio commented 6 years ago
cruscio commented 6 years ago

... ... ... ... ... is the file cached somewhere?

An earlier copy of the ZIP didn't have a top level folder - and also didn't have a couple files that are suspiciously absent from the minion after extracting with enforce_toplevel: False ... the missing files are in a copy of the same zip transferred (from the same -source) to the minion by a file.manage state

winlogbeat archive:
  archive.extracted:                               
    - name: c:/myproject/winlogbeat/                    
    - source: salt://mystate/files/winlogbeat.zip
    - force: True                                  
    - overwrite: True                              
    - enforce_toplevel: False

blagraphonious:                                    
  file.managed:                                    
    - name: c:/mystate/winlogbeat.zip      
    - source: salt://mystate/files/winlogbeat.zip

Same source, but archive.extracted is using an older cached copy of the archive, not the more recent one that file.managed is pulling down

cruscio commented 6 years ago

Whatever the issue was, it's okay now, but I'm going to leave this open for review because it seems like something isn't quite right with how the state was being applied. Can't think of any way I could have ended up with an older timestamp on the newer file.

Ch3LL commented 6 years ago

I know @terminalmage has done some work here so maybe he has some insight for you here

terminalmage commented 6 years ago

Please post the output from salt <minion-id> archive.list salt://mystate/files/winlogbeat.zip, replacing <minion-id> with the appropriate minion ID.

cruscio commented 6 years ago

Unfortunately at this point, whatever condition caused the issue has been cleared up in my environment. I've updated the zip package a couple times now, state.apply runs without error, and archive.list shows the newer file manifest with top level directory and all files.

terminalmage commented 6 years ago

OK. Unfortunately, without that information I can't really troubleshoot this. The way the code works is that it uses archive.list to get the contents of the archive (see here). It then uses the result of that list to try to detect whether or not there is a single top-level directory in the archive (see here). The only thing that causes that error you saw is if there is more than one top-level directory, or if there are any files in the top level of the archive.

Given this information, one of two things happened; there was an extra directory or some files in the top level, or Salt did not properly detect the contents of the file. Without the output from archive.list (with verbose=True, I forgot to mention that earlier), I can't possibly know which is the case.

cruscio commented 6 years ago

After some confusing troubleshooting, it seemed archive.list and archive.extracted behaved as expected, just not on the expected file.

The minion was using two different versions of the same archive file when applying the state.

I'm not sure there's anything more to do here, particularly since I can't reproduce it, I just wanted to leave the issue open until someone more knowledgeable could make that determination, in case it was worth pursuing how the minion was refreshing its cache.

terminalmage commented 6 years ago

@cruscio in that case, I'm going to close this since the way archive.extracted handles caching the source archives was overhauled in https://github.com/saltstack/salt/pull/43681, and the result of that work was released in 2017.7.3. If the problem was file caching, the offending code almost certainly no longer exists. If this issue crops up again, please let me know and I can revisit it.

kiemlicz commented 9 months ago

Still happens

state sls:

extract_idea:
  archive.extracted:
    - name: /opt
    - source: https://download.jetbrains.com/idea/ideaIU-2023.3.2.tar.gz
    - user: johnsnow
    - group: johnsnow
    - enforce_ownership_on: /opt/idea-IU-233.13135.103
    - skip_verify: True
root@ambassador:/# salt thewall archive.list https://download.jetbrains.com/idea/ideaIU-2023.3.2.tar.gz                                     
thewall:                                                                                                                                    
    - idea-IU-233.13135.103/                                                                                                                                                                                                                                                                                                
    - idea-IU-233.13135.103/                                                                                                                                  
    - idea-IU-233.13135.103/                                                                                                                                  
    - idea-IU-233.13135.103/                                                                                                                                  
    - idea-IU-233.13135.103/Install-Linux-tar.txt                                                                                                             
    - idea-IU-233.13135.103/bin/                                                                                                                              
    - idea-IU-233.13135.103/bin/                                                                                                                              
    - idea-IU-233.13135.103/bin/appletviewer.policy                                                                                                           
    - idea-IU-233.13135.103/bin/brokenPlugins.db                                                                                                              
    - idea-IU-233.13135.103/bin/format.sh                                                                                                                     
    - idea-IU-233.13135.103/bin/fsnotifier                                                                                                                    
    - idea-IU-233.13135.103/bin/idea.png                                                                                                                      
    - idea-IU-233.13135.103/bin/idea.properties                                                                                                               
    - idea-IU-233.13135.103/bin/idea.sh                                                                                                                       
    - idea-IU-233.13135.103/bin/idea.svg                                                                                                                      
    - idea-IU-233.13135.103/bin/idea64.vmoptions                                                                                                              
    - idea-IU-233.13135.103/bin/inspect.sh                                                                                                                    
    - idea-IU-233.13135.103/bin/jetbrains_client.sh                                                                                                           
    - idea-IU-233.13135.103/bin/jetbrains_client64.vmoptions       
    ....            
    - idea-IU-233.13135.103/plugins/xpath/lib/
    - idea-IU-233.13135.103/plugins/xpath/lib/rt/
    - idea-IU-233.13135.103/plugins/xpath/lib/rt/xslt-rt.jar
    - idea-IU-233.13135.103/plugins/xpath/lib/xpath.jar
    - idea-IU-233.13135.103/plugins/yaml/
    - idea-IU-233.13135.103/plugins/yaml/lib/
    - idea-IU-233.13135.103/plugins/yaml/lib/yaml.jar
    - idea-IU-233.13135.103/product-info.json