Skip to content
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

[salt-cloud] Protect against passing command line arguments as names for the --destroy command in map files #24036

Closed
arthurzenika opened this issue May 21, 2015 · 6 comments
Assignees
Labels
Bug broken, incorrect, or confusing behavior fixed-pls-verify fix is linked, bug author to confirm fix P3 Priority 3 RIoT Relates to integration with cloud providers, hypervisors, API-based services, etc. Salt-Cloud severity-medium 3rd level, incorrect or bad functionality, confusing and lacks a work around
Milestone

Comments

@arthurzenika
Copy link
Contributor

One can create a subset of a map by using the following command :

salt-cloud -m my_map one_machine another_machine

It seems that adding a --destroy offers to destroy all machines

# salt-cloud -m -d my_map one_machine another_machine
[snip] 
The following virtual machines are set to be destroyed:
  ursa-lxc:
    lxc:
      third_machine
      one_machine
      another_machine
Proceed? [N/y] 

# salt-run --versions-report
                  Salt: 2015.5.0
                Python: 2.7.6 (default, Mar 22 2014, 22:59:56)
                Jinja2: 2.7.2
              M2Crypto: 0.21.1
        msgpack-python: 0.3.0
          msgpack-pure: Not Installed
              pycrypto: 2.6.1
               libnacl: Not Installed
                PyYAML: 3.10
                 ioflo: Not Installed
                 PyZMQ: 14.0.1
                  RAET: Not Installed
                   ZMQ: 4.0.4
                  Mako: 0.9.1
 Debian source package: 2015.5.0+ds-1trusty1
@techhat
Copy link
Contributor

techhat commented May 21, 2015

I was unaware that you could select a subset of a map, and it's definitely not intentional.

But I don't understand why you need to specify a map file, then only the machines inside the map which you want to destroy. The map doesn't provide any information that would be useful for destroying. Why not just specify the names and call it good?

@rallytime rallytime added the Pending-Discussion The issue or pull request needs more discussion before it can be closed or merged label May 21, 2015
@rallytime rallytime added this to the Blocked milestone May 21, 2015
@arthurzenika
Copy link
Contributor Author

@techhat I hadn't thought of it that way, I don't often use the command without a map.

Only thing I'm curious about is the follow use case :

  • I have two backends, let's say Amazon for my production, and LXC for my dev on my laptop
  • I have machine web.example.org on Amazon which is not connected to my developement salt-master
  • I have a provider configured for Amazon so salt-cloud sees web.example.org when it queries
  • I've created web.example.org using salt-cloud and a map which indicates the provider to use is LXC

Am I sure that it's not going to delete web.example.org from Amazon if I just use salt-cloud --destroy web.exemple.org without a map ? In this case using -m my_lxc_map gives some information about which provider to query, doesn't it ?

@techhat
Copy link
Contributor

techhat commented May 22, 2015

@arthurlogilab, no, there's no guarantee that if both are available, that the wrong one won't be destroyed. But Salt Cloud also wasn't designed to be able to handle duplicate IDs, because it assumes that all IDs belong to the same master.

Recent issues that have been submitted have made it clear that people are regularly using one Salt Cloud instance to manage clouds with multiple salt-masters, or at least with multiple infrastructures. It looks like it's time to do some rethinking on this.

@rallytime
Copy link
Contributor

After discussing this with @techhat, we've decided that we're not going to support this behavior. A warning has been added to the docs declaring this. However, we should help protect against accidentally deleting an entire map file if someone does attempt to pass in a specific argument to the map file. The best thing to do here is to make sure that no arguments being passed in, ever, are ignored. Or, at the very least, raise an invocation error. See the discussion in #9772 for another example.

I'm editing the title of this issue to reflect this change.

@rallytime rallytime changed the title [salt-cloud] [UI] use command line arguments as names for the --destroy command [salt-cloud] Protect against passing command line arguments as names for the --destroy command in map files Jun 1, 2015
@rallytime rallytime added Bug broken, incorrect, or confusing behavior severity-medium 3rd level, incorrect or bad functionality, confusing and lacks a work around Salt-Cloud P3 Priority 3 and removed Pending-Discussion The issue or pull request needs more discussion before it can be closed or merged labels Jun 1, 2015
@rallytime rallytime modified the milestones: Approved, Blocked Jun 1, 2015
@jfindlay jfindlay added the RIoT Relates to integration with cloud providers, hypervisors, API-based services, etc. label Jun 9, 2015
@rallytime
Copy link
Contributor

@arthurlogilab I am not sure how are you getting to that point where salt-cloud -d is asking you if you want to delete those machines. I was attempting to add a check to make sure you can't delete your entire map file, but it's stacktracing before I even get to that point:

# salt-cloud -m -d ~/mapfile nt-14
[INFO    ] salt-cloud starting
[ERROR   ] An un-handled exception was caught by salt's global exception handler:
SaltCloudNotFound: The specified map file does not exist: -d

Traceback (most recent call last):
  File "/usr/local/bin/salt-cloud", line 10, in <module>
    salt_cloud()
  File "/root/SaltStack/salt/salt/scripts.py", line 316, in salt_cloud
    client.run()
  File "/root/SaltStack/salt/salt/cloud/cli.py", line 86, in run
    mapper = salt.cloud.Map(self.config)
  File "/root/SaltStack/salt/salt/cloud/__init__.py", line 1558, in __init__
    self.rendered_map = self.read()
  File "/root/SaltStack/salt/salt/cloud/__init__.py", line 1646, in read
    self.opts['map']
SaltCloudNotFound: The specified map file does not exist: -d
Traceback (most recent call last):
  File "/usr/local/bin/salt-cloud", line 10, in <module>
    salt_cloud()
  File "/root/SaltStack/salt/salt/scripts.py", line 316, in salt_cloud
    client.run()
  File "/root/SaltStack/salt/salt/cloud/cli.py", line 86, in run
    mapper = salt.cloud.Map(self.config)
  File "/root/SaltStack/salt/salt/cloud/__init__.py", line 1558, in __init__
    self.rendered_map = self.read()
  File "/root/SaltStack/salt/salt/cloud/__init__.py", line 1646, in read
    self.opts['map']
salt.exceptions.SaltCloudNotFound: The specified map file does not exist: -d

Versions Report:

# salt-cloud --versions
            Salt: 2015.5.0
          Python: 2.7.6 (default, Mar 22 2014, 22:59:56)
          Jinja2: 2.7.3
        M2Crypto: 0.21.1
  msgpack-python: 0.4.4
    msgpack-pure: Not Installed
        pycrypto: 2.6.1
         libnacl: Not Installed
          PyYAML: 3.11
           ioflo: Not Installed
           PyZMQ: 14.0.1
            RAET: Not Installed
             ZMQ: 4.0.4
            Mako: 0.9.1
 Apache Libcloud: 0.14.1

The stacktrace should be cleaned up, but I am not sure how you're getting past that stacktrace. I tried this on 2015.5.0, as well as 2015.5.2.

@techhat
Copy link
Contributor

techhat commented Jun 28, 2015

@rallytime switch the -d and the -m in your command line. I thought we had that cleaned up, but that's what's causing your traceback.

rallytime pushed a commit to rallytime/salt that referenced this issue Jul 30, 2015
@rallytime rallytime self-assigned this Jul 30, 2015
@rallytime rallytime modified the milestones: Be 1, Approved Jul 30, 2015
@rallytime rallytime added the fixed-pls-verify fix is linked, bug author to confirm fix label Jul 30, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug broken, incorrect, or confusing behavior fixed-pls-verify fix is linked, bug author to confirm fix P3 Priority 3 RIoT Relates to integration with cloud providers, hypervisors, API-based services, etc. Salt-Cloud severity-medium 3rd level, incorrect or bad functionality, confusing and lacks a work around
Projects
None yet
Development

No branches or pull requests

4 participants