You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ri...@apache.org on 2026/09/17 11:47:17 UTC

(superset) branch master updated: fix(dashboard): require published for the read-gate's datasource fallback (#44093)

This is an automated email from the ASF dual-hosted git repository.

richardfogaca pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 2ef8e0c1dee fix(dashboard): require published for the read-gate's datasource fallback (#44093)
2ef8e0c1dee is described below

commit 2ef8e0c1dee94d371d395efe71b5f1cac9ff8d1c
Author: Mike Bridge <mi...@preset.io>
AuthorDate: Thu Sep 17 05:47:10 2026 -0600

    fix(dashboard): require published for the read-gate's datasource fallback (#44093)
    
    Co-authored-by: Claude Fable 5 <no...@anthropic.com>
    Co-authored-by: Mike Bridge <mi...@ext.preset.io>
---
 UPDATING.md                                        |  13 ++
 superset/security/manager.py                       |  39 ++++--
 .../dashboards/semantic_view_access_test.py        |  80 ++++++++++-
 .../subjects/test_report_executor_remediation.py   | 148 +++++++++++++++++++++
 4 files changed, 266 insertions(+), 14 deletions(-)

diff --git a/UPDATING.md b/UPDATING.md
index 5c954f505db..d3db7fa212e 100644
--- a/UPDATING.md
+++ b/UPDATING.md
@@ -98,6 +98,19 @@ Resample projections remain capped by `MAX_RESAMPLE_ROWS` (default
 year, …) that previously skipped the check because they have no fixed
 `Timedelta`.
 
+### Dashboard read fallback requires a published dashboard
+
+The object-read gate's datasource-based fallback — including the admit for dashboards with no charts — now applies to **published** dashboards only. For the datasource branch this matches the list filter's fallback, which was already published-only; for the no-charts admit the list filter still never yields chart-less dashboards to ordinary users, a deliberate pre-existing asymmetry that this change narrows but does not remove (the object gate admits opening a published chart-less dashbo [...]
+
+Everything consuming the gate inherits the tightening — including **alert and report execution**, not only schedule creation/validation. An already-scheduled report against an *unpublished, no-viewers* dashboard whose execution principal is a datasource-entitled non-editor will fail on its next run after upgrade.
+
+Before upgrading, audit report schedules targeting unpublished dashboards. For each one, first identify the principal the report actually runs as: that is decided by `ALERT_REPORTS_EXECUTORS`, not by who owns the schedule. Then apply one of:
+
+- **Publish the dashboard** (and confirm the execution principal keeps the read access the gate still requires — viewer membership when the dashboard has viewers, or access to a member datasource when it does not). For the unpublished, no-viewers, datasource-entitled case above, publishing alone supplies the missing prerequisite.
+- **Grant the execution principal dashboard editorship**, where that privilege is appropriate — editors are admitted ahead of the fallback regardless of published state.
+
+Adding the principal to the dashboard's **viewers is not a remedy on its own**: the viewer branch is itself published-gated, so a viewer of an unpublished dashboard is still refused. Re-owning the schedule is not a reliable substitute either — with a `FixedExecutor` (a service or selenium account) the resolved user does not follow schedule ownership at all, and the ownership-sensitive executor types have their own creator/modifier/editor selection rules.
+
 ### Tagging is on by default
 
 `TAGGING_SYSTEM` now ships **on**. The Tags menu entry, the tag columns and
diff --git a/superset/security/manager.py b/superset/security/manager.py
index 1a52e4a7ce8..52c53ea82b6 100644
--- a/superset/security/manager.py
+++ b/superset/security/manager.py
@@ -5044,17 +5044,30 @@ class SupersetSecurityManager(  # pylint: disable=too-many-public-methods
                 if dashboard.published and self.is_viewer(dashboard):
                     return
             else:
-                # Datasource-based fallback. Member chart datasources are
-                # resolved across datasource types via
-                # ``Slice.resolved_datasource`` — ``Dashboard.datasources``
-                # only ever contains SqlaTable-backed datasources, so an
-                # unqualified emptiness check would grant every authenticated
-                # user access to a dashboard composed solely of, e.g.,
-                # semantic-view charts. A dashboard with no charts remains
-                # accessible; a chart whose datasource cannot be resolved
-                # counts as inaccessible, never as absent. Resolution is
-                # lazy and deduplicated per (type, id) so the first
-                # accessible datasource short-circuits the remaining lookups.
+                # Datasource-based fallback, published dashboards only —
+                # matching the list filter's fallback branch
+                # (superset/dashboards/filters.py), so an unpublished
+                # dashboard excluded by the fallback is not readable by
+                # direct URL (published chart-less dashboards stay directly
+                # readable while absent from lists — that asymmetry is
+                # intentional), and emptying
+                # the viewers list can no longer WIDEN access (the viewer
+                # branch above is published-gated; a fallback with no
+                # published gate would otherwise take over). Editors —
+                # owners are folded into editors by the subjects model —
+                # and resolver-granted editors are admitted above
+                # regardless of published, so no authoring flow changes.
+                #
+                # Member chart datasources are resolved across datasource
+                # types via ``Slice.resolved_datasource`` —
+                # ``Dashboard.datasources`` only ever contains
+                # SqlaTable-backed datasources, so an unqualified emptiness
+                # check would grant every authenticated user access to a
+                # dashboard composed solely of, e.g., semantic-view charts.
+                # A PUBLISHED dashboard with no charts remains accessible
+                # (chart-less dashboards can still carry markdown content);
+                # a chart whose datasource cannot be resolved counts as
+                # inaccessible, never as absent.
                 member_slices = dashboard.slices
 
                 def member_datasource_accessible() -> bool:
@@ -5071,7 +5084,9 @@ class SupersetSecurityManager(  # pylint: disable=too-many-public-methods
                             return True
                     return False
 
-                if not member_slices or member_datasource_accessible():
+                if dashboard.published and (
+                    not member_slices or member_datasource_accessible()
+                ):
                     return
 
             raise SupersetSecurityException(
diff --git a/tests/unit_tests/dashboards/semantic_view_access_test.py b/tests/unit_tests/dashboards/semantic_view_access_test.py
index 909d1f31f20..b2fe40b84d3 100644
--- a/tests/unit_tests/dashboards/semantic_view_access_test.py
+++ b/tests/unit_tests/dashboards/semantic_view_access_test.py
@@ -36,12 +36,15 @@ from __future__ import annotations
 import uuid as uuid_lib
 from contextlib import contextmanager, ExitStack
 from types import SimpleNamespace
-from typing import Iterator
+from typing import Iterator, TYPE_CHECKING
 from unittest.mock import MagicMock, patch
 
 import pytest
 from sqlalchemy.orm.session import Session
 
+if TYPE_CHECKING:
+    from superset.security.manager import SupersetSecurityManager
+
 VIEW_PERM = "[test_layer].[test_view](id:1)"
 VIEW2_PERM = "[test_layer].[test_view_2](id:2)"
 TABLE_PERM = "[examples].[birth_names](id:1)"
@@ -429,12 +432,85 @@ def test_gate_denies_dashboard_of_unresolvable_datasources(
 def test_gate_still_allows_empty_dashboard(
     access_fixtures: SimpleNamespace, app_context: None
 ) -> None:
-    """A dashboard with no charts stays accessible (pinned behaviour)."""
+    """A PUBLISHED dashboard with no charts stays accessible.
+
+    Chart-less dashboards can still carry markdown content, and published
+    is the signal that content is meant to be shared; the fixture is
+    published, so this pins the fallback's allow half (sc-120032)."""
     sm = _gate_sm()
     with _gate_patches(sm, granted_perms=set()):
         sm.raise_for_access(dashboard=access_fixtures.empty_dashboard)
 
 
+def test_gate_denies_unpublished_empty_dashboard(
+    access_fixtures: SimpleNamespace, app_context: None
+) -> None:
+    """sc-120032: an UNPUBLISHED chart-less dashboard is editor-only.
+
+    Previously any authenticated user could read it by URL even though it
+    appeared in no list (the list filter's fallback was already
+    published-only); markdown-only dashboards made that a content leak."""
+    # pylint: disable=import-outside-toplevel
+    from superset.exceptions import SupersetSecurityException
+    from superset.models.dashboard import Dashboard
+
+    unpublished_empty: Dashboard = Dashboard(
+        dashboard_title="unpublished empty",
+        slug="unpublished-empty",
+        published=False,
+        slices=[],
+    )
+    access_fixtures.session.add(unpublished_empty)
+    access_fixtures.session.flush()
+
+    sm: SupersetSecurityManager = _gate_sm()
+    with (
+        _gate_patches(sm, granted_perms=set()),
+        pytest.raises(SupersetSecurityException),
+    ):
+        sm.raise_for_access(dashboard=unpublished_empty)
+
+
+def test_gate_allows_published_table_dashboard_for_entitled_user(
+    access_fixtures: SimpleNamespace, app_context: None
+) -> None:
+    """Publication admits a datasource-entitled reader with no viewer subjects."""
+    sm: SupersetSecurityManager = _gate_sm()
+    with _gate_patches(sm, granted_perms={TABLE_PERM}):
+        sm.raise_for_access(dashboard=access_fixtures.regular_dashboard)
+
+
+def test_gate_denies_unpublished_dashboard_despite_datasource_grant(
+    access_fixtures: SimpleNamespace, app_context: None
+) -> None:
+    """sc-120031: an unpublished no-viewers dashboard denies datasource holders.
+
+    With viewers empty, a datasource-entitled non-editor used to be
+    admitted to an UNPUBLISHED dashboard through the fallback — so
+    removing the last viewer subject silently WIDENED access (the viewer
+    branch is published-gated but the fallback was not). The fallback now
+    requires published, matching the list filter's fallback branch."""
+    # pylint: disable=import-outside-toplevel
+    from superset.exceptions import SupersetSecurityException
+    from superset.models.dashboard import Dashboard
+
+    unpublished_regular: Dashboard = Dashboard(
+        dashboard_title="unpublished regular",
+        slug="unpublished-regular",
+        published=False,
+        slices=[access_fixtures.table_slice],
+    )
+    access_fixtures.session.add(unpublished_regular)
+    access_fixtures.session.flush()
+
+    sm: SupersetSecurityManager = _gate_sm()
+    with (
+        _gate_patches(sm, granted_perms={TABLE_PERM}),
+        pytest.raises(SupersetSecurityException),
+    ):
+        sm.raise_for_access(dashboard=unpublished_regular)
+
+
 def test_gate_denies_dashboard_with_datasource_less_chart(
     access_fixtures: SimpleNamespace, app_context: None
 ) -> None:
diff --git a/tests/unit_tests/subjects/test_report_executor_remediation.py b/tests/unit_tests/subjects/test_report_executor_remediation.py
new file mode 100644
index 00000000000..305aeafd829
--- /dev/null
+++ b/tests/unit_tests/subjects/test_report_executor_remediation.py
@@ -0,0 +1,148 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""sc-120031: the UPGRADING remediation for reports must actually work.
+
+The published-dashboard tightening makes an already-scheduled report
+against an unpublished dashboard fail on its next run, so UPDATING.md
+tells operators how to fix it. Richard Fogaça's review found the advice
+wrong: adding the execution principal as a *viewer* does not restore
+access (the viewer branch is itself published-gated), and re-owning the
+schedule does not necessarily change who the report runs as. These pins
+hold the corrected guidance to its claims — each test names the bullet
+it protects, so a future edit that reintroduces bad advice fails here.
+"""
+
+from typing import TYPE_CHECKING
+from unittest.mock import MagicMock, patch
+
+import pytest
+
+from superset.exceptions import SupersetSecurityException
+from superset.tasks.types import ExecutorType, FixedExecutor
+from superset.tasks.utils import get_executor
+
+if TYPE_CHECKING:
+    from superset.security.manager import SupersetSecurityManager
+
+
+def _make_sm() -> "SupersetSecurityManager":
+    """Build only the manager shell needed by the patched access gate."""
+    # Avoid app-init regression: the manager imports the model registry;
+    # resolve it after the app_context fixture initializes the application.
+    # pylint: disable=import-outside-toplevel
+    from superset.security.manager import SupersetSecurityManager
+
+    return SupersetSecurityManager.__new__(SupersetSecurityManager)
+
+
+def _make_dashboard(*, published: bool, has_viewers: bool) -> MagicMock:
+    dashboard: MagicMock = MagicMock()
+    dashboard.published = published
+    dashboard.viewers = [MagicMock()] if has_viewers else []
+    dashboard.slices = []
+    return dashboard
+
+
+def _gate(
+    sm: "SupersetSecurityManager",
+    dashboard: MagicMock,
+    *,
+    is_viewer: bool,
+    is_editor: bool,
+) -> None:
+    """Run the object-read gate as a non-admin, non-guest principal."""
+    with (
+        patch.object(sm, "is_admin", return_value=False),
+        patch.object(sm, "is_editor", return_value=is_editor),
+        patch.object(sm, "is_viewer", return_value=is_viewer),
+        patch.object(sm, "is_guest_user", return_value=False),
+        patch.object(sm, "get_dashboard_access_error_object", return_value=MagicMock()),
+    ):
+        sm.raise_for_access(dashboard=dashboard)
+
+
+def test_viewer_membership_alone_does_not_unblock_an_unpublished_dashboard(
+    app_context: None,
+) -> None:
+    """The REJECTED remedy: adding the executor as a viewer.
+
+    UPDATING.md must not offer this for an unpublished dashboard — the
+    viewer branch requires publication too, so the report keeps failing.
+    """
+    sm: "SupersetSecurityManager" = _make_sm()
+    dashboard: MagicMock = _make_dashboard(published=False, has_viewers=True)
+
+    with pytest.raises(SupersetSecurityException):
+        _gate(sm, dashboard, is_viewer=True, is_editor=False)
+
+
+def test_publishing_unblocks_the_viewer_execution_principal(
+    app_context: None,
+) -> None:
+    """Documented remedy 1: publish, with the principal's read access intact."""
+    sm: "SupersetSecurityManager" = _make_sm()
+    dashboard: MagicMock = _make_dashboard(published=True, has_viewers=True)
+
+    _gate(sm, dashboard, is_viewer=True, is_editor=False)
+
+
+def test_editorship_unblocks_regardless_of_published_state(
+    app_context: None,
+) -> None:
+    """Documented remedy 2: grant the principal dashboard editorship.
+
+    Editors are admitted ahead of both the viewer branch and the
+    datasource fallback, so this works while the dashboard stays
+    unpublished.
+    """
+    sm: "SupersetSecurityManager" = _make_sm()
+    dashboard: MagicMock = _make_dashboard(published=False, has_viewers=True)
+
+    _gate(sm, dashboard, is_viewer=False, is_editor=True)
+
+
+def test_fixed_executor_ignores_schedule_ownership() -> None:
+    """The REJECTED remedy: re-owning the schedule.
+
+    With a FixedExecutor configured the resolved principal is the
+    configured account, whatever the schedule's owners or editors say —
+    so "re-own the schedule to a dashboard editor" cannot be offered as
+    a general fix.
+    """
+    report: MagicMock = MagicMock()
+    report.created_by = MagicMock(username="original_owner")
+    report.changed_by = MagicMock(username="original_owner")
+
+    executor_type: ExecutorType
+    username: str
+    executor_type, username = get_executor(
+        executors=[FixedExecutor("reports_service_account")],
+        model=report,
+    )
+    assert executor_type == ExecutorType.FIXED_USER
+    assert username == "reports_service_account"
+
+    # Hand the schedule to a different owner/modifier entirely: the
+    # resolved execution principal does not move.
+    report.created_by = MagicMock(username="dashboard_editor")
+    report.changed_by = MagicMock(username="dashboard_editor")
+    username_after: str
+    _, username_after = get_executor(
+        executors=[FixedExecutor("reports_service_account")],
+        model=report,
+    )
+    assert username_after == "reports_service_account"