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
feat(authz): use extensible map format for actions in authz rules #11132
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
savonarola
force-pushed
the
0531-authz-qos-retain
branch
11 times, most recently
from
June 28, 2023 09:39
d7ded9c
to
6711ed5
Compare
savonarola
requested review from
a team,
kjellwinblad,
lafirest,
sstrigler and
JimMoen
as code owners
June 28, 2023 10:48
savonarola
force-pushed
the
0531-authz-qos-retain
branch
4 times, most recently
from
July 4, 2023 13:55
2855c7a
to
f88272d
Compare
thalesmg
reviewed
Jul 4, 2023
thalesmg
previously approved these changes
Jul 5, 2023
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I still haven't gone through the tests, but looks good! 🍻
savonarola
force-pushed
the
0531-authz-qos-retain
branch
from
July 7, 2023 13:25
5ed4e42
to
d5f8dee
Compare
* support authorization on retain, qos fields * refactored authz tests heavily
Co-authored-by: Thales Macedo Garitezi <thalesmg@gmail.com>
savonarola
force-pushed
the
0531-authz-qos-retain
branch
from
July 7, 2023 16:42
d5f8dee
to
19f9fc5
Compare
id
approved these changes
Jul 10, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes EMQX-9766
Problem
We have to control whether a client can write retain messages or subscribe/publish using certain QoS levels.
Current model
In authz, we have
allow
anddeny
topic
andaction
(publish, subscribe, all)New model
The current model is not very extensible. We have hotwired primitive types for all resources. We need to extend the model to support more complex resources.
Since the topic is considered to be more or less "constant" data-like structure (e.g. different clients may subscribe the same topic in a different manner), we choose to extend the
action
part of the resource.This also more or less reflects the MQTT protocol itself, where the QoS/Retain are a part of the PUBLISH/SUBSCRIBE packet: different clients subscribe differently to the same topic.
Internal model
Internally we extend the signature of the
emqx_access_control:authorize/3
callback.From
To
Thus, we make
emqx_types:pubsub()
extensible if needed.We update all the entry points (including gateways) to pass the new extended action to the
authorize/3
function.External model
That is, how the user will configure the authorization rules.
We now explicitly differentiate between three types of rules:
raw
rules: rules obtained as plain data structures from a database or API, having the format like:We have a module
emqx_authz_rule_raw
to convert betweenraw
anddsl
rules.dsl
rules: rules described with Erlang data structures. They are used bymnesia
andfile
backends.We use
emqx_authz_rule
to convert fromdsl
tocompiled
rules.compiled
rules: slightly converterdsl
rules, used for final matching.We refactor the backends to utilize the common parser and validator of
raw
rules.Test refactoring
Previous test implementation was not very flexible and was not able to test the new model.
The problem was that the test both "inserted" the test data into a database and then also "queried" the database to check the results. However, many bugs may come from how the data is inserted into the database in the wild, because this is the part that is more likely to be customized by the user.
So we refactor the tests to be more like authn tests, where for each test we have its own storage schema and inserted data.
Example:
Here we explicitly check that
retain
flag stored as an integer is handled correctly.Summary
🤖 Generated by Copilot at d49e101
This pull request enhances the authorization logic and features of the EMQ X broker by adding support for QoS and retain properties in the publish action, and by refactoring and improving the code quality and compatibility of the authorization modules and test suites. It also introduces a new placeholder for the retain flag, a new module for parsing and formatting raw rules, and some new macros and types for the action conditions. The pull request affects several files in the
apps/emqx_authz
andapps/emqx
directories.PR Checklist
changes/{ce,ee}/(feat|perf|fix)-<PR-id>.en.md
files