cube-js / cube

📊 Cube — The Semantic Layer for Building Data Applications
https://cube.dev
Other
17.92k stars 1.78k forks source link

Use Redshift-appropriate query for information schema discovery #3876

Open emmanuel opened 2 years ago

emmanuel commented 2 years ago

Describe the bug

The RedshiftDriver class inherits createSchemaIfNotExists() from the BaseDriver class, by way of the PostgresDriver class. The implementation of that method doesn't error on Redshift, but it only returns results for schemas owned by the querying user. This results in breakage when Cube.js accesses Redshift with credentials that can access a schema but is not the owner of the schema, because the existing implementation of createSchemaIfNotExists() will return no results, and will then attempt to create the pre-aggregation schema. If the calling user does not have permission to create schemas, this will result in an error being thrown without any explanation of which query failed.

To Reproduce Steps to reproduce the behavior:

  1. Provision a Redshift cluster
  2. Create a pre_aggregation schema in that cluster
  3. Create a user in that cluster, with access to the pre_aggregation schema (e.g., GRANT USAGE ON SCHEMA pre_aggregation TO ...;
  4. Create a Cube.js app with a one-cube schema containing a simple pre-aggregation
  5. Run the Cube.js app configured for scheduled refresh, to use the Redshift cluster as the default source DB and to use credentials for the user created in step 3
  6. Watch it fail with a permission error

Expected behavior

Expected Cube.js to function correctly when running as a user with appropriate permissions in the pre-aggregation schema (SELECT, CREATE TABLE, etc).

Screenshots

n/a

Version:

0.29.15

paveltiunov commented 2 years ago

Hey @emmanuel ! Thanks for posting this one! Do you think there's a SQL query that allows seeing schema is in place without ownership permission?

paveltiunov commented 2 years ago

Nvm. I didn't notice the link to the PR.