salt icon indicating copy to clipboard operation
salt copied to clipboard

event_return_whitelist does not implictly blacklist any tag not listed

Open dcovello opened this issue 10 years ago • 3 comments

Description of Issue/Question

I was looking utilize the event_return whitelist feature feature to essentially blacklist all event tags except those I have listed under the event_return_whitelist in my salt-master config. However, after configuring my environment multiple times and testing different combinations of event_return_whitelist and event_return_blacklist I took a look at the source code and noticed that there currently is no way to accomplish what I set out to do without individually declaring tags/globs under event_return_blacklist for all events I don't want published to my returner.

Taking a look at the _filter function in the current salt/utils/event.py :

   def _filter(self, event):
        '''
        Take an event and run it through configured filters.
        Returns True if event should be stored, else False
        '''
        tag = event['tag']
        if tag in self.opts['event_return_whitelist']:
            if tag not in self.opts['event_return_blacklist']:
                return True
            else:
                return False  # Event was whitelisted and blacklisted
        elif tag in self.opts['event_return_blacklist']:
            return False
return True

From the above logic there a four paths of logic:

  1. Event tag does exist in the whitelist and does NOT exist in the blacklist. Event Tag is published.
  2. Event tag does exist in the whitelist and does exist in the blacklist. Event Tag is NOT published.
  3. Event tag does NOT exist in the whitelist and does exists in the blacklist. Event Tag is NOT published.
  4. Event tag does NOT exist in the white list and does NOT exist in the blacklist. Event Tag is published.

Scenario 4 currently renders the concept of the event_return_whitelist useless since the tag will always be published as long as its not listed in the blacklist.

I'm not sure that this is the desired implementation of the whitelist feature but I believe that the presence of a whitelist should implicility blacklist all entries that don't exist in it.

Versions Report

(Snippet of code under description was taken from latest github)

Tested on salt 2015.8.10 (Beryllium)


Dependency Versions:
         Jinja2: 2.7.2
       M2Crypto: 0.21.1
           Mako: Not Installed
         PyYAML: 3.10
          PyZMQ: 14.0.1
         Python: 2.7.6 (default, Jun 22 2015, 17:58:13)
           RAET: Not Installed
        Tornado: 4.2.1
            ZMQ: 4.0.4
           cffi: 1.6.0
       cherrypy: 3.2.2
       dateutil: 1.5
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: Not Installed
        libgit2: 0.22.2
        libnacl: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.3.0
   mysql-python: Not Installed
      pycparser: 2.14
       pycrypto: 2.6.1
         pygit2: 0.22.1
   python-gnupg: Not Installed
          smmap: Not Installed
        timelib: Not Installed

System Versions:
           dist: Ubuntu 14.04 trusty
        machine: x86_64
        release: 4.2.0-27-generic
         system: Ubuntu 14.04 trusty

dcovello avatar Jun 20 '16 22:06 dcovello

@dcovello I agree with you that we need to ensure if event_return_whitelist is set and the event tag does NOT exist in the white list and does NOT exist in the blacklist the tag should not be published. Looks like we need to get this fixed up. Thanks.

Ch3LL avatar Jun 21 '16 16:06 Ch3LL

@dcovello I think the change in #34690 should fix this up for you. Would you mind giving that a try?

rallytime avatar Jul 18 '16 16:07 rallytime

@rallytime

Tested the following event_return_whitelist configuration :

event_return_whitelist:
   - salt/key
   - salt/fs/states/updated

Using "salt-call event.send" to test, I observed that my custom returner module only received events whose tag matched "salt/key" and "salt/fs/states/updated". All other tags were not passed onto my returner. It looks like the whitelisting portion of this fix is working as I expected now.

Thanks!

Tested against the following salt version:

Salt Version:
           Salt: 2016.3.0-912-gbfd87b1

Dependency Versions:
           cffi: 1.7.0
       cherrypy: 3.2.2
       dateutil: Not Installed
          gitdb: Not Installed
      gitpython: Not Installed
          ioflo: Not Installed
         Jinja2: 2.7.2
        libgit2: 0.22.2
        libnacl: Not Installed
       M2Crypto: 0.21.1
           Mako: Not Installed
   msgpack-pure: Not Installed
 msgpack-python: 0.3.0
   mysql-python: Not Installed
      pycparser: 2.14
       pycrypto: 2.6.1
         pygit2: 0.22.1
         Python: 2.7.6 (default, Jun 22 2015, 17:58:13)
   python-gnupg: Not Installed
         PyYAML: 3.10
          PyZMQ: 14.0.1
           RAET: Not Installed
          smmap: Not Installed
        timelib: Not Installed
        Tornado: 4.4
            ZMQ: 4.0.4

System Versions:
           dist: Ubuntu 14.04 trusty
        machine: x86_64
        release: 4.2.0-27-generic
         system: Linux
        version: Ubuntu 14.04 trusty

dcovello avatar Jul 26 '16 20:07 dcovello