Skip to content

feat(improvements): let deployments withhold assets from list queries and commands - #45451

Merged
alexandrusoare merged 10 commits into
masterfrom
alexandrusoare/fix/folder-access-exclusions
Oct 21, 2026
Merged

alexandrusoare merged 10 commits into
masterfrom
alexandrusoare/fix/folder-access-exclusions

Conversation

@alexandrusoare

@alexandrusoare alexandrusoare commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

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_FILTERS can only widen a result set — its conditions are OR'd
into ChartFilter and DashboardAccessFilter — so there is no subtractive half.

EXTRA_ACCESS_QUERY_EXCLUSIONS adds one. A hook names asset ids; those ids are
withheld. No behaviour change when it is unset, which is the default.

Two placement decisions carry the behaviour:

  • Applied before the is_admin() / can_access_all_datasources()
    short-circuits, since those are the principals the role paths stop narrowing.
  • Applied after the guest branch, leaving embedded guests alone: a guest token
    already scopes its holder and fails closed.

Implemented as NOT EXISTS rather than NOT IN, which is NULL-safe.

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

@github-actions github-actions Bot added the api Related to the REST API label Oct 19, 2026
@netlify

netlify Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit 6227331
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6ad883e564f88f33c34b0081
😎 Deploy Preview https://deploy-preview-45451--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@codecov

codecov Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.33333% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.06%. Comparing base (b6ef0bf) to head (cf5c590).
⚠️ Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
superset/commands/report/base.py 88.88% 1 Missing and 1 partial ⚠️
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     
Flag Coverage Δ
hive 34.91% <40.00%> (+<0.01%) ⬆️
mysql 52.88% <76.00%> (+0.01%) ⬆️
postgres 52.88% <76.00%> (+0.01%) ⬆️
presto 36.64% <52.00%> (+<0.01%) ⬆️
python 87.30% <96.00%> (+<0.01%) ⬆️
sqlite 52.64% <76.00%> (+0.01%) ⬆️
unit 81.56% <96.00%> (+0.01%) ⬆️

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

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@msyavuz
msyavuz self-requested a review October 20, 2026 08:55

@msyavuz msyavuz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

  • 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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Comment thread superset/utils/filters.py Outdated
if not user_id:
return query

return query.filter(id_column.notin_(hook(user_id)))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Comment thread superset/commands/explore/get.py Outdated
# 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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

@alexandrusoare

Copy link
Copy Markdown
Contributor Author
  • 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?

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 msyavuz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

  • 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_EXCLUSIONS key get an UPDATING.md entry?

Comment thread superset/utils/filters.py Outdated
return None

excluded = hook(user_id)
excluded_id = list(excluded.c)[0]

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed — a hook returning the advertised Query would raise AttributeError in ChartFilter.

Comment thread superset/commands/report/base.py Outdated
# 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):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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

Comment thread superset/utils/filters.py Resolved
@codeant-ai-for-open-source

codeant-ai-for-open-source Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

CodeAnt PR Risk: Low Risk

  • The PR appears safe to merge; exclusion hook results are normalized before their columns are read, handling ORM queries, selects, and subqueries.

Assessed commit: cf5c590aaafe

@alexandrusoare alexandrusoare changed the title feat(improvements): add EXTRA_ACCESS_QUERY_EXCLUSIONS and require dataset access for Explore feat(improvements): let deployments withhold assets from list queries and commands Oct 20, 2026
Comment thread superset/commands/report/base.py Resolved
Comment thread superset/utils/filters.py Resolved
Comment thread superset/dashboards/filters.py Resolved
Comment thread superset/charts/filters.py Resolved
@github-actions github-actions Bot added the doc Namespace | Anything related to documentation label Oct 20, 2026
# 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):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, fixed it

Comment thread superset/commands/report/base.py Resolved
Comment thread superset/charts/filters.py Resolved
Comment thread superset/commands/report/base.py Outdated
else ("dashboard", effective_dashboard)
)
target_id = getattr(effective_id, "id", effective_id)
if isinstance(target_id, int) and is_excluded_by_extra_access(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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?

@rusackas rusackas left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Comment thread superset/commands/report/base.py Outdated
# 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):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

@alexandrusoare
alexandrusoare merged commit 75be8f9 into master Oct 21, 2026
72 checks passed
@alexandrusoare
alexandrusoare deleted the alexandrusoare/fix/folder-access-exclusions branch October 21, 2026 11:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api Related to the REST API doc Namespace | Anything related to documentation size/XXL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants