You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "AmoghAtreya (via GitHub)" <gi...@apache.org> on 2026/10/04 20:01:12 UTC

[PR] fix(sqllab): let schema grants authorize SQL Lab again [superset]

AmoghAtreya opened a new pull request, #44968:
URL: https://github.com/apache/superset/pull/44968

   ### SUMMARY
   Fixes #44903. After #40409, SQL Lab required `datasource_access` on a registered dataset for every referenced table. A Gamma user with `sql_lab` plus `schema_access` and `catalog_access` could still browse the schema and open charts, but every SQL Lab query was denied. The error read as if those schema grants were missing, and there was no configuration to restore the previous behavior. Registering every table as a dataset does not scale for schemas where tables are added and renamed often, and `database_access` is broader than a single schema.
   
   `SQLLAB_REQUIRE_DATASET_MATCH` defaults to `True`, so the dataset-match requirement stays on unless an admin opts out. Set it to `False` to authorize SQL Lab from `schema_access` or `catalog_access` alone. That grant then covers every table in the schema, including tables that are not registered as datasets.
   
   The flag covers the SQL Lab paths that execute a query or return its rows:
   
   - query execution
   - result fetch
   - CSV and streaming export
   - cost estimates
   - SQL formatting
   - the MCP `execute_sql` tool
   
   Charts and Explore already honor `schema_access` and `catalog_access` and are unchanged. Reports, alerts, MetaDB, and SQL validation keep requiring a dataset match.
   
   When the requirement is left on, a denial names the dataset requirement. It says `schema_access` and `catalog_access` do not authorize the query, instead of reading as if those grants are absent.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   N/A. Backend permission check and configuration only.
   
   ### TESTING INSTRUCTIONS
   1. Use a database that supports catalogs, with "Allow changing catalogs" enabled. Create a non-admin user with the `sql_lab` role and only these data grants:
      - `catalog_access` on `[Database].[catalog]`
      - `schema_access` on `[Database].[catalog].[schema]`
      - no `database_access`
      - no per-table `datasource_access`
   2. Leave `SQLLAB_REQUIRE_DATASET_MATCH` unset (default `True`). In SQL Lab, run `SELECT * FROM schema.table LIMIT 100`. The query is denied. The error says a registered dataset with `datasource_access` is required, and that `schema_access` and `catalog_access` do not authorize the query.
   3. Set `SQLLAB_REQUIRE_DATASET_MATCH = False` in `superset_config.py` and restart. Run the same query. It succeeds.
   4. Set the flag back to `True`. Grant `datasource_access` on a registered dataset for that table and run the query again. It succeeds.
   5. With the flag at either value, open a chart or dashboard backed by a dataset in that schema. It still loads for a user who holds `schema_access`.
   
   ```bash
   pytest tests/unit_tests/sqllab/test_requires_dataset_match.py \
     tests/unit_tests/sqllab/api_test.py \
     tests/unit_tests/commands/sql_lab/test_estimate.py \
     tests/unit_tests/security/manager_test.py \
     -k "dataset_match or format_sql or catalog_self_reference"
   
   
   ### ADDITIONAL INFORMATION
   - [x] Has associated issue: Fixes #44903
   - [ ] Required feature flags:
   - [ ] Changes UI
   - [ ] Includes DB Migration (follow approval process in [SIP-59](https://github.com/apache/superset/issues/13351))
     - [ ] 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
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(sqllab): let schema grants authorize SQL Lab again [superset]

Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on code in PR #44968:
URL: https://github.com/apache/superset/pull/44968#discussion_r4179534858


##########
tests/unit_tests/sqllab/test_requires_dataset_match.py:
##########
@@ -0,0 +1,75 @@
+# 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.
+from __future__ import annotations
+
+from unittest.mock import patch
+
+from flask import current_app
+from pytest_mock import MockerFixture
+
+from superset.sqllab.utils import requires_dataset_match
+from superset.sqllab.validators import CanAccessQueryValidatorImpl
+
+
+def test_requires_dataset_match_defaults_to_true() -> None:
+    """A missing config key keeps the dataset-match requirement on."""
+    config = current_app.config
+    original = config.pop("SQLLAB_REQUIRE_DATASET_MATCH", None)
+    try:
+        assert requires_dataset_match() is True
+    finally:
+        if original is not None:
+            config["SQLLAB_REQUIRE_DATASET_MATCH"] = original
+
+
+def test_requires_dataset_match_reads_config() -> None:
+    with patch.dict(current_app.config, {"SQLLAB_REQUIRE_DATASET_MATCH": False}):
+        assert requires_dataset_match() is False
+    with patch.dict(current_app.config, {"SQLLAB_REQUIRE_DATASET_MATCH": True}):
+        assert requires_dataset_match() is True
+
+
+def test_execute_validator_follows_config(mocker: MockerFixture) -> None:
+    """SQL Lab execute uses the same flag as result fetch and export."""
+    raise_for_access = mocker.patch(
+        "superset.sqllab.validators.security_manager.raise_for_access"
+    )
+    query = mocker.MagicMock()
+
+    with patch.dict(current_app.config, {"SQLLAB_REQUIRE_DATASET_MATCH": False}):
+        CanAccessQueryValidatorImpl().validate(query, template_params={"a": 1})
+
+    raise_for_access.assert_called_once_with(
+        query=query,
+        template_params={"a": 1},
+        force_dataset_match=False,
+    )
+
+
+def test_query_raise_for_access_follows_config(mocker: MockerFixture) -> None:

Review Comment:
   <!-- Bito Reply -->
   The update is noted. Moving the import to the module level is consistent with the requested best practice, as it avoids unnecessary function-local imports when no circular dependency exists.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(sqllab): let schema grants authorize SQL Lab again [superset]

Posted by "rusackas (via GitHub) via notifications" <no...@superset.apache.org>.
rusackas commented on code in PR #44968:
URL: https://github.com/apache/superset/pull/44968#discussion_r4635490978


##########
superset/security/manager.py:
##########
@@ -5488,8 +5512,10 @@ def raise_for_access(  # noqa: C901
                 # Statements that rebind how unqualified table names resolve
                 # (``USE``, ``SET SCHEMA``, or a ``search_path`` change) make
                 # the qualification below diverge from what the engine uses at
-                # execution time, so reject them regardless of engine.
-                if force_dataset_match and parse_result.script.changes_default_schema():
+                # execution time. This is independent of dataset matching: a
+                # schema or catalog grant must not authorize a script that
+                # then switches the shared cursor to another schema.
+                if parse_result.script.changes_default_schema():

Review Comment:
   Glad this one is unconditional. The `has_unparseable_statement` check just above is still gated on `force_dataset_match` though, so with the flag off a statement sqlglot can't model (an `exp.Command`, or anything on a non-sqlglot engine like Kusto) yields no tables and nothing gets denied, right? That seems to let a `schema_access` grant reach past its schema the same way `USE` did.
   
   Same question for the `not table_.schema` deny and the editorship exclusion further down, which also relax when the flag is off. Should those stay enforced regardless, or at least get called out in the docs?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(sqllab): let schema grants authorize SQL Lab again [superset]

Posted by "AmoghAtreya (via GitHub)" <gi...@apache.org>.
AmoghAtreya commented on code in PR #44968:
URL: https://github.com/apache/superset/pull/44968#discussion_r4179549749


##########
superset/sqllab/validators.py:
##########
@@ -33,5 +34,5 @@ def validate(
         security_manager.raise_for_access(
             query=query,
             template_params=template_params,
-            force_dataset_match=True,
+            force_dataset_match=requires_dataset_match(),

Review Comment:
   Thanks for catching that error @sadpandajoe! Just resolved it in 5eb1aa0. The schema-rebinding check is no longer tied to dataset matching. With `SQLLAB_REQUIRE_DATASET_MATCH` off, a grant on `tenant_a` still allows `SELECT * FROM orders`, and `USE tenant_b; SELECT * FROM orders` is denied. The access check would otherwise qualify `orders` as `tenant_a.orders` while the shared cursor reads `tenant_b.orders`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(sqllab): let schema grants authorize SQL Lab again [superset]

Posted by "codeant-ai-for-open-source[bot] (via GitHub)" <gi...@apache.org>.
codeant-ai-for-open-source[bot] commented on code in PR #44968:
URL: https://github.com/apache/superset/pull/44968#discussion_r4179125259


##########
docs/admin_docs/security/security.mdx:
##########
@@ -61,6 +61,16 @@ Beyond the base `sql_lab` role, two additional SQL Lab permissions must be expli
 
 Grant these in **Security β†’ List Roles** by adding the permissions to the relevant role.
 
+Running a query also needs a data grant. By default (`SQLLAB_REQUIRE_DATASET_MATCH = True`), every table the SQL references must be a registered dataset the user has `datasource_access` on (or owns). `database_access` still authorizes the whole database. `schema_access` and `catalog_access` let the user browse that schema in SQL Lab and still authorize charts, but they do not authorize query execution.
+
+Set the following in `superset_config.py` when schema- or catalog-wide SQL Lab access is the intended control (for example, access is managed on the warehouse and tables change often):
+
+```python
+SQLLAB_REQUIRE_DATASET_MATCH = False
+```
+
+A `schema_access` or `catalog_access` grant then authorizes SQL Lab queries against every table in that schema, including tables that are not registered as datasets. The same flag covers result fetch, CSV and streaming export, cost estimates, SQL formatting, and the MCP `execute_sql` tool. Chart and Explore access are unchanged. Reports, alerts, MetaDB, and SQL validation still require a dataset match.

Review Comment:
   **Suggestion:** `catalog_access` is checked without a schema restriction, so it authorizes tables across the catalog; this sentence incorrectly narrows its scope to one schema.
   
   **Assessment:** 🟠 `Major` Β· πŸ” `Occurrence: Sometimes` Β· 🏷️ `Comment mismatch`
   
   [![Use CodeAnt Skill](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/use-codeant-skill-flat-v2.svg)](https://docs.codeant.ai/cli/resolve-pr-comments-skill) [![Fix in Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=6283dc15a75949818c45b0e79746db28&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [![Fix in VSCode Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=6283dc15a75949818c45b0e79746db28&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   <details>
   <summary><b>Prompt for AI Agent πŸ€– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** docs/admin_docs/security/security.mdx
   **Line:** 72:72
   **Comment:**
   	*Comment Mismatch: `catalog_access` is checked without a schema restriction, so it authorizes tables across the catalog; this sentence incorrectly narrows its scope to one schema.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44968&comment_hash=11a12f00bc003da81aabf932a4a7cea46234831cb93e21b69132046d6adecdef&reaction=like'>πŸ‘</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44968&comment_hash=11a12f00bc003da81aabf932a4a7cea46234831cb93e21b69132046d6adecdef&reaction=dislike'>πŸ‘Ž</a>



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(sqllab): let schema grants authorize SQL Lab again [superset]

Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #44968:
URL: https://github.com/apache/superset/pull/44968#issuecomment-5983849146

   AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(sqllab): let schema grants authorize SQL Lab again [superset]

Posted by "AmoghAtreya (via GitHub)" <gi...@apache.org>.
AmoghAtreya commented on code in PR #44968:
URL: https://github.com/apache/superset/pull/44968#discussion_r4179549749


##########
superset/sqllab/validators.py:
##########
@@ -33,5 +34,5 @@ def validate(
         security_manager.raise_for_access(
             query=query,
             template_params=template_params,
-            force_dataset_match=True,
+            force_dataset_match=requires_dataset_match(),

Review Comment:
   Thanks for catching that error @sadpandajoe! Just resolved it in the latest commit. The schema-rebinding check is no longer tied to dataset matching. With `SQLLAB_REQUIRE_DATASET_MATCH` off, a grant on `tenant_a` still allows `SELECT * FROM orders`, and `USE tenant_b; SELECT * FROM orders` is denied. The access check would otherwise qualify `orders` as `tenant_a.orders` while the shared cursor reads `tenant_b.orders`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(sqllab): let schema grants authorize SQL Lab again [superset]

Posted by "netlify[bot] (via GitHub)" <gi...@apache.org>.
netlify[bot] commented on PR #44968:
URL: https://github.com/apache/superset/pull/44968#issuecomment-5983867130

   ### <span aria-hidden="true">βœ…</span> Deploy Preview for *superset-docs-preview* ready!
   
   
   |  Name | Link |
   |:-:|------------------------|
   |<span aria-hidden="true">πŸ”¨</span> Latest commit | d11f470c8e65c4b811d39cb0048732b0d7d91cff |
   |<span aria-hidden="true">πŸ”</span> Latest deploy log | https://app.netlify.com/projects/superset-docs-preview/deploys/6ac2b0888af2550008a9057a |
   |<span aria-hidden="true">😎</span> Deploy Preview | [https://deploy-preview-44968--superset-docs-preview.netlify.app](https://deploy-preview-44968--superset-docs-preview.netlify.app) |
   |<span aria-hidden="true">πŸ“±</span> Preview on mobile | <details><summary> Toggle QR Code... </summary><br /><br />![QR Code](https://app.netlify.com/qr-code/eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1cmwiOiJodHRwczovL2RlcGxveS1wcmV2aWV3LTQ0OTY4LS1zdXBlcnNldC1kb2NzLXByZXZpZXcubmV0bGlmeS5hcHAifQ.b1ZmFLLHIPKFSGXxc8dafje838TCFnAmbhXaeg47WXo)<br /><br />_Use your smartphone camera to open QR code link._</details> |
   |<span aria-hidden="true">πŸ€–</span> Make changes | [Run an agent on this branch](https://app.netlify.com/projects/superset-docs-preview/agent-runs#DcpBCoAgEADAv-w5aREs6wc9Y92MAmtNDYro73mbw7wQk-yxwAjQgEt08Fq9bHebzxDIqcyr30kRs89ZSSxKrlLv7GOQZ5rr7oi1Q2stLdoYRLQ0oOkJvh8) |
   ---
   <!-- [superset-docs-preview Preview](https://deploy-preview-44968--superset-docs-preview.netlify.app) -->
   _To edit notification comments on pull requests, go to your [Netlify project configuration](https://app.netlify.com/projects/superset-docs-preview/configuration/notifications#deploy-notifications)._


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(sqllab): let schema grants authorize SQL Lab again [superset]

Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on code in PR #44968:
URL: https://github.com/apache/superset/pull/44968#discussion_r4180655380


##########
superset/mcp_service/sql_lab/tool/execute_sql.py:
##########
@@ -210,12 +248,17 @@ async def execute_sql(request: ExecuteSqlRequest, ctx: Context) -> ExecuteSqlRes
                 await ctx.error("Query could not be parsed for access validation")
                 return _invalid_sql_response()
 
+            rendered_sql = await _authorize_rendered_sql(

Review Comment:
   <!-- Bito Reply -->
   The reasoning provided is correct. The two authorization checks serve distinct purposes: the first acts as a gatekeeper to prevent the evaluation of live macros in unauthorized queries, while the second authorizes the specific rendered SQL that will be executed. Since these renders can involve different tables, maintaining both checks is necessary for security and functional correctness.
   
   **superset/mcp_service/sql_lab/tool/execute_sql.py**
   ```
   await ctx.error("Query could not be parsed for access validation")
                   return _invalid_sql_response()
    
   +            rendered_sql = await _authorize_rendered_sql(
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(sqllab): let schema grants authorize SQL Lab again [superset]

Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on code in PR #44968:
URL: https://github.com/apache/superset/pull/44968#discussion_r4179531502


##########
tests/unit_tests/sqllab/test_requires_dataset_match.py:
##########
@@ -0,0 +1,75 @@
+# 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.
+from __future__ import annotations
+
+from unittest.mock import patch
+
+from flask import current_app
+from pytest_mock import MockerFixture
+
+from superset.sqllab.utils import requires_dataset_match
+from superset.sqllab.validators import CanAccessQueryValidatorImpl
+
+
+def test_requires_dataset_match_defaults_to_true() -> None:
+    """A missing config key keeps the dataset-match requirement on."""
+    config = current_app.config
+    original = config.pop("SQLLAB_REQUIRE_DATASET_MATCH", None)
+    try:
+        assert requires_dataset_match() is True
+    finally:
+        if original is not None:
+            config["SQLLAB_REQUIRE_DATASET_MATCH"] = original
+
+
+def test_requires_dataset_match_reads_config() -> None:
+    with patch.dict(current_app.config, {"SQLLAB_REQUIRE_DATASET_MATCH": False}):
+        assert requires_dataset_match() is False
+    with patch.dict(current_app.config, {"SQLLAB_REQUIRE_DATASET_MATCH": True}):
+        assert requires_dataset_match() is True
+
+
+def test_execute_validator_follows_config(mocker: MockerFixture) -> None:
+    """SQL Lab execute uses the same flag as result fetch and export."""
+    raise_for_access = mocker.patch(
+        "superset.sqllab.validators.security_manager.raise_for_access"

Review Comment:
   <!-- Bito Reply -->
   The update to annotate `raise_for_access` as `MagicMock` in the test file is appropriate. This change addresses the requirement for explicit mock annotations, improving type safety and static analysis for the test code.
   
   **tests/unit_tests/sqllab/test_requires_dataset_match.py**
   ```
   raise_for_access: MagicMock = mocker.patch(
           "superset.sqllab.validators.security_manager.raise_for_access"
       )
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(sqllab): let schema grants authorize SQL Lab again [superset]

Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on code in PR #44968:
URL: https://github.com/apache/superset/pull/44968#discussion_r4179526759


##########
tests/unit_tests/sqllab/test_requires_dataset_match.py:
##########
@@ -0,0 +1,75 @@
+# 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.
+from __future__ import annotations
+
+from unittest.mock import patch
+
+from flask import current_app
+from pytest_mock import MockerFixture
+
+from superset.sqllab.utils import requires_dataset_match
+from superset.sqllab.validators import CanAccessQueryValidatorImpl
+
+
+def test_requires_dataset_match_defaults_to_true() -> None:
+    """A missing config key keeps the dataset-match requirement on."""
+    config = current_app.config
+    original = config.pop("SQLLAB_REQUIRE_DATASET_MATCH", None)
+    try:
+        assert requires_dataset_match() is True
+    finally:
+        if original is not None:
+            config["SQLLAB_REQUIRE_DATASET_MATCH"] = original
+
+
+def test_requires_dataset_match_reads_config() -> None:

Review Comment:
   <!-- Bito Reply -->
   The user has addressed the reviewer's suggestion by adding a docstring to `test_requires_dataset_match_reads_config` in `tests/unit_tests/sqllab/test_requires_dataset_match.py`. This update ensures consistency with the other test functions in the file, as requested.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(sqllab): let schema grants authorize SQL Lab again [superset]

Posted by "sadpandajoe (via GitHub)" <gi...@apache.org>.
sadpandajoe commented on code in PR #44968:
URL: https://github.com/apache/superset/pull/44968#discussion_r4179273388


##########
superset/sqllab/validators.py:
##########
@@ -33,5 +34,5 @@ def validate(
         security_manager.raise_for_access(
             query=query,
             template_params=template_params,
-            force_dataset_match=True,
+            force_dataset_match=requires_dataset_match(),

Review Comment:
   With this flag disabled, a user granted only `tenant_a` can submit `USE tenant_b; SELECT * FROM orders`: authorization checks `tenant_a.orders`, but the shared execution cursor reads `tenant_b.orders`. Could the schema-rebinding safeguard remain enforced independently of dataset matching, with a regression test that this out-of-grant query is denied when the flag is off?



##########
docs/admin_docs/security/security.mdx:
##########
@@ -61,6 +61,16 @@ Beyond the base `sql_lab` role, two additional SQL Lab permissions must be expli
 
 Grant these in **Security β†’ List Roles** by adding the permissions to the relevant role.
 
+Running a query also needs a data grant. By default (`SQLLAB_REQUIRE_DATASET_MATCH = True`), every table the SQL references must be a registered dataset the user has `datasource_access` on (or owns). `database_access` still authorizes the whole database. `schema_access` and `catalog_access` let the user browse that schema in SQL Lab and still authorize charts, but they do not authorize query execution.
+
+Set the following in `superset_config.py` when schema- or catalog-wide SQL Lab access is the intended control (for example, access is managed on the warehouse and tables change often):
+
+```python
+SQLLAB_REQUIRE_DATASET_MATCH = False
+```
+
+A `schema_access` or `catalog_access` grant then authorizes SQL Lab queries against every table in that schema, including tables that are not registered as datasets. The same flag covers result fetch, CSV and streaming export, cost estimates, SQL formatting, and the MCP `execute_sql` tool. Chart and Explore access are unchanged. Reports, alerts, MetaDB, and SQL validation still require a dataset match.

Review Comment:
   Agreedβ€”`catalog_access` permits tables across every schema in the granted catalog, so this understates the access an operator enables. Could the documentation distinguish catalog-wide access from a single-schema grant?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(sqllab): let schema grants authorize SQL Lab again [superset]

Posted by "codeant-ai-for-open-source[bot] (via GitHub)" <gi...@apache.org>.
codeant-ai-for-open-source[bot] commented on PR #44968:
URL: https://github.com/apache/superset/pull/44968#issuecomment-6309948295

   ## CodeAnt PR Risk: Low Risk
   
   - The PR appears safe to merge; the documentation now correctly distinguishes schema-wide from catalog-wide access.
   - Cost estimation and MCP execution authorize the rendered SQL before use, preventing a later template render from changing the checked tables.
   
   **Assessed commit:** `c7aa9f836af8`


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(sqllab): let schema grants authorize SQL Lab again [superset]

Posted by "AmoghAtreya (via GitHub)" <gi...@apache.org>.
AmoghAtreya commented on code in PR #44968:
URL: https://github.com/apache/superset/pull/44968#discussion_r4179522205


##########
superset/mcp_service/sql_lab/tool/execute_sql.py:
##########
@@ -182,17 +183,16 @@ async def execute_sql(request: ExecuteSqlRequest, ctx: Context) -> ExecuteSqlRes
 
             # Authorize through the same entry point as the SQL Lab
             # execution path (``superset/sqllab/validators.py``), so both
-            # surfaces scope a query the same way: it covers database-level
-            # access and, for a user without it, requires every table the
-            # query references to resolve to a dataset they are granted.
+            # surfaces scope a query the same way, including
+            # ``SQLLAB_REQUIRE_DATASET_MATCH``.
             try:
                 security_manager.raise_for_access(
                     database=database,
                     sql=request.sql,
                     catalog=request.catalog,
                     schema=request.schema_name,
                     template_params=template_params,
-                    force_dataset_match=True,
+                    force_dataset_match=requires_dataset_match(),

Review Comment:
   Fixed as well. The access check rendered the Jinja source once, and `database.execute` rendered it again, so a template that does not always produce the same SQL could run against a table the first check never saw. The tool now renders once with `process_template`, authorizes that exact SQL, and passes that same string to the destructive-SQL check and to `database.execute` with `template_params=None`, so it is not rendered again. If the second check fails, the query does not run.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(sqllab): let schema grants authorize SQL Lab again [superset]

Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #44968:
URL: https://github.com/apache/superset/pull/44968#issuecomment-5986329278

   AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
   
   <details>
   <summary>
   Bito Usage Guide
   </summary>
   
   **Commands**
         
   Type the following command in the pull request comment and save the comment.
         
   - `/review` - Manually triggers an incremental AI Review.
   - `/review full` - Manually triggers a full AI Review.
   
   - `/pause` - Pauses automatic reviews on this pull request.
   - `/resume` - Resumes automatic reviews.
   - `/resolve` - Marks all Bito-posted review comments as resolved.
   - `/abort` - Cancels all in-progress reviews.
   
         
   Refer to the <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/available-commands" target="_blank" rel="noopener noreferrer">documentation</a> for additional commands.
         
   **Configuration**
   
   This repository uses `Superset` You can customize the agent settings <a href="https://alpha.bito.ai/home/ai-agents/code-review-agent" target="_blank" rel="noopener noreferrer">here</a> or contact your Bito workspace admin at evan@preset.io.
         
   **Documentation & Help**
   - <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/getting-started/install-run-using-bito-cloud/create-or-customize-an-agent-instance" target="_blank" rel="noopener noreferrer">Customize agent settings</a>
   - <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/implementing-custom-code-review-rules" target="_blank" rel="noopener noreferrer">Review rules</a>
   - <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent" target="_blank" rel="noopener noreferrer">General documentation</a>
   - <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/faqs" target="_blank" rel="noopener noreferrer">FAQ</a>
   
   </details>
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(sqllab): let schema grants authorize SQL Lab again [superset]

Posted by "AmoghAtreya (via GitHub)" <gi...@apache.org>.
AmoghAtreya commented on code in PR #44968:
URL: https://github.com/apache/superset/pull/44968#discussion_r4179497161


##########
docs/admin_docs/security/security.mdx:
##########
@@ -61,6 +61,16 @@ Beyond the base `sql_lab` role, two additional SQL Lab permissions must be expli
 
 Grant these in **Security β†’ List Roles** by adding the permissions to the relevant role.
 
+Running a query also needs a data grant. By default (`SQLLAB_REQUIRE_DATASET_MATCH = True`), every table the SQL references must be a registered dataset the user has `datasource_access` on (or owns). `database_access` still authorizes the whole database. `schema_access` and `catalog_access` let the user browse that schema in SQL Lab and still authorize charts, but they do not authorize query execution.
+
+Set the following in `superset_config.py` when schema- or catalog-wide SQL Lab access is the intended control (for example, access is managed on the warehouse and tables change often):
+
+```python
+SQLLAB_REQUIRE_DATASET_MATCH = False
+```
+
+A `schema_access` or `catalog_access` grant then authorizes SQL Lab queries against every table in that schema, including tables that are not registered as datasets. The same flag covers result fetch, CSV and streaming export, cost estimates, SQL formatting, and the MCP `execute_sql` tool. Chart and Explore access are unchanged. Reports, alerts, MetaDB, and SQL validation still require a dataset match.

Review Comment:
   Fixed. `catalog_access` is checked only on the catalog, so with `SQLLAB_REQUIRE_DATASET_MATCH = False` it authorizes every table in that catalog, across schemas. `schema_access` is the grant limited to one schema. The security docs, configuration docs, SECURITY.md, UPDATING.md, and the config comment now say that separately.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(sqllab): let schema grants authorize SQL Lab again [superset]

Posted by "AmoghAtreya (via GitHub) via notifications" <no...@superset.apache.org>.
AmoghAtreya commented on PR #44968:
URL: https://github.com/apache/superset/pull/44968#issuecomment-6678868061

   Everything is updated and ready to be reviewed @sadpandajoe . The branch is current with master, and the merge conflicts are resolved. 
   
   The License Check failure is not a missing license header. The job downloads the Apache RAT jar before it scans any files, and that download failed on the runner. The same check is passing on other pull requests, and the script on this branch matches master. Re-running the job should clear it.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(sqllab): let schema grants authorize SQL Lab again [superset]

Posted by "AmoghAtreya (via GitHub)" <gi...@apache.org>.
AmoghAtreya commented on code in PR #44968:
URL: https://github.com/apache/superset/pull/44968#discussion_r4179530881


##########
tests/unit_tests/sqllab/test_requires_dataset_match.py:
##########
@@ -0,0 +1,75 @@
+# 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.
+from __future__ import annotations
+
+from unittest.mock import patch
+
+from flask import current_app
+from pytest_mock import MockerFixture
+
+from superset.sqllab.utils import requires_dataset_match
+from superset.sqllab.validators import CanAccessQueryValidatorImpl
+
+
+def test_requires_dataset_match_defaults_to_true() -> None:
+    """A missing config key keeps the dataset-match requirement on."""
+    config = current_app.config
+    original = config.pop("SQLLAB_REQUIRE_DATASET_MATCH", None)
+    try:
+        assert requires_dataset_match() is True
+    finally:
+        if original is not None:
+            config["SQLLAB_REQUIRE_DATASET_MATCH"] = original
+
+
+def test_requires_dataset_match_reads_config() -> None:
+    with patch.dict(current_app.config, {"SQLLAB_REQUIRE_DATASET_MATCH": False}):
+        assert requires_dataset_match() is False
+    with patch.dict(current_app.config, {"SQLLAB_REQUIRE_DATASET_MATCH": True}):
+        assert requires_dataset_match() is True
+
+
+def test_execute_validator_follows_config(mocker: MockerFixture) -> None:
+    """SQL Lab execute uses the same flag as result fetch and export."""
+    raise_for_access = mocker.patch(
+        "superset.sqllab.validators.security_manager.raise_for_access"

Review Comment:
   Fixed. `raise_for_access` in both tests and the `query` mock are annotated as `MagicMock`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(sqllab): let schema grants authorize SQL Lab again [superset]

Posted by "AmoghAtreya (via GitHub)" <gi...@apache.org>.
AmoghAtreya commented on code in PR #44968:
URL: https://github.com/apache/superset/pull/44968#discussion_r4179526073


##########
tests/unit_tests/sqllab/test_requires_dataset_match.py:
##########
@@ -0,0 +1,75 @@
+# 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.
+from __future__ import annotations
+
+from unittest.mock import patch
+
+from flask import current_app
+from pytest_mock import MockerFixture
+
+from superset.sqllab.utils import requires_dataset_match
+from superset.sqllab.validators import CanAccessQueryValidatorImpl
+
+
+def test_requires_dataset_match_defaults_to_true() -> None:
+    """A missing config key keeps the dataset-match requirement on."""
+    config = current_app.config
+    original = config.pop("SQLLAB_REQUIRE_DATASET_MATCH", None)
+    try:
+        assert requires_dataset_match() is True
+    finally:
+        if original is not None:
+            config["SQLLAB_REQUIRE_DATASET_MATCH"] = original
+
+
+def test_requires_dataset_match_reads_config() -> None:

Review Comment:
   Fixed. `test_requires_dataset_match_reads_config` now has a docstring, consistent with the other tests in the file.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(sqllab): let schema grants authorize SQL Lab again [superset]

Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #44968:
URL: https://github.com/apache/superset/pull/44968#issuecomment-5983903952

   <!-- Bito Reply -->
   The review comment is correct. The documentation in `docs/admin_docs/security/security.mdx` incorrectly implies that `catalog_access` is restricted to a single schema, whereas it actually authorizes access across the entire catalog. 
   
   To resolve this, the sentence should be updated to clarify that `catalog_access` provides broader scope. I have implemented the correction below:
   
   ```md
   - `schema_access` and `catalog_access` let the user browse that schema in SQL Lab and still authorize charts, but they do not authorize query execution.
   + `schema_access` lets the user browse that schema in SQL Lab, and `catalog_access` lets the user browse the catalog, and both still authorize charts, but they do not authorize query execution.
   ```
   
   I have checked the other comments on this PR. Would you like me to fetch all comments, validate them, and implement fixes for the rest as well?
   
   **docs/admin_docs/security/security.mdx**
   ```
   - `schema_access` and `catalog_access` let the user browse that schema in SQL Lab and still authorize charts, but they do not authorize query execution.
   + `schema_access` lets the user browse that schema in SQL Lab, and `catalog_access` lets the user browse the catalog, and both still authorize charts, but they do not authorize query execution.
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(sqllab): let schema grants authorize SQL Lab again [superset]

Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on code in PR #44968:
URL: https://github.com/apache/superset/pull/44968#discussion_r4179174432


##########
tests/unit_tests/sqllab/test_requires_dataset_match.py:
##########
@@ -0,0 +1,75 @@
+# 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.
+from __future__ import annotations
+
+from unittest.mock import patch
+
+from flask import current_app
+from pytest_mock import MockerFixture
+
+from superset.sqllab.utils import requires_dataset_match
+from superset.sqllab.validators import CanAccessQueryValidatorImpl
+
+
+def test_requires_dataset_match_defaults_to_true() -> None:
+    """A missing config key keeps the dataset-match requirement on."""
+    config = current_app.config
+    original = config.pop("SQLLAB_REQUIRE_DATASET_MATCH", None)
+    try:
+        assert requires_dataset_match() is True
+    finally:
+        if original is not None:
+            config["SQLLAB_REQUIRE_DATASET_MATCH"] = original
+
+
+def test_requires_dataset_match_reads_config() -> None:

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Missing test docstring</b></div>
   <div id="fix">
   
   BITO.md adaptive rule 12148 requires every new test function to carry a docstring. `test_requires_dataset_match_reads_config` is the only test in this file without one; `test_requires_dataset_match_defaults_to_true`, `test_execute_validator_follows_config`, and `test_query_raise_for_access_follows_config` all have docstrings. Add a one-line docstring for consistency.
   </div>
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #1629cf</i></small>
   </div>
   
   ---
   Should Bito avoid suggestions like this for future reviews? (<a href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
   - [ ] Yes, avoid them



##########
tests/unit_tests/sqllab/test_requires_dataset_match.py:
##########
@@ -0,0 +1,75 @@
+# 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.
+from __future__ import annotations
+
+from unittest.mock import patch
+
+from flask import current_app
+from pytest_mock import MockerFixture
+
+from superset.sqllab.utils import requires_dataset_match
+from superset.sqllab.validators import CanAccessQueryValidatorImpl
+
+
+def test_requires_dataset_match_defaults_to_true() -> None:
+    """A missing config key keeps the dataset-match requirement on."""
+    config = current_app.config
+    original = config.pop("SQLLAB_REQUIRE_DATASET_MATCH", None)
+    try:
+        assert requires_dataset_match() is True
+    finally:
+        if original is not None:
+            config["SQLLAB_REQUIRE_DATASET_MATCH"] = original
+
+
+def test_requires_dataset_match_reads_config() -> None:
+    with patch.dict(current_app.config, {"SQLLAB_REQUIRE_DATASET_MATCH": False}):
+        assert requires_dataset_match() is False
+    with patch.dict(current_app.config, {"SQLLAB_REQUIRE_DATASET_MATCH": True}):
+        assert requires_dataset_match() is True
+
+
+def test_execute_validator_follows_config(mocker: MockerFixture) -> None:
+    """SQL Lab execute uses the same flag as result fetch and export."""
+    raise_for_access = mocker.patch(
+        "superset.sqllab.validators.security_manager.raise_for_access"
+    )
+    query = mocker.MagicMock()
+
+    with patch.dict(current_app.config, {"SQLLAB_REQUIRE_DATASET_MATCH": False}):
+        CanAccessQueryValidatorImpl().validate(query, template_params={"a": 1})
+
+    raise_for_access.assert_called_once_with(
+        query=query,
+        template_params={"a": 1},
+        force_dataset_match=False,
+    )
+
+
+def test_query_raise_for_access_follows_config(mocker: MockerFixture) -> None:

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Function-local import violates rule</b></div>
   <div id="fix">
   
   BITO.md adaptive rule 12745 requires module-level imports unless a documented circular dependency exists. `from superset.models.sql_lab import Query` sits inside `test_query_raise_for_access_follows_config` with no explanatory comment, and this module already imports `superset.sqllab.utils` and `superset.sqllab.validators` at top level, so no cycle is avoided. Move it to the top import block.
   </div>
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #1629cf</i></small>
   </div>
   
   ---
   Should Bito avoid suggestions like this for future reviews? (<a href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
   - [ ] Yes, avoid them



##########
tests/unit_tests/sqllab/test_requires_dataset_match.py:
##########
@@ -0,0 +1,75 @@
+# 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.
+from __future__ import annotations
+
+from unittest.mock import patch
+
+from flask import current_app
+from pytest_mock import MockerFixture
+
+from superset.sqllab.utils import requires_dataset_match
+from superset.sqllab.validators import CanAccessQueryValidatorImpl
+
+
+def test_requires_dataset_match_defaults_to_true() -> None:
+    """A missing config key keeps the dataset-match requirement on."""
+    config = current_app.config
+    original = config.pop("SQLLAB_REQUIRE_DATASET_MATCH", None)
+    try:
+        assert requires_dataset_match() is True
+    finally:
+        if original is not None:
+            config["SQLLAB_REQUIRE_DATASET_MATCH"] = original
+
+
+def test_requires_dataset_match_reads_config() -> None:
+    with patch.dict(current_app.config, {"SQLLAB_REQUIRE_DATASET_MATCH": False}):
+        assert requires_dataset_match() is False
+    with patch.dict(current_app.config, {"SQLLAB_REQUIRE_DATASET_MATCH": True}):
+        assert requires_dataset_match() is True
+
+
+def test_execute_validator_follows_config(mocker: MockerFixture) -> None:
+    """SQL Lab execute uses the same flag as result fetch and export."""
+    raise_for_access = mocker.patch(
+        "superset.sqllab.validators.security_manager.raise_for_access"

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Untyped mock variables</b></div>
   <div id="fix">
   
   BITO.md adaptive rule 12787 requires explicit annotations on mock variables. `raise_for_access` (lines 46-48 here and 67-69 in `test_query_raise_for_access_follows_config`) and `query` (line 49) are untyped mocks. Annotate them as `MagicMock` and import `MagicMock` from `unittest.mock` so static checkers can validate the test code.
   </div>
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #1629cf</i></small>
   </div>
   
   ---
   Should Bito avoid suggestions like this for future reviews? (<a href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
   - [ ] Yes, avoid them



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(sqllab): let schema grants authorize SQL Lab again [superset]

Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #44968:
URL: https://github.com/apache/superset/pull/44968#issuecomment-5984031496

   ## [Codecov](https://app.codecov.io/gh/apache/superset/pull/44968?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   :x: Patch coverage is `94.11765%` with `1 line` in your changes missing coverage. Please review.
   :white_check_mark: Project coverage is 66.09%. Comparing base ([`ccae778`](https://app.codecov.io/gh/apache/superset/commit/ccae77849824db1fb3bc8c0107b6fb109fbb31c4?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`d11f470`](https://app.codecov.io/gh/apache/superset/commit/d11f470c8e65c4b811d39cb0048732b0d7d91cff?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
   :warning: Report is 1 commits behind head on master.
   
   | [Files with missing lines](https://app.codecov.io/gh/apache/superset/pull/44968?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
   |---|---|---|
   | [superset/mcp\_service/sql\_lab/tool/execute\_sql.py](https://app.codecov.io/gh/apache/superset/pull/44968?src=pr&el=tree&filepath=superset%2Fmcp_service%2Fsql_lab%2Ftool%2Fexecute_sql.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvbWNwX3NlcnZpY2Uvc3FsX2xhYi90b29sL2V4ZWN1dGVfc3FsLnB5) | 0.00% | [1 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/44968?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
   > :exclamation:  There is a different number of reports uploaded between BASE (ccae778) and HEAD (d11f470). Click for more details.
   > 
   > <details><summary>HEAD has 4 uploads less than BASE</summary>
   >
   >| Flag | BASE (ccae778) | HEAD (d11f470) |
   >|------|------|------|
   >|python|7|3|
   ></details>
   
   <details><summary>Additional details and impacted files</summary>
   
   
   
   ```diff
   @@             Coverage Diff             @@
   ##           master   #44968       +/-   ##
   ===========================================
   - Coverage   82.28%   66.09%   -16.19%     
   ===========================================
     Files        2997     2997               
     Lines      185240   185254       +14     
     Branches    42867    42868        +1     
   ===========================================
   - Hits       152433   122452    -29981     
   - Misses      30045    60119    +30074     
   + Partials     2762     2683       -79     
   ```
   
   | [Flag](https://app.codecov.io/gh/apache/superset/pull/44968/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Ξ” | |
   |---|---|---|
   | [hive](https://app.codecov.io/gh/apache/superset/pull/44968/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `36.30% <76.47%> (+<0.01%)` | :arrow_up: |
   | [mysql](https://app.codecov.io/gh/apache/superset/pull/44968/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [postgres](https://app.codecov.io/gh/apache/superset/pull/44968/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   | [presto](https://app.codecov.io/gh/apache/superset/pull/44968/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `38.18% <76.47%> (+<0.01%)` | :arrow_up: |
   | [python](https://app.codecov.io/gh/apache/superset/pull/44968/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `55.19% <94.11%> (-31.05%)` | :arrow_down: |
   | [sqlite](https://app.codecov.io/gh/apache/superset/pull/44968/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `55.06% <94.11%> (+<0.01%)` | :arrow_up: |
   | [unit](https://app.codecov.io/gh/apache/superset/pull/44968/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
   
   Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
   </details>
   
   [:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/superset/pull/44968?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).   
   :loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
   <details><summary> :rocket: New features to boost your workflow: </summary>
   
   - :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
   - :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
   </details>


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(sqllab): let schema grants authorize SQL Lab again [superset]

Posted by "codeant-ai-for-open-source[bot] (via GitHub)" <gi...@apache.org>.
codeant-ai-for-open-source[bot] commented on code in PR #44968:
URL: https://github.com/apache/superset/pull/44968#discussion_r4179128289


##########
superset/commands/sql_lab/estimate.py:
##########
@@ -91,7 +92,7 @@ def validate(self) -> None:
             catalog=self._catalog,
             schema=self._schema or None,
             template_params=self._template_params,
-            force_dataset_match=True,
+            force_dataset_match=requires_dataset_match(),

Review Comment:
   **Suggestion:** With nonempty template parameters, `validate()` authorizes one Jinja rendering while `run()` renders again, allowing cost estimation of a table without its dataset grant.
   
   **Assessment:** 🟠 `Major` Β· πŸ” `Occurrence: Rarely` Β· 🏷️ `Security`
   
   [![Use CodeAnt Skill](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/use-codeant-skill-flat-v2.svg)](https://docs.codeant.ai/cli/resolve-pr-comments-skill) [![Fix in Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=61fb8a68a209457b8cef8199b2474e36&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [![Fix in VSCode Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=61fb8a68a209457b8cef8199b2474e36&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   <details>
   <summary><b>Prompt for AI Agent πŸ€– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset/commands/sql_lab/estimate.py
   **Line:** 95:95
   **Comment:**
   	*Security: With nonempty template parameters, `validate()` authorizes one Jinja rendering while `run()` renders again, allowing cost estimation of a table without its dataset grant.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44968&comment_hash=34cc3d14d31e89aca4f198bbd99c0991ef62c5d520752481337cb4649a871430&reaction=like'>πŸ‘</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44968&comment_hash=34cc3d14d31e89aca4f198bbd99c0991ef62c5d520752481337cb4649a871430&reaction=dislike'>πŸ‘Ž</a>



##########
superset/mcp_service/sql_lab/tool/execute_sql.py:
##########
@@ -182,17 +183,16 @@ async def execute_sql(request: ExecuteSqlRequest, ctx: Context) -> ExecuteSqlRes
 
             # Authorize through the same entry point as the SQL Lab
             # execution path (``superset/sqllab/validators.py``), so both
-            # surfaces scope a query the same way: it covers database-level
-            # access and, for a user without it, requires every table the
-            # query references to resolve to a dataset they are granted.
+            # surfaces scope a query the same way, including
+            # ``SQLLAB_REQUIRE_DATASET_MATCH``.
             try:
                 security_manager.raise_for_access(
                     database=database,
                     sql=request.sql,
                     catalog=request.catalog,
                     schema=request.schema_name,
                     template_params=template_params,
-                    force_dataset_match=True,
+                    force_dataset_match=requires_dataset_match(),

Review Comment:
   **Suggestion:** `raise_for_access` checks one Jinja rendering, but `database.execute` renders the source again; a changing template can execute against a table the user cannot access.
   
   **Assessment:** πŸ”΄ `Critical` Β· πŸ” `Occurrence: Rarely` Β· 🏷️ `Security`
   
   [![Use CodeAnt Skill](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/use-codeant-skill-flat-v2.svg)](https://docs.codeant.ai/cli/resolve-pr-comments-skill) [![Fix in Cursor](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-cursor-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=fe2943a15c5f4afe9fd0f72de2d9bf8d&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [![Fix in VSCode Claude](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/fix-in-vscode-claude-flat.svg)](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=fe2943a15c5f4afe9fd0f72de2d9bf8d&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
   <details>
   <summary><b>Prompt for AI Agent πŸ€– </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** superset/mcp_service/sql_lab/tool/execute_sql.py
   **Line:** 195:195
   **Comment:**
   	*Security: `raise_for_access` checks one Jinja rendering, but `database.execute` renders the source again; a changing template can execute against a table the user cannot access.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44968&comment_hash=445499ca73402e98ed6e2222ab0c0d32b2f60c8ad469744e88351eaea5b30d50&reaction=like'>πŸ‘</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44968&comment_hash=445499ca73402e98ed6e2222ab0c0d32b2f60c8ad469744e88351eaea5b30d50&reaction=dislike'>πŸ‘Ž</a>



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(sqllab): let schema grants authorize SQL Lab again [superset]

Posted by "AmoghAtreya (via GitHub)" <gi...@apache.org>.
AmoghAtreya commented on code in PR #44968:
URL: https://github.com/apache/superset/pull/44968#discussion_r4179534234


##########
tests/unit_tests/sqllab/test_requires_dataset_match.py:
##########
@@ -0,0 +1,75 @@
+# 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.
+from __future__ import annotations
+
+from unittest.mock import patch
+
+from flask import current_app
+from pytest_mock import MockerFixture
+
+from superset.sqllab.utils import requires_dataset_match
+from superset.sqllab.validators import CanAccessQueryValidatorImpl
+
+
+def test_requires_dataset_match_defaults_to_true() -> None:
+    """A missing config key keeps the dataset-match requirement on."""
+    config = current_app.config
+    original = config.pop("SQLLAB_REQUIRE_DATASET_MATCH", None)
+    try:
+        assert requires_dataset_match() is True
+    finally:
+        if original is not None:
+            config["SQLLAB_REQUIRE_DATASET_MATCH"] = original
+
+
+def test_requires_dataset_match_reads_config() -> None:
+    with patch.dict(current_app.config, {"SQLLAB_REQUIRE_DATASET_MATCH": False}):
+        assert requires_dataset_match() is False
+    with patch.dict(current_app.config, {"SQLLAB_REQUIRE_DATASET_MATCH": True}):
+        assert requires_dataset_match() is True
+
+
+def test_execute_validator_follows_config(mocker: MockerFixture) -> None:
+    """SQL Lab execute uses the same flag as result fetch and export."""
+    raise_for_access = mocker.patch(
+        "superset.sqllab.validators.security_manager.raise_for_access"
+    )
+    query = mocker.MagicMock()
+
+    with patch.dict(current_app.config, {"SQLLAB_REQUIRE_DATASET_MATCH": False}):
+        CanAccessQueryValidatorImpl().validate(query, template_params={"a": 1})
+
+    raise_for_access.assert_called_once_with(
+        query=query,
+        template_params={"a": 1},
+        force_dataset_match=False,
+    )
+
+
+def test_query_raise_for_access_follows_config(mocker: MockerFixture) -> None:

Review Comment:
   Fixed. `Query` is imported at module level. The test file does not create a circular import, so the function-local import was unnecessary.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(sqllab): let schema grants authorize SQL Lab again [superset]

Posted by "codeant-ai-for-open-source[bot] (via GitHub)" <gi...@apache.org>.
codeant-ai-for-open-source[bot] commented on code in PR #44968:
URL: https://github.com/apache/superset/pull/44968#discussion_r4179509149


##########
superset/commands/sql_lab/estimate.py:
##########
@@ -91,7 +92,7 @@ def validate(self) -> None:
             catalog=self._catalog,
             schema=self._schema or None,
             template_params=self._template_params,
-            force_dataset_match=True,
+            force_dataset_match=requires_dataset_match(),

Review Comment:
   βœ… **CodeAnt verified this suggestion was addressed in subsequent commits and marked this thread resolved** as of `834f4d3`.
   
   The estimation path authorizes the source before rendering, then authorizes the literal SQL rendered by `run()` without rendering it again, so access is checked against the SQL being estimated.
   
   <sub>If that's not right, unresolve this thread and CodeAnt will leave it open.</sub>
   
   <!-- codeant-auto-resolve-reply -->



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(sqllab): let schema grants authorize SQL Lab again [superset]

Posted by "AmoghAtreya (via GitHub)" <gi...@apache.org>.
AmoghAtreya commented on code in PR #44968:
URL: https://github.com/apache/superset/pull/44968#discussion_r4179508431


##########
superset/commands/sql_lab/estimate.py:
##########
@@ -91,7 +92,7 @@ def validate(self) -> None:
             catalog=self._catalog,
             schema=self._schema or None,
             template_params=self._template_params,
-            force_dataset_match=True,
+            force_dataset_match=requires_dataset_match(),

Review Comment:
   Fixed. `validate()` still authorizes the Jinja source before rendering, and `run()` now authorizes the rendered SQL again before the cost estimate. The second check parses that literal statement, so a template that renders to a different table cannot be estimated against a table the first check never saw. If the second check fails, the database is not queried.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(sqllab): let schema grants authorize SQL Lab again [superset]

Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on code in PR #44968:
URL: https://github.com/apache/superset/pull/44968#discussion_r4180091984


##########
superset/mcp_service/sql_lab/tool/execute_sql.py:
##########
@@ -210,12 +248,17 @@ async def execute_sql(request: ExecuteSqlRequest, ctx: Context) -> ExecuteSqlRes
                 await ctx.error("Query could not be parsed for access validation")
                 return _invalid_sql_response()
 
+            rendered_sql = await _authorize_rendered_sql(

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Redundant double authorization</b></div>
   <div id="fix">
   
   `_authorize_rendered_sql` (line 251) re-renders and re-authorizes `request.sql`, duplicating the `raise_for_access` at line 227, which already renders via `process_jinja_sql` and checks access. Every query now renders/parses twice with two different renderers. Since execution uses `rendered_sql`, the first check is redundant; consider removing it so only the rendered SQL is authorized.
   </div>
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #483b91</i></small>
   </div>
   
   ---
   Should Bito avoid suggestions like this for future reviews? (<a href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
   - [ ] Yes, avoid them



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(sqllab): let schema grants authorize SQL Lab again [superset]

Posted by "AmoghAtreya (via GitHub)" <gi...@apache.org>.
AmoghAtreya commented on code in PR #44968:
URL: https://github.com/apache/superset/pull/44968#discussion_r4180654661


##########
superset/mcp_service/sql_lab/tool/execute_sql.py:
##########
@@ -210,12 +248,17 @@ async def execute_sql(request: ExecuteSqlRequest, ctx: Context) -> ExecuteSqlRes
                 await ctx.error("Query could not be parsed for access validation")
                 return _invalid_sql_response()
 
+            rendered_sql = await _authorize_rendered_sql(

Review Comment:
   Just took a look at this and I believe that Bito is incorrect about the redundancy being unnecessary here. The two checks authorize different SQL, making the double authorization valid. `raise_for_access` renders through `process_jinja_sql`, which neutralizes partition macros before parsing. `_authorize_rendered_sql` renders with `process_template`, the renderer execution uses and authorizes that literal string. Those renders can name different tables, so the second check is what gates the SQL that actually runs. The first check stays so a denied query does not get its live macros evaluated.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org


Re: [PR] fix(sqllab): let schema grants authorize SQL Lab again [superset]

Posted by "AmoghAtreya (via GitHub) via notifications" <no...@superset.apache.org>.
AmoghAtreya commented on code in PR #44968:
URL: https://github.com/apache/superset/pull/44968#discussion_r4635687637


##########
superset/security/manager.py:
##########
@@ -5488,8 +5512,10 @@ def raise_for_access(  # noqa: C901
                 # Statements that rebind how unqualified table names resolve
                 # (``USE``, ``SET SCHEMA``, or a ``search_path`` change) make
                 # the qualification below diverge from what the engine uses at
-                # execution time, so reject them regardless of engine.
-                if force_dataset_match and parse_result.script.changes_default_schema():
+                # execution time. This is independent of dataset matching: a
+                # schema or catalog grant must not authorize a script that
+                # then switches the shared cursor to another schema.
+                if parse_result.script.changes_default_schema():

Review Comment:
   Thank you for taking a look! Kept those checks on when SQLLAB_REQUIRE_DATASET_MATCH is off.
   
   Unparseable SQL (CALL, Kusto KQL, and anything else that yields no tables) is denied either way, same as USE / search_path. A schema grant does not cover a table whose schema cannot be determined, so the lookup cannot match a same-named table in another schema. A catalog grant still covers every schema in that catalog.
   
   SQL Lab now passes allow_editorship=False on execution, results, export, formatting, cost estimates, and MCP execute_sql. Editorship of a dataset does not authorize those paths when the flag is off. Chart and Explore still accept editorship on the non-strict path.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org