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

fix: dashboard get by id or slug access filter #22358

Conversation

dpgaspar
Copy link
Member

@dpgaspar dpgaspar commented Dec 7, 2022

SUMMARY

This PR re-introduces the defined dashboard access filter into Dashboard DAO get item method.
Currently viewing a list of dashboards and requesting a specific dashboard by its slug or id will allow for different access levels.

I believe that access filters at the DAO level need to be applied on all methods (that fetch or mutate a not yet fetched item) and offer a coherent centralised first layer of security checks

This PR also:

  • Changes HTTP response status codes for filter states, since a dashboard that a user does not have permission to access is automatically filtered at the DAO level, filter states for these dashboards will return 404 instead of 403 (Improved security)

  • Fixes a bug when using DASHBOARD_RBAC, currently on master, a Gamma user (for example) that has access to a dashboard using data access permissions can list the dashboard but can't render the dashboard itself (/api/v1/dashboard/<id> and /api/v1/dashboard/<id>/charts/ returns HTTP 403). This happens because only raise_for_dashboard_access is called and not data access permission is previously checked.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@dpgaspar dpgaspar changed the title fix: dashboard get by id or slug access filter [WiP] fix: dashboard get by id or slug access filter Dec 7, 2022
@codecov
Copy link

codecov bot commented Dec 7, 2022

Codecov Report

Merging #22358 (b5b1e84) into master (ff1d29c) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master   #22358      +/-   ##
==========================================
- Coverage   66.85%   66.85%   -0.01%     
==========================================
  Files        1847     1850       +3     
  Lines       70560    70658      +98     
  Branches     7737     7737              
==========================================
+ Hits        47173    47238      +65     
- Misses      21380    21413      +33     
  Partials     2007     2007              
Flag Coverage Δ
hive 52.47% <42.85%> (-0.06%) ⬇️
mysql 77.97% <100.00%> (+0.02%) ⬆️
postgres 78.04% <100.00%> (+0.02%) ⬆️
presto 52.37% <42.85%> (-0.06%) ⬇️
python 81.19% <100.00%> (-0.05%) ⬇️
sqlite ?
unit 50.92% <42.85%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
superset/dashboards/dao.py 96.40% <100.00%> (+0.02%) ⬆️
superset/dashboards/filter_state/commands/utils.py 80.00% <0.00%> (-10.00%) ⬇️
superset/db_engine_specs/sqlite.py 89.28% <0.00%> (-7.15%) ⬇️
superset/tasks/thumbnails.py 39.02% <0.00%> (-6.14%) ⬇️
...uperset/dashboards/filter_state/commands/delete.py 91.30% <0.00%> (-4.35%) ⬇️
superset/utils/celery.py 86.20% <0.00%> (-3.45%) ⬇️
...uperset/dashboards/filter_state/commands/update.py 96.66% <0.00%> (-3.34%) ⬇️
superset/connectors/sqla/utils.py 87.37% <0.00%> (-1.95%) ⬇️
superset/result_set.py 96.42% <0.00%> (-1.43%) ⬇️
superset/db_engine_specs/bigquery.py 81.68% <0.00%> (-1.00%) ⬇️
... and 23 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@pull-request-size pull-request-size bot added size/M and removed size/S labels Dec 9, 2022
@pull-request-size pull-request-size bot added size/L and removed size/M labels Dec 9, 2022
@dpgaspar dpgaspar changed the title [WiP] fix: dashboard get by id or slug access filter fix: dashboard get by id or slug access filter Dec 14, 2022
@@ -40,11 +40,22 @@ class DashboardDAO(BaseDAO):
base_filter = DashboardAccessFilter

@staticmethod
def get_by_id_or_slug(id_or_slug: str) -> Dashboard:
dashboard = Dashboard.get(id_or_slug)
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't FAB fetch all the relationships as well, i.e., why do we need to explicitly compose a query which joins all the related models?

Copy link
Member Author

Choose a reason for hiding this comment

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

it does but the get item endpoint for dashboards is custom on Superset because we need to fetch a dashboard by id or slug, so on this case we need to custom develop. FAB ModelRestApi on get item endpoints will get item by the table primary key

"""
All users should have access to dashboards without roles
Copy link
Member

Choose a reason for hiding this comment

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

Is All users should have access to dashboards without roles not supported anymore? Does a draft dashboard have roles?

Copy link
Member Author

@dpgaspar dpgaspar Dec 22, 2022

Choose a reason for hiding this comment

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

yes this PR removes it. I'm setting /api/v1/dashboard/<1> to the same level of authorization has /api/v1/dashboard/, this mean the dashboard metadata has the same access level

@michael-s-molina
Copy link
Member

/testenv up

@github-actions
Copy link
Contributor

@michael-s-molina Ephemeral environment spinning up at http://34.220.124.185:8080. Credentials are admin/admin. Please allow several minutes for bootstrapping and startup.

Copy link
Member

@michael-s-molina michael-s-molina left a comment

Choose a reason for hiding this comment

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

LGTM

@dpgaspar dpgaspar merged commit 3761694 into apache:master Jan 5, 2023
@dpgaspar dpgaspar deleted the danielgaspar/sc-53722/fix-dashboard-by-id-or-slug-unauthorised branch January 5, 2023 17:10
@github-actions
Copy link
Contributor

github-actions bot commented Jan 5, 2023

Ephemeral environment shutdown and build artifacts deleted.

sadpandajoe added a commit to preset-io/superset that referenced this pull request Jan 31, 2023
AnushaErrabelli added a commit to preset-io/superset that referenced this pull request Jan 31, 2023
sadpandajoe added a commit to preset-io/superset that referenced this pull request Feb 24, 2023
sadpandajoe added a commit to preset-io/superset that referenced this pull request Feb 27, 2023
@dpgaspar dpgaspar added the v2.1 label Mar 2, 2023
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 2.1.0 and removed 🚢 2.1.3 labels Mar 13, 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 v2.1 🚢 2.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants