-
Notifications
You must be signed in to change notification settings - Fork 14.6k
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
fix: Refactor ownership checks #20499
fix: Refactor ownership checks #20499
Conversation
Codecov Report
@@ Coverage Diff @@
## master #20499 +/- ##
==========================================
- Coverage 66.82% 66.59% -0.24%
==========================================
Files 1752 1751 -1
Lines 65620 65504 -116
Branches 6938 6940 +2
==========================================
- Hits 43853 43620 -233
- Misses 20007 20122 +115
- Partials 1760 1762 +2
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
9d16076
to
80d717b
Compare
superset/security/manager.py
Outdated
owners.append(resource.owner) | ||
|
||
if hasattr(resource, "created_by"): | ||
owners.append(resource.created_by) |
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 comparing this method to the old one which pulled out the original object from the db rather than use the one that was passed in. Could the resource here come from user input rather than the db? I'm thinking of the scenario where a non-owner might try to grant themselves ownership by adding themselves to the list of owners on a resource. Since it's not making a db call to the original resource could we be allowing them to define their own set of owners? One example perhaps is the pre_update
hook for the SliceModelView
.
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.
@eschutho apologies for the delay in responding as I was away on PTO. I think the point you raise is a good call and I'll revert the logic.
As a side note I think a lot of the pre_update
logic is possibly obsolete with the DAO model—which merely complicates the code base—and we likely could deprecate some of that. I'm planning on authoring another PR to address said issue.
80d717b
to
f71f182
Compare
88c5910
to
91c9b14
Compare
d0b4273
to
e220a4c
Compare
e220a4c
to
560ff4a
Compare
50b921d
to
6aa4855
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.
lgtm
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 does shave the Yak a bit more ;)
On the other hand we will loose some future flexibility if we would ever wanted to use DAO or commands with different users, celery context for example?
superset/security/manager.py
Outdated
return | ||
|
||
orig_resource = ( | ||
db.session.query(resource.__class__).filter_by(id=resource.id).first() |
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: db.session.query(resource.__class__).filter_by(id=resource.id).one_or_none()
or db.session.query(resource.__class__).get(resource.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.
@dpgaspar I agree with the one_or_none
. This was a copy-and-paste from check_ownership
but I'll make the update.
I don't disagree in terms of lose of flexibility, however the |
6aa4855
to
7f71252
Compare
7f71252
to
823b9d3
Compare
Co-authored-by: John Bodley <[email protected]>
SUMMARY
Yak shaving at its finest. Originally I drafted this PR to fix an issue with inconsistencies between ownership checks as described in this Slack thread. BTW this PR does not address said issue—I believe we only need a migration for legacy charts/datasets.
Things quickly spiraled out of control as I realized that the DAO
check_access
method checks whether the actor is an owner alongside a check whether the current user is an admin—this clearly is wrong, i.e., both checks should be for the same user. Digging further I realize that the actor is alwaysg.user
and thus continuing my crusade to simplify the whole user space (removing passingg.user
all around the place) I opted to fully deprecate the actor concept—which touched a huge swatch of files. The main reason being is that Superset is really only configured to work with the logged in user and overrides should be done—if needed—via theoverride_user
context manager.The TL;DR of this PR:
actor
construct across all the DAO models.check_ownership
which either raised or returned abool
into theraise_for_owernship
andis_owner
methods—the later being a wrapper of the former. This helps to improve code readability, i.e., it is apparent thatraise_for_owernship
raises. These methods have been moved to the security manager to allow for customization.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TESTING INSTRUCTIONS
ADDITIONAL INFORMATION