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

[metric] Exposing security methods for visualizations and query-context #8175

Conversation

john-bodley
Copy link
Member

@john-bodley john-bodley commented Sep 5, 2019

CATEGORY

Choose one

  • Bug Fix
  • Enhancement (new features, refinement)
  • Refactor
  • Add tests
  • Build / Development Environment
  • Documentation

SUMMARY

For both the Druid and SQLA connectors metrics can be restricted (via the metric_access permission) however there were not really any security checks associated with this. For the Druid connector there was a check to see if restricted metrics were being used at query time (though this can be pushed higher in the stack to the views given that the Druid REST API doesn't support SQL).

I realize that with the advent of ad-hoc metrics the notion of restricted metrics is probably somewhat obsolete but there seems to be merit in having the security manager be more context aware from a permission standpoint for the explore_json, slice_json, or v1/query routes where rather than checking whether the user has access to the datasource the check should be at the visualization or query context level (higher fidelity).

This PR adds a couple of more context aware (higher fidelity) public methods to the security manager:

  • assert_query_context_permission
  • assert_viz_permission

replacing calls to assert_datasource_permission where appropriate.

TEST PLAN

Added unit tests.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Changes UI
  • Requires DB Migration.
  • Confirm DB Migration upgrade and downgrade tested.
  • Introduces new feature or API
  • Removes existing feature or API

REVIEWERS

to: @betodealmeida @DiggidyDave @michellethomas @mistercrunch @villebro

@john-bodley john-bodley force-pushed the john-bodley--security-assert-viz-access branch from 8d728bd to 7683b7c Compare September 5, 2019 00:47
@mistercrunch
Copy link
Member

I really think we should deprecate restricted metrics as they don't work as expected since the adhoc metrics have been added.

Also agree with moving more data-access logic and context to the security manager.

@john-bodley
Copy link
Member Author

@mistercrunch are you ok with the security manager having logic like assert_viz_permission?

I agree that we should probably deprecate restricted metrics seeing as i) ad-hoc metrics completely bypass the restrictedness, and ii) there’s currently no check for SQL datasources.

Do you think it best if I provide the change to deprecate restricted metrics in this PR or a followup PR?

@mistercrunch
Copy link
Member

The idea of assert_viz_permission in SecurityManager makes sense and I understand why you'd do that.

The only concern is whether the BaseViz interface is settled enough to expose externally through SecurityManager. assert_query_context_permission exposes less surface which is preferable. Taping into the viz object offers lots of flexibility, but little guarantee as to whether you hooks will still work after you upgrade...

There's another underlying issue I'd like to fix, it's the fact that check_datasource_perms is called from a decorator and recreates a BaseViz object that gets thrown away and recreated later on. Decorators are cool and all, but a clear shortcoming is how it gets ugly in cases like this (context need to be shared across decorator and function body). We need to de-decorate that function and do things right.

Also we should clarify if these security assertions call each other or, the view calls them individually/sequentially. It works either way, but what's important is having something super intuitive and readable. Currently there's quite a bit of indirection (the decorator with the callback + a complex method hierarchy) and it's hard to reason about and easy to eff this up and introduce some regression.

Knowing all this, what we want to accomplish:

  • deprecate restricted metrics
  • de-decorate security assertions
  • have a set of comprehensive data access assertion in security manager (clear score and hierarchy, consistent naming, clarity on what is private/public), comments on places where interfaces may change (override at your own risk!)

I'm not sure how to roll this out best, but a chain of small PRs is probably best.

About restricted metrics, you could start partially deprecating here by not trying to migrate the code, idk how involved deprecating the feature will be, but shouldn't be too hard.

@mistercrunch
Copy link
Member

I was curious to give deprecation of restricted metrics a shot and it took me ~15 minutes to get to this draft: #8197

@mistercrunch
Copy link
Member

I merged the PR deprecating is_restricted and related logic/docs, it should simplify this one.

@john-bodley
Copy link
Member Author

Thanks @mistercrunch. I’ll update the logic in this PR. I agree that the security manager is overly complex and will try to simplify where possible.

@john-bodley john-bodley force-pushed the john-bodley--security-assert-viz-access branch 3 times, most recently from 5ffa99c to 5fc3d7d Compare September 12, 2019 22:02
@john-bodley john-bodley changed the title [metric] Adding security for restricted metrics [metric] Exposing security methods for visualizations and query-context Sep 12, 2019
@john-bodley john-bodley force-pushed the john-bodley--security-assert-viz-access branch from 5fc3d7d to ca30ca4 Compare September 12, 2019 22:39
@john-bodley
Copy link
Member Author

john-bodley commented Sep 12, 2019

@mistercrunch thanks for deprecating the restricted metrics (as a side note I wonder if there should be another migration to remove all the obsolete metric_access permissions).

I've updated the PR which removes the now obsolete metric checks. Are you still supportive of having the:

  • assert_query_context_permission
  • assert_viz_permission

methods which now have the same behavior as the datasource access but simply provide more context, i.e., the fully defined current context, if a custom security manager would like to override.

Let me know how best to proceed.

Copy link
Member

@etr2460 etr2460 left a comment

Choose a reason for hiding this comment

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

lgtm

@etr2460
Copy link
Member

etr2460 commented Sep 25, 2019

@mistercrunch could you take another look at this?

Copy link
Member

@mistercrunch mistercrunch left a comment

Choose a reason for hiding this comment

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

LGTM

Not a dealbreaker but caution around having external code (in your security manager) around BaseViz as it's not guaranteed it will stay the same in the future.

@john-bodley
Copy link
Member Author

Noted @mistercrunch.

@john-bodley john-bodley merged commit 05b6767 into apache:master Oct 1, 2019
@john-bodley john-bodley deleted the john-bodley--security-assert-viz-access branch October 1, 2019 23:52
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 0.35.0 labels Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels size/L 🚢 0.35.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants