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

Added topic filtering Plugin #118

Merged
merged 1 commit into from Mar 21, 2018
Merged

Conversation

romancardenas
Copy link
Contributor

I have developed a new version of HBMQTT which supports topic filtering. This is: you can define a topic filtering plugin in order to grant or deny subscriptions to certain topics, depending on the policy you want.
For that, I have created the hbmqtt/plugins/topic_checking.py file, where I developed a very silly topic filtering policy: If you want to subscribe to prohibited, top-secret or data/classified topics, your username must be admin. Otherwise, you will not be subscribed. You may take this example as a template for designing your own topic policy.

How to try it

After downloading this fork, execute the following python commands on the hbmqtt directory:

python3 setup.py build
python3 setup.py install

You can notice that this commit also adds a line in this script: This is necessary for the namespace to being able to detect the new plugin.

After that, you will execute three processes:

  • python3 samples/broker_taboo.py
    This starts an MQTT broker with topic_taboo plugin enabled. This can be configured via the configuration parameter of the broker:
config = {
    'listeners': {
        'default': {
            'type': 'tcp',
            'bind': '0.0.0.0:1883',
        },
        'ws-mqtt': {
            'bind': '127.0.0.1:8080',
            'type': 'ws',
            'max_connections': 10,
        },
    },
    'sys_interval': 10,
    'auth': {
        'allow-anonymous': True,
        'password-file': os.path.join(os.path.dirname(os.path.realpath(__file__)), "passwd"),
        'plugins': [
            'auth_file', 'auth_anonymous'
        ]

    },
    'topic-check': {
        'enabled': True,
        'plugins': [
            'topic_taboo'
        ]
    }
}
  • python3 samples/client_subscribe_taboo.py
    This starts an MQTT client that will try to subscribe to a valid topic and a forbidden topic

  • python3 samples/client_publish_taboo.py
    This starts an MQTT client that will publish two messages in the valid and the forbidden topic.
    The console of the client subscribed will only receive the valid message.

@coveralls
Copy link

Coverage Status

Coverage remained the same at ?% when pulling 59f9d28 on romancardenas:master into 0d6030c on beerfactory:master.

1 similar comment
@coveralls
Copy link

coveralls commented Mar 19, 2018

Coverage Status

Coverage remained the same at ?% when pulling 59f9d28 on romancardenas:master into 0d6030c on beerfactory:master.

@PythonLinks
Copy link

This is a really good idea for corporate chat servers. Have a tree of topics, but only allow certain users to see certain topics. Perhaps some of the MQTT servers support access control lists, but that becomes very cumbersome. Much better to call a Python function.

The next thing I need are tools to store the messages by topic, one file for each topic. I would think that this is a very common need, and yet I am having difficulty finding such a tool . Here is the only such tool I have found.
http://www.steves-internet-guide.com/simple-python-mqtt-data-logger/
Are any others out there?

@romancardenas romancardenas mentioned this pull request Mar 19, 2018
@romancardenas
Copy link
Contributor Author

I will check that upgrade. I am now working on a project where security and privacy is very important, so I really need a broker able to filter subscriptions.
I am working now on a new version able to filter publications, but I would prefer this repository to accept my contributions one by one. In this way, the upgrades would be maintained by the whole community, which is a great opportunity to enrich this project.

@njouanin njouanin merged commit 53fd32e into njouanin:master Mar 21, 2018
@njouanin njouanin added this to the 0.10.0 milestone Mar 21, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants