cube-js / cube

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

Metabase 49.3 connector issue #8105

Closed tanguyantoine closed 6 months ago

tanguyantoine commented 6 months ago

Describe the bug A clear and concise description of what the bug is.

Metabase has recently changed the way they check permissions when connecting to a new database https://github.com/metabase/metabase/pull/40034/files

They now rely on has_any_column_privilege rather than has_table_privilege

it makes impossible to connect metabase 49.3 to cube using postres protocol through apiType postgre

with table_privileges as (
   select
   NULL as role,
   t.schemaname as schema,
   t.objectname as table,
   pg_catalog.has_any_column_privilege(current_user, '\"' || t.schemaname || '\"' || '.' || '\"' || t.objectname || '\"',  'update') as  update,
   pg_catalog.has_any_column_privilege(current_user, '\"' || t.schemaname || '\"' || '.' || '\"' || t.objectname || '\"',  'select') as select,
   pg_catalog.has_any_column_privilege(current_user, '\"' || t.schemaname || '\"' || '.' || '\"' || t.objectname || '\"',  'insert') as insert,
   pg_catalog.has_table_privilege(current_user, '\"' || t.schemaname || '\"' || '.' || '\"' || t.objectname || '\"',  'delete') as delete
 from (
     select schemaname, tablename as objectname from pg_catalog.pg_tables
   union
   select schemaname, viewname as objectname from pg_catalog.pg_views
   union
   select schemaname, matviewname as objectname from pg_catalog.pg_matviews
 ) t
 where t.schemaname !~ '^pg_'
   and t.schemaname <> 'information_schema'
   and pg_catalog.has_schema_privilege(current_user, t.schemaname, 'usage')
)
select t.*
from table_privileges t```

**To Reproduce**
Steps to reproduce the behavior:
1. Go to metabase admin (version 49.3)
2. add cube as database using correct credentials
4. See error

**Expected behavior**
The connection should work and schema should be fetched by Metabase

**Minimally reproducible Cube Schema**

```javascript
cube(`Orders`, {
  sql: `
  select 1 as id, 100 as amount, 'new' status
  UNION ALL
  select 2 as id, 200 as amount, 'new' status
  UNION ALL
  select 3 as id, 300 as amount, 'processed' status
  UNION ALL
  select 4 as id, 500 as amount, 'processed' status
  UNION ALL
  select 5 as id, 600 as amount, 'shipped' status
  `,
  measures: {
    count: {
      type: `count`,
    },
    totalAmount: {
      sql: `amount`,
      type: `sum`,
    },
    toRemove: {
      type: `count`,
    },
  },
  dimensions: {
    status: {
      sql: `status`,
      type: `string`,
    },
  },
});

Version: 0.35.10

Additional context Nothing else

igorlukanin commented 6 months ago

Hi @tanguyantoine 👋

Are you absolutely sure it doesn't work with 0.35.10? Does anything change if you set CUBESQL_SQL_PUSH_DOWN to true?

@ovr has shipped the fix for this one yesterday in 0.35.10, hence my question: https://github.com/cube-js/cube/releases/tag/v0.35.10

tanguyantoine commented 6 months ago

Hi @igorlukanin I confirm it does not work I'm getting this error

Error during processing PostgreSQL message: CubeError: External error: This feature is not implemented: has_any_column_privilege is not implemented, it's a stub

ovr commented 6 months ago

Fixed & release in v0.35.11

Could you give it a try?

Thanks

tanguyantoine commented 6 months ago

It fixed the connectivity issue. Thank you