Repository navigation
fix(api): enforce is_managed_externally on chart/dashboard/dataset update - #44025
richardfogaca merged 10 commits into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #44025 +/- ##
=======================================
Coverage 80.25% 80.25%
=======================================
Files 2927 2927
Lines 173166 173198 +32
Branches 40156 40161 +5
=======================================
+ Hits 138973 139001 +28
- Misses 31600 31603 +3
- Partials 2593 2594 +1
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:
|
51fa53a to
3c37f08
Compare
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
@aminghadersohi — requesting review on the Shape: one shared
Remaining direct DAO writers (MCP tools, certification paths) are inventoried in a follow-up ticket rather than folded in. Tests: 15 unit (parametrized across the three entities; reverting the production change flips 7) + 2 integration (REST PUT 403 + legacy overwrite 403, both asserting the body). CI fully green at cf2f4cb including the DB matrix, unit lane, and openapi-spec-drift (the two commits after f7d40c0 are test-only: mock-fixture flag pins and a docstring nit). 🤖 Generated with Claude Code |
- The comment and test docstring cited UpdateDashboardCommand's raise_if_managed_externally gate as existing shared code; that gate is proposed in the open apache#44025 — reworded intent-shaped (the in-tree dashboard command layer has no managed-externally check at all, which makes the tool-local refusal MORE necessary, not less). - The gate now sits below the no-field inspect branch: reading current certification values changes nothing and stays available on managed dashboards (they are readable via get_dashboard_info anyway), pinned by a new test. - DashboardMutationErrorFields.permission_denied description widened to cover object-state refusals, so agents don't steer users toward requesting edit rights that would not help. sc-120051 Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JRLEJS4mUqKBoPjSjviKUW
Cross-model round folds: the denial test is parametrized across BOTH badge fields and both set and clear (gating one field but not the other can no longer pass), the inspect test pins certification_details preservation and changed_fields == [], the apache#44025 references are replaced with the durable invariant (direct assign+commit means no command-layer check can protect this tool), and the added result locals are annotated CallToolResult. sc-120051 Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JRLEJS4mUqKBoPjSjviKUW
Code Review Agent Run #d09baeActionable Suggestions - 0Additional Suggestions - 4
Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
…date
An entity with is_managed_externally set has its source of truth outside
Superset; the browser hides the edit affordances, but the refusal was
browser-only — an otherwise-authorized editor could mutate the entity via
PUT /api/v1/{chart,dashboard,dataset}/<id> directly and have the change
overwritten on the next external sync. This is the update-path counterpart
of the matching gate apache#44013 adds to version restore.
Add a shared raise_if_managed_externally helper (commands/utils.py) and
call it from all three UpdateCommand.validate() implementations, after the
editorship check, raising each entity's editorship-denial exception so the
403 response body is identical to a permission denial and discloses
nothing new. Two derived-state save paths are deliberately exempt: the
chart query-context-only save (report workers) and the dashboard
colors-sync command (fired in the background while a dashboard is merely
viewed).
sc-120011
Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JRLEJS4mUqKBoPjSjviKUW
Rework from the adversarial review round: the two 'derived state' exemptions were both live integrity holes, and two adjacent surfaces were unguarded. - The chart query-context-only save is now gated too: stored query context is executable state (report execution loads and runs it), so a client-supplied context on a managed chart is a behavior change, not derived state. No server-side path writes it (Explore's background save is the only writer and ignores the 403). - The dashboard colors exemption is narrowed to derived values only: color_scheme and label_colors are authoritative content persisted into exported json_metadata, so a payload that would change them on a managed dashboard is refused; the derived keys (color_scheme_domain, shared_label_colors, map_label_colors) keep flowing so background colors sync still works. The colors command now dispatches through its own validate() override rather than calling the parent directly. - PUT /api/v1/dataset/<pk>/refresh is gated after editorship: refresh persists fetched column metadata, which the external sync owns. - The ordinary PUT schemas discard is_managed_externally on load: it was client-writable, and with the gate a client-set true would have been irreversible via the API. Discarded (pre_load) rather than removed so clients echoing GET payloads back do not start failing on an unknown field. Direct DAO/model write surfaces that bypass the command layer (MCP tools, legacy Explore overwrite) are tracked separately as a follow-up. sc-120011 Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JRLEJS4mUqKBoPjSjviKUW
…ract Committer re-run findings on the managed-externally gate: - The legacy Explore save (/superset/explore/, action=overwrite) assigns request values (params, query_context, ...) directly to the loaded chart and persists via ChartDAO.update, bypassing UpdateChartCommand's gate — so an editor could still rewrite a managed chart's query context there. Refuse it after the editorship check with the same 403 message, pinned by a regression test that asserts the refusal message (a 403 from an unrelated check cannot satisfy it). The remaining direct DAO writers are tracked separately. - Removing is_managed_externally from the PUT schemas broke the published OpenAPI contract (spec-drift CI red). The field declarations are restored; the pre_load discard still runs first, so the key can never reach the loaded payload — declared for the contract, inert on load. Test updated to pin declared-but-discarded. - Stale comment referencing the removed chart query-context exemption dropped; UPDATING.md covers the legacy-overwrite gate. sc-120011 Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JRLEJS4mUqKBoPjSjviKUW
sc-120011 Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JRLEJS4mUqKBoPjSjviKUW
The new managed-externally gate (and the pre-existing editorship denial
directly above it, which shares the pattern) passed flask-babel's
lazy_gettext proxy to json_error_response, whose isinstance(str) check a
LazyString fails — so the 403 body degraded to {} and the regression
test's message assert failed on the CI Postgres/MySQL/SQLite lanes (the
only failure on both). Use the module's eager gettext alias so the denial
actually carries its message. Verified by a local probe with the
datasource check mocked: the body now reads
{"error": "You don't have the rights to alter this chart"}.
sc-120011
Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JRLEJS4mUqKBoPjSjviKUW
The new managed-externally gates read entity.is_managed_externally in UpdateChartCommand / UpdateDatasetCommand / RefreshDatasetCommand validate(); the pre-existing unit suites for those commands build their entities as bare MagicMocks, whose auto-created attribute is truthy, so 35 tests started failing with the 403 refusal on the CI unit-tests lane. Declare the flag False on the entity mocks — these tests model ordinary, locally-managed entities. (The dashboard suite already passed: its entity fixtures don't trip the gate.) sc-120011 Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JRLEJS4mUqKBoPjSjviKUW
cf2f4cb to
8a32575
Compare
|
The flagged issue is correct. In To resolve this, you should check if the key is present in Here is a corrected version of def _changes_authoritative_colors(self) -> bool:
assert self._model
metadata = json.loads(self._model.json_metadata or "{}")
for key in self._AUTHORITATIVE_COLOR_KEYS:
if key in self._properties:
# Check if the value is actually changing
if self._properties[key] != metadata.get(key):
return True
return FalseI have validated this fix against the provided diff. Would you like me to check the other comments on this PR and implement fixes for them as well? superset/commands/dashboard/update.py |
…s absent Bot finding on the colors gate, verified correct: an incoming color_scheme/label_colors of null compared equal to metadata.get(key)'s None default when the stored metadata lacked the key, slipping the managed-externally refusal — yet the DAO writes every provided key, so the exported json_metadata would gain a literal null entry, a real change. Compare against a sentinel default instead, and pin the absent-vs-null case for both authoritative keys. sc-120011 Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JRLEJS4mUqKBoPjSjviKUW
|
The codeant/bito finding on 🤖 Generated with Claude Code |
Code Review Agent Run #588cc4Actionable Suggestions - 0Additional Suggestions - 3
Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
fitzee
left a comment
There was a problem hiding this comment.
Adversarial review of the server-side is_managed_externally enforcement. The core gate (raise_if_managed_externally, placed after the editorship check in all three update commands + dataset refresh + legacy Explore overwrite), the 403-as-editorship-denial choice, and the pre_load discard of the client-writable flag are all sound. One correctness bug that defeats the PR's own colors-sync carve-out (#1), one likely-unintended breakage of a local-only field (#2), and three smaller items below. (Automated review; posted by a human reviewer.)
…gle; pin the sibling gates
Review round (fitzee):
- The colors gate now compares EFFECTIVE authoritative color state:
absent, explicit null, and empty ("" / {}) all encode "no colors".
The background sync always sends label_colors: {} while a dashboard
is merely viewed, so the previous byte-level sentinel comparison
403'd every view of a managed dashboard whose metadata lacked the
key — defeating the derived-colors carve-out in its most common
case. This deliberately supersedes the earlier
refuses-null-for-absent-key pin (an overcorrection): clearing a key
that HOLDS state and setting a value on an absent key both still
refuse (controls added).
- published-only updates pass the managed gate: the publish toggle is
Superset-local visibility state, not content owned by the external
source of truth; savePublished PUTs exactly {published}. Bundling
any content field re-arms the gate (control pinned).
- The native-filters and chart-customizations sibling commands'
inherited refusal of managed dashboards is now pinned as declared
behavior (edit-time content writes, unlike the view-time colors
sync).
- The thrice copy-pasted @pre_load is_managed_externally discard hook
is now a shared DiscardIsManagedExternallyMixin in
superset/utils/schema.py.
- UPDATING.md: blank line before the new heading (MD022).
Co-Authored-By: Claude Fable 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01JRLEJS4mUqKBoPjSjviKUW
Code Review Agent Run #2e4536Actionable Suggestions - 0Additional Suggestions - 1
Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
richardfogaca
left a comment
There was a problem hiding this comment.
Richard's agent here:
Reviewed f3c23dcfa9a0; no substantive findings. CI is green. Review was based on source and available test evidence; full local integration/browser validation was not performed.
UPDATING.md keeps both entries (master's version-history edit-gate note and this branch's externally-managed-update note). The views/core.py conflict was a placement artefact — master made no change there — so the legacy-overwrite is_managed_externally guard is retained as written. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01EA4MGEkUcDpyLReqjQBhPy
|
Bito Automatic Review Skipped – PR Already Merged |
apache#44025 landed the update-path is_managed_externally gate today and updated every test in this file that existed then. This branch's soft-deleted-twin test was written on a separate branch, so the two only met when master was merged in: its bare MagicMock returns a truthy attribute, the new gate reads that as externally managed, and the dataset is refused before the uniqueness guidance it exists to assert. Matches the pattern the other ten tests in this file already use. Control: with the stub removed the test fails with DatasetForbiddenError; restored, the file's 32 tests pass. Both states asserted by file content. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01EA4MGEkUcDpyLReqjQBhPy
…date (#44025) Co-authored-by: Claude Fable 5 <[email protected]> Co-authored-by: Mike Bridge <[email protected]> (cherry picked from commit 6cfb331)
SUMMARY
An entity with
is_managed_externally = Truehas its source of truth outside Superset: an in-app write would be overwritten on the next external sync, which is why the UI hides the edit affordances for such entities. But the refusal was browser-only — an otherwise-authorized editor could still mutate the entity by callingPUT /api/v1/{chart,dashboard,dataset}/<id>directly. This is the ordinary-update counterpart of the gap #44013 closes for version restore (in review), and landing both keeps the restore and update surfaces from drifting.Core change: a shared
raise_if_managed_externallyhelper insuperset/commands/utils.py, called from all threeUpdateCommand.validate()implementations after the editorship check, raising each entity's existing editorship-denial exception (ChartForbiddenError/DashboardForbiddenError/DatasetForbiddenError) so the HTTP 403 body is identical to a permission denial and discloses nothing new.Hardening from the adversarial review round (initially-proposed exemptions turned out to be bypasses):
query_contextis executable state — report execution loads and runs it — so a client-supplied context on a managed chart changes chart/report behavior; it is not derived state. No server-side path writes it: Explore's background context save is the only writer, and for a managed chart that fire-and-forget call receives a 403 it ignores.PUT /api/v1/dashboard/<id>/colorsfires in the background whenever an editor merely views a dashboard with stale color metadata, so it stays writable on managed dashboards — but only for the derived keys (color_scheme_domain,shared_label_colors,map_label_colors). A payload that would change the authoritativecolor_scheme/label_colors(persisted into exportedjson_metadata) is refused with the same 403. The colors command also dispatches through its ownvalidate()override (itsrun()previously called the parent's validate directly).PUT /api/v1/dataset/<pk>/refreshis gated after editorship: refresh persists fetched column metadata, which the external sync owns.is_managed_externallyon load. The field was client-writable, and with the gate in place a client-settruewould have been irreversible via the API (the stored flag is checked before any payload is applied). The field stays declared (preserving the published OpenAPI contract and generated clients) but a@pre_loadhook drops the key before field loading, so it can never reach the loaded payload — and clients echoing GET payloads back on PUT don't start failing on an unknown field./superset/explore/withaction=overwriteassigns request values (params,query_context, …) directly to the loaded chart and persists viaChartDAO.update, bypassing the command layer — refused after the editorship check with the same 403 message, pinned by a regression test that asserts the refusal message (a 403 from an unrelated check cannot satisfy it). En route this fixed a latent pre-existing bug: the overwrite editorship denial directly above passed a flask-babel LazyString tojson_error_response(whoseisinstance(str)check it fails), so that 403 has been shipping an empty{}body — both denials now use the eager gettext alias and carry their message.Scope note: this is a data-integrity consistency fix, not a privilege escalation — an editor holding edit rights is entitled to mutate these entities under the role/capability matrix;
is_managed_externallyis an external-sync integrity concern. Direct DAO/model write surfaces that bypass the command layer (MCP tools, legacy Explore overwrite) are inventoried in a separate follow-up.There is precedent for the check in this very layer:
UpdateChartCommandalready refuses linking a chart to an externally managed target dashboard.BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A — API-only behavior change. Before:
PUTon an externally managed entity returned 200 and mutated it. After: HTTP 403, entity unchanged.TESTING INSTRUCTIONS
pytest tests/unit_tests/commands/test_update_managed_externally.py— 15 tests: parametrized refusal across chart/dashboard/dataset (the singleraise_for_editorshipcall also pins that the gate runs after editorship); call-site wiring pins; the chart query-context-only refusal; colors derived-only exemption + parametrized authoritative-key refusals; the dataset refresh gate; the PUT schemas discarding the flag (no field, no 422, key absent after load); the helper contract. Reverting only the production changes flips 7 of the 15 (verified via stash control).tests/integration_tests/charts/api_tests.py::TestChartApi::test_update_chart_refuses_externally_managed— representative real-endpoint case: adminPUTon an externally managed chart returns 403 and the chart is unchanged (exception-safe cleanup).tests/integration_tests/core_tests.py::TestCore::test_overwrite_refuses_externally_managed_slice— the legacy Explore overwrite path:action=overwriteon a managed chart returns 403 with the refusal message and the chart (includingquery_context) is unchanged.is_managed_externallyon any chart, thenPUT /api/v1/chart/<id>with{"slice_name": "x"}as an admin → 403; flip it back → 200. On a managed dashboard,PUT /api/v1/dashboard/<id>/colorswith a changedcolor_scheme→ 403; with only derived keys → 200.ADDITIONAL INFORMATION
🤖 Generated with Claude Code
https://claude.ai/code/session_01JRLEJS4mUqKBoPjSjviKUW