-
Notifications
You must be signed in to change notification settings - Fork 15
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: add support for extra rlsf #107
Conversation
Thanks for the pull request, @Ian2012! Please note that it may take us up to several weeks or months to complete a review and merge your PR. Feel free to add as much of the following information to the ticket as you can:
All technical communication about the code itself will be done via the GitHub pull request interface. As a reminder, our process documentation is here. Please let us know once your PR is ready for our review and all tests are green. |
274a9ba
to
72a85fb
Compare
9cc35d5
to
d72abc3
Compare
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.
This seems ok to me, but @pomegranited knows a lot more about it than I do
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.
@Ian2012 This is working fine, and a good addition to the config.
But I have some questions about the documentation, and a suggestion for the implementation. What do you think?
tutoraspects/templates/aspects/apps/superset/pythonpath/create_row_level_security.py
Outdated
Show resolved
Hide resolved
assert openedx_role, "{{SUPERSET_OPENEDX_ROLE_NAME}} role doesn't exist yet?" | ||
|
||
for (schema, table_name, group_key, clause, filter_type) in ( | ||
row_level_security_filters = [ | ||
( | ||
"{{ASPECTS_XAPI_DATABASE}}", | ||
"{{ASPECTS_XAPI_TABLE}}", |
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 see we actually do have a new datasources for transcript_usage
and video_plays
now.. don't we need RLSFs for them too?
And so maybe the details for these filters should all live in the tutor config, so here we can iterate over SUPERSET_ROW_LEVEL_SECURITY_FILTERS
+ SUPERSET_EXTRA_ROW_LEVEL_SECURITY_FILTERS
?
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.
Thanks for the review, I agree in all points
1bd1f80
to
fac03dd
Compare
@pomegranited it seems like tutor doesn't render nested fields, so this: "SUPERSET_BASE_ROW_LEVEL_SECURITY_FILTERS", {
"schema": "{{ ASPECTS_XAPI_DATABASE }}",
"table_name": "{{ ASPECTS_XAPI_TABLE }}",
"role_name": "{{ SUPERSET_OPENEDX_ROLE_NAME }}",
"group_key": "{{ SUPERSET_ROW_LEVEL_SECURITY_XAPI_GROUP_KEY }}",
"clause": "{{can_view_courses(current_username(),"
"\"splitByChar(\"/\", course_id)[-1]\")}}",
"filter_type": "Regular",
}, Is rendered as raw strings. BASE_SECURITY_FILTERS = [
(
"{{ ASPECTS_XAPI_DATABASE }}",
"{{ ASPECTS_XAPI_TABLE }}",
"{{ SUPERSET_OPENEDX_ROLE_NAME }}",
"{{ SUPERSET_ROW_LEVEL_SECURITY_XAPI_GROUP_KEY }}",
'{{can_view_courses(current_username(),"splitByChar("/", course_id)[-1]")}}',
"Regular",
),
] This should be refactored, but I will go back to the old approach. And mark it for improvement. |
5e14622
to
458eac4
Compare
@pomegranited @bmtcril I've used a patch to add base security filters that will support interpolation, so I guess the setting SUPERSET_EXTRA_ROW_LEVEL_SECURITY_FILTERS is not needed anymore, because one can use the tutor patch to accomplish the same result and use the same "api" to define rlsf |
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.
@Ian2012 I started reviewing this too but ran out of time.. I'd specifically like to test the SUPERSET_EXTRA_JINJA_FEATURES patch you've documented to make sure it actually works.
But here's some comments, thanks for this!
README.rst
Outdated
.. code-block:: python | ||
|
||
def can_view_courses(username, field_name="course_id"): |
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.
Don't we need to provide yaml here?
.. code-block:: python | |
def can_view_courses(username, field_name="course_id"): | |
.. code-block:: python | |
SUPERSET_EXTRA_JINJA_FILTERS: | |
custom_can_view_courses: | | |
def can_view_courses(username, field_name="course_id"): |
And so I think the rest of this code block needs to be indented too?
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 was not clear with this documentation, I corrected and added a missing step for register the jinja filter using SUPERSET_EXTRA_JINJA_FILTERS
ac87942
to
c2b6fa7
Compare
@pomegranited This is ready for review, I will assign proper rlsf to the other datasets in another PR with some changes to the permissions |
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.
Just a couple of documentation nits. I tested this by creating a plugin with both patches, installing it, init-ing superset, and confirming that the sql was appended to the queries appropriately by both seeing the data change and by viewing the chart SQL.
README.rst
Outdated
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
If you add new datasources, tables, or fields to Superset, you may want to add new `row level security filters`_ | ||
to restrict access to that data based on people's course roles. To apply custom row level security filters |
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.
nit: "to restrict access to that data based on things like course roles, or organization"
Since you can use these on any column.
superset-row-level-security: | | ||
{ | ||
"schema": "{{ASPECTS_XAPI_DATABASE}}", | ||
"table_name": "{{ASPECTS_XAPI_TABLE}}", |
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.
We should be really clear that the schema / table need to exist in the assets.yaml
, so they can't filter on upstream tables that don't end up getting imported to Superset. I just fought with this for 30 mins trying to figure out why it thought a table didn't exist. Maybe a note about when you see AssertionError: {schema.table} table doesn't exist yet?
to make sure it's exported to Superset.
Just a heads up on this: #153 I think it's probably a more general issue of "how do we deal with deleted assets" but I wanted to track it. |
c2b6fa7
to
892cba8
Compare
@bmtcril ready, I cannot merge it |
@Ian2012 🎉 Your pull request was merged! Please take a moment to answer a two question survey so we can improve your experience in the future. |
Description
This PR allows importing extra row-level security filters, which in combination with #123 will allow users to have granular control over what users can see.
Use cases: