Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle empty catalog when DB supports them #29840

Merged
merged 8 commits into from
Aug 13, 2024

Conversation

betodealmeida
Copy link
Member

@betodealmeida betodealmeida commented Aug 2, 2024

SUMMARY

Handle edge cases when catalog is passed as null but the database supports catalog. This happens when "Allow changing catalogs" is disabled in the database. In these cases we need to use the default catalog, so that permissions checks work as expected.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A

TESTING INSTRUCTIONS

  1. Add a database with catalogs (eg, Postgres)
  • Catalog permissions are created (eg, [Postgres].[superset])
  • Schema permissions are created (eg, [Postgres].[superset].[public])
  1. Create a user A with catalog-level permissions to the default catalog
  • User can see schemas in SQL Lab
  • User can choose schema in SQL Lab
  • User can choose table in SQL Lab
  • User can run queries
  • User can create a new dataset
  • User can see charts built from the dataset
  1. Create a user B with schema-level permissions to the default catalog
  • User can see only 1 schema in SQL Lab
  • User can choose table in SQL Lab
  • User can run queries
  • User can create a new dataset
  • User can see charts built from the dataset
  1. Create a user C with catalog-level permissions to a non-default catalog
  • User can't see schemas/tables in SQL Lab
  • User can't run queries in SQL Lab
  1. Create a user D with schema-level permissions to a non-default catalog
  • User can't see schemas/tables in SQL Lab
  • User can't run queries in SQL Lab
  1. Enable multi-catalog
  • Admin should see all catalogs
  • A, B, C, D should only see the catalogs they have access to
  • Repeat steps from (2)

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@pull-request-size pull-request-size bot added size/L and removed size/M labels Aug 4, 2024
@rusackas rusackas marked this pull request as draft August 5, 2024 16:46
@rusackas
Copy link
Member

rusackas commented Aug 5, 2024

I just put this in draft mode whilst it doesn't have a title/description :) Best of luck with whatever it is! :D

@betodealmeida betodealmeida changed the title WIP fix: handle empty catalog when DB supports them Aug 6, 2024
@github-actions github-actions bot added the api Related to the REST API label Aug 6, 2024
@betodealmeida betodealmeida marked this pull request as ready for review August 6, 2024 21:49
@dosubot dosubot bot added authentication:access-control Rlated to access control data Namespace | Anything related to data, including databases configurations, datasets, etc. labels Aug 6, 2024
@@ -52,7 +52,7 @@
def fetch_files_github_api(url: str): # type: ignore
"""Fetches data using GitHub API."""
req = Request(url)
req.add_header("Authorization", f"token {GITHUB_TOKEN}")
req.add_header("Authorization", f"Bearer {GITHUB_TOKEN}")
Copy link
Member Author

Choose a reason for hiding this comment

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

Note: In most cases, you can use Authorization: Bearer or Authorization: token to pass a token. However, if you are passing a JSON web token (JWT), you must use Authorization: Bearer. [source]

Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!

@sadpandajoe
Copy link
Member

@supersetbot label 4.1

@github-actions github-actions bot added the v4.1 Label added by the release manager to track PRs to be included in the 4.1 branch label Aug 7, 2024
@betodealmeida betodealmeida mentioned this pull request Aug 9, 2024
9 tasks
@@ -1159,7 +1159,7 @@ def select_star(
self.incr_stats("init", self.select_star.__name__)
try:
result = database.select_star(
Table(table_name, schema_name),
Table(table_name, schema_name, database.get_default_catalog()),
Copy link
Contributor

Choose a reason for hiding this comment

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

Should catalog be added to the API path as well (when the table is not from the default one)? Not related with this PR, just asking if it's something we need to do.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, but I I couldn't find any API calls to this endpoint — it seems like we return this in the database request now, instead of calling /select_star/, which is why I didn't change the code to pass a parameter. I think we should keep this endpoint until the next major version and then get rid of it.

Copy link
Contributor

Choose a reason for hiding this comment

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

gotcha! thank you

Copy link
Contributor

@Vitor-Avila Vitor-Avila left a comment

Choose a reason for hiding this comment

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

LGTM!

@@ -1563,34 +1563,6 @@ def test_get_select_star_not_allowed(self):
rv = self.client.get(uri)
self.assertEqual(rv.status_code, 404)

def test_get_select_star_datasource_access(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

Non-blocking comment: would be good if you could mention why these tests were removed.

Copy link
Member Author

Choose a reason for hiding this comment

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

These tests were poorly written and relied on weird side effects.

Copy link
Contributor

Choose a reason for hiding this comment

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

thank you!

@betodealmeida betodealmeida merged commit 39209c2 into master Aug 13, 2024
35 checks passed
sadpandajoe pushed a commit that referenced this pull request Aug 13, 2024
@rusackas rusackas deleted the use-default-catalog branch September 27, 2024 20:55
@github-actions github-actions bot added 🍒 4.1.0 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels labels Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Related to the REST API authentication:access-control Rlated to access control 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels data Namespace | Anything related to data, including databases configurations, datasets, etc. preset-io review:draft size/L v4.1 Label added by the release manager to track PRs to be included in the 4.1 branch 🍒 4.1.0 🍒 4.1.1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants