Repository navigation
feat(improvements): let deployments withhold assets from list queries and commands - #45451
Conversation
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #45451 +/- ##
=======================================
Coverage 84.05% 84.06%
=======================================
Files 3056 3056
Lines 200958 201028 +70
Branches 47016 47025 +9
=======================================
+ Hits 168922 168988 +66
- Misses 28798 28800 +2
- Partials 3238 3240 +2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
…andrusoare/fix/folder-access-exclusions
msyavuz
left a comment
There was a problem hiding this comment.
- Are we OK with the Explore change locking out viewers who reach a chart only through dashboard access, or should it be gated behind a flag or config?
| """ | ||
|
|
||
| def apply(self, query: Query, value: Any) -> Query: | ||
| query = apply_extra_access_exclusions(query, "report_target_charts", Slice.id) |
There was a problem hiding this comment.
The report_target_* exclusion only narrows the related-field dropdown: _check_object_access in commands/report/base.py resolves the target through ChartDAO/DashboardDAO.find_by_id, whose base filter applies only the plain charts/dashboards key, so a POST or PUT with an excluded chart or dashboard id is still accepted.
There was a problem hiding this comment.
Correct, and the important one — thanks. The filter only shaped the picker; _check_object_access resolves the target through find_by_id, which applies the plain key, so a direct POST still went through. Now it asks the same question where the id is actually resolved, and surfaces the deployment's reason on the 403. Added a test asserting the single-id check agrees with the filter.
| if not user_id: | ||
| return query | ||
|
|
||
| return query.filter(id_column.notin_(hook(user_id))) |
There was a problem hiding this comment.
NOT IN against a hook subquery that yields any NULL id evaluates to NULL for every row, so a single NULL silently empties the whole chart or dashboard list, including for admins; filter out NULLs or use NOT EXISTS.
There was a problem hiding this comment.
Right. I'd written this down as a known hazard and shipped it anyway, so thanks for catching it. Switched to NOT EXISTS, which doesn't match a NULL, so a malformed hook withholds nothing instead of everything. Test puts a literal NULL through a hook and asserts the list survives.
| # dataset grant of their own, and the chart check alone let it pass. | ||
| security_manager.raise_for_access(chart=slc) | ||
| elif isinstance(datasource, Query): | ||
| _raise_for_datasource(datasource) |
There was a problem hiding this comment.
Saved charts now also need dataset access, so dashboard-only viewers (dashboard RBAC or EXTRA_RAISE_FOR_ACCESS_BYPASS) who could open "View in Explore" before will now get a 403; this is a user-visible behaviour change and has no UPDATING.md entry.
There was a problem hiding this comment.
Moot now that the Explore change is out — with it gone there's no user-visible behaviour change left; both hooks are no-ops when unset. Happy to add an entry for the new config keys on their own if you think they warrant one.
Dropped it. You were right to push — I'd framed the affected users as a dashboard-RBAC edge case, but the chart branch is if chart.viewers: if is_viewer(chart): return with an elif for the dataset check, so the dataset check isn't consulted at all when a chart has explicit viewers. Chart viewers without a dataset grant open Explore today by design; that's chart-level sharing working, not a configuration quirk. |
msyavuz
left a comment
There was a problem hiding this comment.
- The PR title still says "require dataset access for Explore", but that change was dropped. Should the title change before merge, and should the new
EXTRA_ACCESS_QUERY_EXCLUSIONSkey get an UPDATING.md entry?
| return None | ||
|
|
||
| excluded = hook(user_id) | ||
| excluded_id = list(excluded.c)[0] |
There was a problem hiding this comment.
list(excluded.c)[0] only works when the hook returns a .subquery(), but ExclusionSpec/ExclusionEntry type the hook as Callable[[int], Query], and the existing EXTRA_ACCESS_QUERY_FILTERS hooks get passed to .in_(), which takes a Query or a select. So a hook that returns a plain Query or select() raises AttributeError in ChartFilter/DashboardAccessFilter, and that breaks every chart or dashboard list for every user, admins included. Either normalise the return value (e.g. call .subquery() when it's missing) or fix the type and docs.
There was a problem hiding this comment.
Agreed — a hook returning the advertised Query would raise AttributeError in ChartFilter.
| # otherwise be accepted. Ask the report-target question here, where | ||
| # the id is actually resolved. | ||
| exclusion_kind = f"report_target_{kind}s" | ||
| if is_excluded_by_extra_access(exclusion_kind, object_id): |
There was a problem hiding this comment.
This new 403 on report POST/PUT is the actual authorisation boundary from the earlier review thread, but the only test (is_excluded_by_extra_access in isolation) never goes through _check_object_access. A regression in the f"report_target_{kind}s" key mapping or the raise would not be caught.
There was a problem hiding this comment.
Fair — the helper was tested but not the path through it. Added two tests on _check_object_access: one asserting the refusal, the reason reaching the caller, and the derived key string
CodeAnt PR Risk: Low Risk
Assessed commit: |
| # id branch below through that filter -- would not apply here, and | ||
| # the same dashboard would be absent by id while readable by uuid. | ||
| # Withheld means withheld whichever identifier names it. | ||
| if dashboard and is_excluded_by_extra_access("dashboards", dashboard.id): |
There was a problem hiding this comment.
is_excluded_by_extra_access has no guest check, so an embedded guest who fetches a dashboard by UUID gets a 404 for a dashboard their token grants, even though DashboardAccessFilter (and the docs) exempt guests from exclusions.
There was a problem hiding this comment.
Good catch, fixed it
…andrusoare/fix/folder-access-exclusions
| else ("dashboard", effective_dashboard) | ||
| ) | ||
| target_id = getattr(effective_id, "id", effective_id) | ||
| if isinstance(target_id, int) and is_excluded_by_extra_access( |
There was a problem hiding this comment.
This check also runs when the update only sets active: false. If a report's dashboard or chart is later withheld via report_target_*, its owner's pause request (PUT /api/v1/report/<id> with {"active": false}) now returns 403, while the scheduler keeps selecting the active report and delivering it. The check is also keyed only on report_target_*, so with just charts/dashboards configured, {"active": true} on a report whose stored chart was withheld is accepted, while resubmitting {"chart": <id>} is refused. Should deactivation-only updates skip this check, and should the stored target ask the same questions as a submitted one?
| # id branch below through that filter -- would not apply here, and | ||
| # the same dashboard would be absent by id while readable by uuid. | ||
| # Withheld means withheld whichever identifier names it. | ||
| if dashboard and is_excluded_by_extra_access("dashboards", dashboard.id): |
There was a problem hiding this comment.
This makes the uuid read agree with the id read, but other direct reads of the same assets still skip the exclusion. /superset/dashboard/<id_or_slug>/ resolves through Dashboard.get() plus raise_for_access(), so a withheld dashboard still returns a 200 page with its title and description. For charts, /api/v1/explore/?slice_id=<id> loads the Slice through get_form_data, gated only by can_access_chart, so a chart that /api/v1/chart/<id> 404s still returns its saved form data. Is "withheld" meant to cover those reads, or only lists, exports, pickers and the REST detail endpoints? If it is the narrower contract, should the docs and this comment say so?
| # The ordinary "charts" key must not be what narrows a report target list. | ||
| assert mock_exclusions.call_args.args[1] == "report_target_charts" | ||
| # ...and the parent's rules still run, on the narrowed query. | ||
| mock_parent.assert_called_once_with(query, None) |
There was a problem hiding this comment.
Both picker tests have the exclusion helper return the same query object they pass in, then assert the parent apply receives that object. If ReportTargetChartFilter.apply stopped using the helper's result (say, the query = ... assignment was dropped), both tests would still pass while excluded targets reappear in the related-field picker. Could the mock return a distinct sentinel and the assertion check that the parent receives it, for the dashboard variant too?
There was a problem hiding this comment.
Not approving over this. sadpandajoe found 9 separate access-control gaps here, several of them real authorization bypasses (the NOT IN against a hook subquery with a possible NULL is a textbook SQL gotcha, that one's unambiguously real: three-valued logic makes the whole NOT IN evaluate to unknown/false for every row the moment one NULL shows up, silently exposing or hiding everything rather than just the excluded ids). Several others describe the exclusion only narrowing UI pickers while the actual API/command path still allows direct access to an excluded asset, which is exactly the kind of boundary that matters for this feature's whole purpose.
msyavuz's approval looks like it landed before sadpandajoe's last two rounds of findings (15:12 and 15:36, after the 13:26 approval). Worth a fresh look once those are addressed rather than relying on the existing approval. Not duplicating the line-by-line pass, just flagging this isn't in a mergeable state yet.
…andrusoare/fix/folder-access-exclusions
| # ordinary access filter, so an excluded id posted directly would | ||
| # otherwise be accepted. Ask the report-target question here, where | ||
| # the id is actually resolved. | ||
| if is_excluded_by_extra_access(f"report_target_{kind}s", object_id): |
There was a problem hiding this comment.
This check raises even when the update sets active: false. The report edit modal resends the stored chart/dashboard id with every save, so an owner who pauses a report on a withheld target from that modal still gets a 403, and the pause exemption in _check_stored_target_access only helps callers that send {"active": false} alone.
There was a problem hiding this comment.
Confirmed, and thanks — you're right about the modal. The list page's toggle sends {"active": false} on its own so it reached the exemption, but the modal always resends the stored target, which takes the submitted-target branch instead.
SUMMARY
A deployment with its own notion of a withheld asset has no way to keep it out of
a chart or dashboard list, an export, or a related-field picker.
EXTRA_ACCESS_QUERY_FILTERScan only widen a result set — its conditions are OR'dinto
ChartFilterandDashboardAccessFilter— so there is no subtractive half.EXTRA_ACCESS_QUERY_EXCLUSIONSadds one. A hook names asset ids; those ids arewithheld. No behaviour change when it is unset, which is the default.
Two placement decisions carry the behaviour:
is_admin()/can_access_all_datasources()short-circuits, since those are the principals the role paths stop narrowing.
already scopes its holder and fails closed.
Implemented as
NOT EXISTSrather thanNOT IN, which is NULL-safe.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TESTING INSTRUCTIONS
ADDITIONAL INFORMATION