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

Apply ACL controls to PUBLISH operations #66

Merged
merged 33 commits into from
Aug 17, 2021

Conversation

sjlongland
Copy link
Contributor

This is a work-in-progress, but basically the idea is that the topic_acl plug-in should be able to also dictate what topics a user may publish to, as well as what topics they may subscribe from.

Not fully tested at this stage… still trying to figure out the structure of the test suite.

This will allow a topic filter to act on both subscription requests and
publishing.
We maintain backward compatibility with older configurations by assuming
all `PUBLISH` actions are permitted if no ACL is present.  Otherwise, we
follow the same rules as for `SUBSCRIBE`, with the exception that we
read the ACL from the `publish-acl` property instead of `acl`.
If the user forgets to provide a `topic-check` key, we need to
initialise `topic_config` to some value or else `topic_filtering` will
fail with an `AttributeError`.
@sjlongland sjlongland force-pushed the feature/publish-acl branch from 863bc30 to 60f3bee Compare June 6, 2021 06:47
This is more of a "demo" plug-in, but let's test it anyway.
If `BaseTopicPlugin` returns `False`, we should propagate that failed
response in `TopicAccessControlListPlugin`.
Yes, too lazy to hold down shift when hitting the `'` key.
@FlorianLudwig
Copy link
Member

Hi @sjlongland Thanks for taking this up!

Have you seen #42?

I guess your work superseeds that MR.

This uses the real plug-ins to test the broker correctly responds to the
return values when publishing and subscribing.

The plug-ins themselves are tested elsewhere.
@sjlongland
Copy link
Contributor Author

Hi @sjlongland Thanks for taking this up!

Have you seen #42?

I guess your work superseeds that MR.

I had not seen that (should've looked first I guess). Seems there's a bit more to be done on that before it can be merged.

@sjlongland
Copy link
Contributor Author

I couldn't figure out an easy way to "unit test" the relevant code paths in amqtt/broker.py, so wound up spinning up a separately configured server on a different port. Not ideal, but it gets the job done, and the plug-ins themselves have unit tests now.

@sjlongland
Copy link
Contributor Author

So, rather than making DummyLogger a fixture, I had another look around, and found a py.test plug-in that basically allows us to do the same thing with much greater flexibility.

https://pypi.org/project/pytest-logdog/

Have a look, and see what you think.

@sjlongland sjlongland marked this pull request as ready for review July 4, 2021 06:21
@FlorianLudwig
Copy link
Member

Hi @sjlongland thanks for continuing the work on this!

The amount of tests is amazing :)

regarding pytest-logdog

I usually don't test log output, so I am not really knowladable about the different log-capture plugins that exist for pytest.
This one seems to be rather newesh from a lone developer - which is something I am usually a bit cautions about.
Otherwise the plugin looks good.

releasing

Your contribution will make it into 0.11 as it does break the API. With 0.11 we will take more freedom to break with hbmqtt

test_user:$6$.c9f9sAzs5YXX2de$GSdOi3iFwHJRCIJn1W63muDFQAL29yoFmU/TXcwDB42F2BZg3zcN5uKBM0.1PjwdMpWHRydbhXWSc3uWKSmKr.
# Password for these is "test"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should have different passwords for different test users - otherwise a bug where user1 can authenticate with password of user2 might not be catched.

While this MR is not about authentication, having it in the example data is a liability in my eyes :)

assert authorised is False

# Should have printed a couple of warnings
log_records = list(pile.drain(name="testlog"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example in the documentation interacts with pile after closing the context manager. Not sure how exactly it is intended to be used.

As pointed out, the `logdog` docs do the checks outside of the context
manager scope, so we should do so as well.
As pointed out, it's possible to accidentally mix them up if the
passwords are the same.  Obviously, the passwords used for these tests
should _NOT_ be used in production.
@sjlongland
Copy link
Contributor Author

Yeah, the password thing was me being lazy… but you make a valid point. I've changed those.

As for logdog… it's a valid criticism, I suppose the decision was between something like that which is maintained by one person and is "new", or doing something custom like the DummyLogger class I started (thus is newer), which we'd have to maintain ourselves. py.test also has some logging capture fixtures, but they basically give you everything and you have to filter it yourself, which was the problem that inspired logdog.

A release in 0.11 makes sense. Shake off the shackles of hbmqtt in 0.10. :-)

Copy link
Contributor

@HerrMuellerluedenscheid HerrMuellerluedenscheid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks!

@FlorianLudwig your call. Approved from my side.

EDIT: Well, that was a little too early I guess :) Some failures need to be fixed on the pipeline.

@sjlongland
Copy link
Contributor Author

I think I've got the formatting issues sorted, just working through how to call flake8 to get a meaningful report.

@sjlongland
Copy link
Contributor Author

There we go, I've ignored the warnings from the hbmqtt tree as I didn't touch that… anything in tests/ and amqtt should be clean now. :-)

Seems Python 3.8+ moved it, and I took the reference from there.
@HerrMuellerluedenscheid
Copy link
Contributor

Is this good to go? LGTM. @sjlongland if this is ready, can you request a review from @FlorianLudwig ?

@sjlongland
Copy link
Contributor Author

Is this good to go? LGTM. @sjlongland if this is ready, can you request a review from @FlorianLudwig ?

Yep, it is… and I have. :-)

@FlorianLudwig
Copy link
Member

The master-branch is now open for 0.11 - time to break some api! :)

@FlorianLudwig FlorianLudwig merged commit 5315e2d into Yakifo:master Aug 17, 2021
@sjlongland sjlongland deleted the feature/publish-acl branch August 17, 2021 21:42
@sjlongland
Copy link
Contributor Author

Many thanks. :-)

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.

3 participants