pg.ddx.io pgsql-odbc@postgresql.org mailing list archive
help / color / mirror / Atom feedQuestion regarding accessing only tables to which the user has access
8+ messages / 4 participants
[nested] [flat]
* Question regarding accessing only tables to which the user has access
@ 2016-03-28 17:40 Fernando Luna <Fernando.Luna@Tideworks.com>
2016-03-29 03:10 ` Re: Question regarding accessing only tables to which the user has access Tsunakawa, Takayuki <tsunakawa.takay@jp.fujitsu.com>
2016-03-29 03:49 ` Re: Question regarding accessing only tables to which the user has access Inoue, Hiroshi <h-inoue@dream.email.ne.jp>
0 siblings, 2 replies; 8+ messages in thread
From: Fernando Luna @ 2016-03-28 17:40 UTC (permalink / raw)
To: pgsql-odbc
I am using Tableau version 9.2 to connect to a PostgreSQL database (version 9.4). This database resides in a VM running Redhat CentOS and I am connecting from my Windows 7 box using the latest Windows driver found under http://www.postgresql.org/ftp/odbc/versions/msi/ . The zipfile name is psqlodbc_09_05_0100-x64.zip<https://ftp.postgresql.org/pub/odbc/versions/msi/psqlodbc_09_05_0100-x64.zip;
My question is this. When Tableau connects it retrieves a list of tables/views to use. My problem is that Tableau is listing tables to which the connected user has no privileges and it makes for a poor user experience to allow Tableau to do that in our case. We want to only list those tables/views to which the connected user has at the very least select privileges. At first I thought it was Tableau doing this and after a while I decided to turn on logging on PostgreSQL and found that the following query is issued whenever I connect using Tableau.
select relname, nspname, relkind
from pg_catalog.pg_class c, pg_catalog.pg_namespace n
where relkind in ('r', 'v')
and nspname not in ('pg_catalog', 'information_schema', 'pg_toast', 'pg_temp_1')
and n.oid = relnamespace
order by nspname, relname
I discovered that this query is executed by the postgres odbc driver on connect. I looked at the source code for the latest driver and found this code snippet in info.c:
if (!list_some)
{
if (CC_accessible_only(conn))
strcat(tables_query, " and has_table_privilege(c.oid, 'select')");
}
My question is, how can I get the driver to add this snippet to the query? Please bear in mind that I know nearly nothing about Postgres and ODBC and would appreciate being pointed in the right direction as to how to influence pgsql odbc to issue the query like this:
select relname, nspname, relkind
from pg_catalog.pg_class c, pg_catalog.pg_namespace n
where relkind in ('r', 'v')
and nspname not in ('pg_catalog', 'information_schema', 'pg_toast', 'pg_temp_1')
and has_table_privilege(c.oid, 'select')
and n.oid = relnamespace
order by nspname, relname
I've tried searching for references to CC_accessible_only and references to "has_table_privileges" in your forum/mailing list but I've not found anything that tells me definitively how to accomplish this.
Thanks!
Fernando Luna
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Question regarding accessing only tables to which the user has access
2016-03-28 17:40 Question regarding accessing only tables to which the user has access Fernando Luna <Fernando.Luna@Tideworks.com>
@ 2016-03-29 03:10 ` Tsunakawa, Takayuki <tsunakawa.takay@jp.fujitsu.com>
2016-03-29 03:27 ` Re: Question regarding accessing only tables to which the user has access Fernando Luna <Fernando.Luna@Tideworks.com>
1 sibling, 1 reply; 8+ messages in thread
From: Tsunakawa, Takayuki @ 2016-03-29 03:10 UTC (permalink / raw)
To: Fernando Luna <Fernando.Luna@Tideworks.com>; pgsql-odbc
Hello, Fernando,
Try setting the extra option parameter in either of the following ways:
* If you use the connection string, add "AB=10".
* If you configure the data source using the ODBC Administrator, enter "10" in the "Extra Opts" text box in advanced settings page 2.
BTW, maybe Tableau should provide the option to list the tables on which the user has SELECT privilege. Tableau should do so by first calling SQLGetInfo(SQL_ACCESSIBLE_TABLES), and then calling SQLTablePrivileges() if SQLGetInfo() returns "N". Tableau perhaps calls SQLTables() instead. As the reference page describes, it is driver-dependent whether SQLTables() returns only accessible tables or all tables.
SQLTables Function
https://msdn.microsoft.com/en-us/library/ms711831(v=vs.85).aspx
--------------------------------------------------
SQLTables lists all tables in the requested range. A user may or may not have SELECT privileges to any of these tables. To check accessibility, an application can:
Call SQLGetInfo and check the SQL_ACCESSIBLE_TABLES information type.
Call SQLTablePrivileges to check the privileges for each table.
--------------------------------------------------
Regards
Takayuki Tsunakawa
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Question regarding accessing only tables to which the user has access
2016-03-28 17:40 Question regarding accessing only tables to which the user has access Fernando Luna <Fernando.Luna@Tideworks.com>
2016-03-29 03:10 ` Re: Question regarding accessing only tables to which the user has access Tsunakawa, Takayuki <tsunakawa.takay@jp.fujitsu.com>
@ 2016-03-29 03:27 ` Fernando Luna <Fernando.Luna@Tideworks.com>
0 siblings, 0 replies; 8+ messages in thread
From: Fernando Luna @ 2016-03-29 03:27 UTC (permalink / raw)
To: Tsunakawa, Takayuki <tsunakawa.takay@jp.fujitsu.com>; pgsql-odbc
Hi Takayuki:
Thank you so much for your quick reply. I'll try this in the morning and let you know how it goes. Additionally I'll pass on your comments to the Tableau folks.
Have a great day!
Fernando Luna
_______________________________________
From: Tsunakawa, Takayuki [tsunakawa.takay@jp.fujitsu.com]
Sent: Monday, March 28, 2016 8:10 PM
To: Fernando Luna; 'pgsql-odbc@postgresql.org'
Subject: RE: Question regarding accessing only tables to which the user has access
Hello, Fernando,
Try setting the extra option parameter in either of the following ways:
* If you use the connection string, add "AB=10".
* If you configure the data source using the ODBC Administrator, enter "10" in the "Extra Opts" text box in advanced settings page 2.
BTW, maybe Tableau should provide the option to list the tables on which the user has SELECT privilege. Tableau should do so by first calling SQLGetInfo(SQL_ACCESSIBLE_TABLES), and then calling SQLTablePrivileges() if SQLGetInfo() returns "N". Tableau perhaps calls SQLTables() instead. As the reference page describes, it is driver-dependent whether SQLTables() returns only accessible tables or all tables.
SQLTables Function
https://msdn.microsoft.com/en-us/library/ms711831(v=vs.85).aspx
--------------------------------------------------
SQLTables lists all tables in the requested range. A user may or may not have SELECT privileges to any of these tables. To check accessibility, an application can:
Call SQLGetInfo and check the SQL_ACCESSIBLE_TABLES information type.
Call SQLTablePrivileges to check the privileges for each table.
--------------------------------------------------
Regards
Takayuki Tsunakawa
--
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Question regarding accessing only tables to which the user has access
2016-03-28 17:40 Question regarding accessing only tables to which the user has access Fernando Luna <Fernando.Luna@Tideworks.com>
@ 2016-03-29 03:49 ` Inoue, Hiroshi <h-inoue@dream.email.ne.jp>
2016-03-29 15:33 ` Re: Question regarding accessing only tables to which the user has access Fernando Luna <Fernando.Luna@Tideworks.com>
1 sibling, 1 reply; 8+ messages in thread
From: Inoue, Hiroshi @ 2016-03-29 03:49 UTC (permalink / raw)
To: Fernando Luna <Fernando.Luna@Tideworks.com>; +Cc: pgsql-odbc
Hi Fernando,
On 2016/03/29 2:40, Fernando Luna wrote:
>
> I am using Tableau version 9.2 to connect to a PostgreSQL database
> (version 9.4). This database resides in a VM running Redhat CentOS and
> I am connecting from my Windows 7 box using the latest Windows driver
> found under http://www.postgresql.org/ftp/odbc/versions/msi/ . The
> zipfile name is psqlodbc_09_05_0100-x64.zip
> <https://ftp.postgresql.org/pub/odbc/versions/msi/psqlodbc_09_05_0100-x64.zip;
>
> My question is this. When Tableau connects it retrieves a list of
> tables/views to use. My problem is that Tableau is listing tables to
> which the connected user has no privileges and it makes for a poor
> user experience to allow Tableau to do that in our case. We want to
> only list those tables/views to which the connected user has at the
> very least select privileges. At first I thought it was Tableau doing
> this and after a while I decided to turn on logging on PostgreSQL and
> found that the following query is issued whenever I connect using Tableau.
>
> select relname, nspname, relkind
>
> from pg_catalog.pg_class c, pg_catalog.pg_namespace n
>
> where relkind in ('r', 'v')
>
> and nspname not in ('pg_catalog', 'information_schema', 'pg_toast',
> 'pg_temp_1')
>
> and n.oid = relnamespace
>
> order by nspname, relname
>
> I discovered that this query is executed by the postgres odbc driver
> on connect. I looked at the source code for the latest driver and
> found this code snippet in info.c:
>
> if (!list_some)
>
> {
>
> if (CC_accessible_only(conn))
>
> strcat(tables_query, " and has_table_privilege(c.oid, 'select')");
>
> }
>
> My question is, how can I get the driver to add this snippet to the
> query? Please bear in mind that I know nearly nothing about Postgres
> and ODBC and would appreciate being pointed in the right direction as
> to how to influence pgsql odbc to issue the query like this:
>
> select relname, nspname, relkind
>
> from pg_catalog.pg_class c, pg_catalog.pg_namespace n
>
> where relkind in ('r', 'v')
>
> and nspname not in ('pg_catalog', 'information_schema', 'pg_toast',
> 'pg_temp_1')
>
> and has_table_privilege(c.oid, 'select')
>
> and n.oid = relnamespace
>
> order by nspname, relname
>
Please set the "Extra Opts" option of Advanced Options(Datasource) Page
2 using ODBC Data Source Administrator.
Try to set Extra Opts to 0x10.
regards,
Hiroshi Inoue
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: Question regarding accessing only tables to which the user has access
2016-03-28 17:40 Question regarding accessing only tables to which the user has access Fernando Luna <Fernando.Luna@Tideworks.com>
2016-03-29 03:49 ` Re: Question regarding accessing only tables to which the user has access Inoue, Hiroshi <h-inoue@dream.email.ne.jp>
@ 2016-03-29 15:33 ` Fernando Luna <Fernando.Luna@Tideworks.com>
0 siblings, 0 replies; 8+ messages in thread
From: Fernando Luna @ 2016-03-29 15:33 UTC (permalink / raw)
To: Inoue, Hiroshi <h-inoue@dream.email.ne.jp>; +Cc: pgsql-odbc
Hi Hiroshi!
I will definitely give that a shit. Thanks so much for your quick reply!
Fernando Luna
________________________________________
From: Inoue, Hiroshi [h-inoue@dream.email.ne.jp]
Sent: Monday, March 28, 2016 8:49 PM
To: Fernando Luna
Cc: 'pgsql-odbc@postgresql.org'
Subject: Re: [ODBC] Question regarding accessing only tables to which the user has access
Hi Fernando,
On 2016/03/29 2:40, Fernando Luna wrote:
I am using Tableau version 9.2 to connect to a PostgreSQL database (version 9.4). This database resides in a VM running Redhat CentOS and I am connecting from my Windows 7 box using the latest Windows driver found under http://www.postgresql.org/ftp/odbc/versions/msi/ . The zipfile name is psqlodbc_09_05_0100-x64.zip<https://ftp.postgresql.org/pub/odbc/versions/msi/psqlodbc_09_05_0100-x64.zip;
My question is this. When Tableau connects it retrieves a list of tables/views to use. My problem is that Tableau is listing tables to which the connected user has no privileges and it makes for a poor user experience to allow Tableau to do that in our case. We want to only list those tables/views to which the connected user has at the very least select privileges. At first I thought it was Tableau doing this and after a while I decided to turn on logging on PostgreSQL and found that the following query is issued whenever I connect using Tableau.
select relname, nspname, relkind
from pg_catalog.pg_class c, pg_catalog.pg_namespace n
where relkind in ('r', 'v')
and nspname not in ('pg_catalog', 'information_schema', 'pg_toast', 'pg_temp_1')
and n.oid = relnamespace
order by nspname, relname
I discovered that this query is executed by the postgres odbc driver on connect. I looked at the source code for the latest driver and found this code snippet in info.c:
if (!list_some)
{
if (CC_accessible_only(conn))
strcat(tables_query, " and has_table_privilege(c.oid, 'select')");
}
My question is, how can I get the driver to add this snippet to the query? Please bear in mind that I know nearly nothing about Postgres and ODBC and would appreciate being pointed in the right direction as to how to influence pgsql odbc to issue the query like this:
select relname, nspname, relkind
from pg_catalog.pg_class c, pg_catalog.pg_namespace n
where relkind in ('r', 'v')
and nspname not in ('pg_catalog', 'information_schema', 'pg_toast', 'pg_temp_1')
and has_table_privilege(c.oid, 'select')
and n.oid = relnamespace
order by nspname, relname
Please set the "Extra Opts" option of Advanced Options(Datasource) Page 2 using ODBC Data Source Administrator.
Try to set Extra Opts to 0x10.
regards,
Hiroshi Inoue
--
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc
^ permalink raw reply [nested|flat] 8+ messages in thread
* RE: [ODBC] Question regarding accessing only tables to which the user has access
@ 2018-04-23 17:36 Fernando Luna <Fernando.Luna@Tideworks.com>
2018-04-24 18:38 ` Re: [ODBC] Question regarding accessing only tables to which the user has access John Kew <jkew@tableau.com>
0 siblings, 1 reply; 8+ messages in thread
From: Fernando Luna @ 2018-04-23 17:36 UTC (permalink / raw)
To: pgsql-odbc; +Cc: Inoue, Hiroshi <h-inoue@dream.email.ne.jp>
Hello:
I broached this subject a couple of years ago. Basically, Tableau, the product we use for Business Intelligence uses the Postgres JDBC driver and we were puzzled as to why it seemed to allow users to view tables to which they didn't have permissions on the database. It made for a poor user experience and with some sleuthing I discovered that the query that the JDBC driver uses doesn't seem to take into account whether or not the connecting user has the SELECT privilege.
This is the query the JDBC driver is issuing:
select relname, nspname, relkind
from pg_catalog.pg_class c, pg_catalog.pg_namespace n
where relkind in ('r', 'v')
and nspname not in ('pg_catalog', 'information_schema', 'pg_toast', 'pg_temp_1')
and n.oid = relnamespace
order by nspname, relname
Not only is this not taking into account the user's SELECT privilege but it completely excludes materialized views!
Now, I know that your source code provides for this under specific conditions:
IE:
if (!list_some)
{
if (CC_accessible_only(conn))
strcat(tables_query, " and has_table_privilege(c.oid, 'select')");
}
But this is an incomplete solution and it would not be desirable to present a list of tables to a user that they have no hope of accessing.
I propose that someone change this permanently (under all conditions) to something that makes more sense like this:
select c.relname, n.nspname, c.relkind
from pg_catalog.pg_class c, pg_catalog.pg_namespace n
where c.relkind in ('r', 'v', 'm')
and n.nspname not in ('pg_catalog', 'information_schema', 'pg_toast', 'pg_temp_1')
and has_table_privilege(c.oid, 'select')
and n.oid = c.relnamespace
order by n.nspname, c.relname
Note that I have added an extra condition for relkind ('m' for materialized views) and also an extra check (has_table_privilege).
This would help our problem and provide a solution for all Tableau users as Tableau is recommending creating dynamic views that do not perform well as a work-around (which suggests they don't know the solution to this is tied to the driver).
Let me know if this would be possible. While Hiroshi's solution below was appreciated, I don't think it's workable for us to require our customer base to make changes as to how the driver is engaged within Tableau.
Regards,
Fernando Luna
Fernando.Luna@Tideworks.com<mailto:Fernando.Luna@Tideworks.com>
Senior SDE/Data Engineering
[cid:image001.png@01CF6B5B.9BA017B0]
-----Original Message-----
From: Fernando Luna
Sent: Tuesday, March 29, 2016 8:33 AM
To: Inoue, Hiroshi <h-inoue@dream.email.ne.jp>
Cc: 'pgsql-odbc@postgresql.org' <pgsql-odbc@postgresql.org>
Subject: RE: [ODBC] Question regarding accessing only tables to which the user has access
Hi Hiroshi!
I will definitely give that a shot. Thanks so much for your quick reply!
Fernando Luna
________________________________________
From: Inoue, Hiroshi [h-inoue@dream.email.ne.jp]
Sent: Monday, March 28, 2016 8:49 PM
To: Fernando Luna
Cc: 'pgsql-odbc@postgresql.org'
Subject: Re: [ODBC] Question regarding accessing only tables to which the user has access
Hi Fernando,
On 2016/03/29 2:40, Fernando Luna wrote:
I am using Tableau version 9.2 to connect to a PostgreSQL database (version 9.4). This database resides in a VM running Redhat CentOS and I am connecting from my Windows 7 box using the latest Windows driver found under http://www.postgresql.org/ftp/odbc/versions/msi/ . The zipfile name is psqlodbc_09_05_0100-x64.zip<https://ftp.postgresql.org/pub/odbc/versions/msi/psqlodbc_09_05_0100-x64.zip;
My question is this. When Tableau connects it retrieves a list of tables/views to use. My problem is that Tableau is listing tables to which the connected user has no privileges and it makes for a poor user experience to allow Tableau to do that in our case. We want to only list those tables/views to which the connected user has at the very least select privileges. At first I thought it was Tableau doing this and after a while I decided to turn on logging on PostgreSQL and found that the following query is issued whenever I connect using Tableau.
select relname, nspname, relkind
from pg_catalog.pg_class c, pg_catalog.pg_namespace n
where relkind in ('r', 'v')
and nspname not in ('pg_catalog', 'information_schema', 'pg_toast', 'pg_temp_1')
and n.oid = relnamespace
order by nspname, relname
I discovered that this query is executed by the postgres odbc driver on connect. I looked at the source code for the latest driver and found this code snippet in info.c:
if (!list_some)
{
if (CC_accessible_only(conn))
strcat(tables_query, " and has_table_privilege(c.oid, 'select')");
}
My question is, how can I get the driver to add this snippet to the query? Please bear in mind that I know nearly nothing about Postgres and ODBC and would appreciate being pointed in the right direction as to how to influence pgsql odbc to issue the query like this:
select relname, nspname, relkind
from pg_catalog.pg_class c, pg_catalog.pg_namespace n
where relkind in ('r', 'v')
and nspname not in ('pg_catalog', 'information_schema', 'pg_toast', 'pg_temp_1')
and has_table_privilege(c.oid, 'select')
and n.oid = relnamespace
order by nspname, relname
Please set the "Extra Opts" option of Advanced Options(Datasource) Page 2 using ODBC Data Source Administrator.
Try to set Extra Opts to 0x10.
regards,
Hiroshi Inoue
Attachments:
image001.jpg (image/jpeg, 3.8K) download
view image
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: [ODBC] Question regarding accessing only tables to which the user has access
2018-04-23 17:36 RE: [ODBC] Question regarding accessing only tables to which the user has access Fernando Luna <Fernando.Luna@Tideworks.com>
@ 2018-04-24 18:38 ` John Kew <jkew@tableau.com>
2018-04-24 18:47 ` RE: [ODBC] Question regarding accessing only tables to which the user has access Fernando Luna <Fernando.Luna@Tideworks.com>
0 siblings, 1 reply; 8+ messages in thread
From: John Kew @ 2018-04-24 18:38 UTC (permalink / raw)
To: Fernando Luna <Fernando.Luna@Tideworks.com>; pgsql-odbc; +Cc: Inoue, Hiroshi <h-inoue@dream.email.ne.jp>
Fernando,
I'm with the connectivity team at Tableau and we are responsible for the postresql connector. First off if you are using Tableau you are probably using ODBC. We do have JDBC implemented, but it isn't turned on for general customers.
Materialized Views
As you have noticed, when connecting to PostgreSQL using ODBC we use SQLTablesW rather than issue a custom query ourselves. In an ideal world we would support materialized views through the information schema but this has not made it into the spec:
https://www.postgresql.org/message-id/3794.1412980686@sss.pgh.pa.us
We actually have a feature open to support this because honestly there are lots of people at Tableau who want to use materialized views as well. To do this we would essentially stop calling SQLTablesW and make a direct query. I'll talk with our team to figure out if this is something we can schedule given that it is probably unlikely that materialized views will be a standard part of the information schema any time soon.
Select Grants
Listing tables for select grants is a little more complicated, but really only for other databases which make use of libpq but have more complicated role models. This requires more consideration, it is not a oft requested feature, and it may have some performance impact on non-postgres libpq compatible databases.
-John
________________________________
From: Fernando Luna <Fernando.Luna@Tideworks.com>
Sent: Monday, April 23, 2018 10:36:36 AM
To: 'pgsql-odbc@postgresql.org'
Cc: Inoue, Hiroshi
Subject: RE: [ODBC] Question regarding accessing only tables to which the user has access
Hello:
I broached this subject a couple of years ago. Basically, Tableau, the product we use for Business Intelligence uses the Postgres JDBC driver and we were puzzled as to why it seemed to allow users to view tables to which they didn’t have permissions on the database. It made for a poor user experience and with some sleuthing I discovered that the query that the JDBC driver uses doesn’t seem to take into account whether or not the connecting user has the SELECT privilege.
This is the query the JDBC driver is issuing:
select relname, nspname, relkind
from pg_catalog.pg_class c, pg_catalog.pg_namespace n
where relkind in ('r', 'v')
and nspname not in ('pg_catalog', 'information_schema', 'pg_toast', 'pg_temp_1')
and n.oid = relnamespace
order by nspname, relname
Not only is this not taking into account the user’s SELECT privilege but it completely excludes materialized views!
Now, I know that your source code provides for this under specific conditions:
IE:
if (!list_some)
{
if (CC_accessible_only(conn))
strcat(tables_query, " and has_table_privilege(c.oid, 'select')");
}
But this is an incomplete solution and it would not be desirable to present a list of tables to a user that they have no hope of accessing.
I propose that someone change this permanently (under all conditions) to something that makes more sense like this:
select c.relname, n.nspname, c.relkind
from pg_catalog.pg_class c, pg_catalog.pg_namespace n
where c.relkind in ('r', 'v', 'm')
and n.nspname not in ('pg_catalog', 'information_schema', 'pg_toast', 'pg_temp_1')
and has_table_privilege(c.oid, 'select')
and n.oid = c.relnamespace
order by n.nspname, c.relname
Note that I have added an extra condition for relkind (‘m’ for materialized views) and also an extra check (has_table_privilege).
This would help our problem and provide a solution for all Tableau users as Tableau is recommending creating dynamic views that do not perform well as a work-around (which suggests they don’t know the solution to this is tied to the driver).
Let me know if this would be possible. While Hiroshi’s solution below was appreciated, I don’t think it’s workable for us to require our customer base to make changes as to how the driver is engaged within Tableau.
Regards,
Fernando Luna
Fernando.Luna@Tideworks.com<mailto:Fernando.Luna@Tideworks.com>
Senior SDE/Data Engineering
[cid:image001.png@01CF6B5B.9BA017B0]
-----Original Message-----
From: Fernando Luna
Sent: Tuesday, March 29, 2016 8:33 AM
To: Inoue, Hiroshi <h-inoue@dream.email.ne.jp>
Cc: 'pgsql-odbc@postgresql.org' <pgsql-odbc@postgresql.org>
Subject: RE: [ODBC] Question regarding accessing only tables to which the user has access
Hi Hiroshi!
I will definitely give that a shot. Thanks so much for your quick reply!
Fernando Luna
________________________________________
From: Inoue, Hiroshi [h-inoue@dream.email.ne.jp]
Sent: Monday, March 28, 2016 8:49 PM
To: Fernando Luna
Cc: 'pgsql-odbc@postgresql.org'
Subject: Re: [ODBC] Question regarding accessing only tables to which the user has access
Hi Fernando,
On 2016/03/29 2:40, Fernando Luna wrote:
I am using Tableau version 9.2 to connect to a PostgreSQL database (version 9.4). This database resides in a VM running Redhat CentOS and I am connecting from my Windows 7 box using the latest Windows driver found under http://www.postgresql.org/ftp/odbc/versions/msi/<http://www.postgresql.org/ftp/odbc/versions/msi/; . The zipfile name is psqlodbc_09_05_0100-x64.zip<https://ftp.postgresql.org/pub/odbc/versions/msi/psqlodbc_09_05_0100-x64.zip<https://ftp.postgres...;
My question is this. When Tableau connects it retrieves a list of tables/views to use. My problem is that Tableau is listing tables to which the connected user has no privileges and it makes for a poor user experience to allow Tableau to do that in our case. We want to only list those tables/views to which the connected user has at the very least select privileges. At first I thought it was Tableau doing this and after a while I decided to turn on logging on PostgreSQL and found that the following query is issued whenever I connect using Tableau.
select relname, nspname, relkind
from pg_catalog.pg_class c, pg_catalog.pg_namespace n
where relkind in ('r', 'v')
and nspname not in ('pg_catalog', 'information_schema', 'pg_toast', 'pg_temp_1')
and n.oid = relnamespace
order by nspname, relname
I discovered that this query is executed by the postgres odbc driver on connect. I looked at the source code for the latest driver and found this code snippet in info.c:
if (!list_some)
{
if (CC_accessible_only(conn))
strcat(tables_query, " and has_table_privilege(c.oid, 'select')");
}
My question is, how can I get the driver to add this snippet to the query? Please bear in mind that I know nearly nothing about Postgres and ODBC and would appreciate being pointed in the right direction as to how to influence pgsql odbc to issue the query like this:
select relname, nspname, relkind
from pg_catalog.pg_class c, pg_catalog.pg_namespace n
where relkind in ('r', 'v')
and nspname not in ('pg_catalog', 'information_schema', 'pg_toast', 'pg_temp_1')
and has_table_privilege(c.oid, 'select')
and n.oid = relnamespace
order by nspname, relname
Please set the "Extra Opts" option of Advanced Options(Datasource) Page 2 using ODBC Data Source Administrator.
Try to set Extra Opts to 0x10.
regards,
Hiroshi Inoue
Attachments:
image001.jpg (image/jpeg, 3.8K) download
view image
^ permalink raw reply [nested|flat] 8+ messages in thread
* RE: [ODBC] Question regarding accessing only tables to which the user has access
2018-04-23 17:36 RE: [ODBC] Question regarding accessing only tables to which the user has access Fernando Luna <Fernando.Luna@Tideworks.com>
2018-04-24 18:38 ` Re: [ODBC] Question regarding accessing only tables to which the user has access John Kew <jkew@tableau.com>
@ 2018-04-24 18:47 ` Fernando Luna <Fernando.Luna@Tideworks.com>
0 siblings, 0 replies; 8+ messages in thread
From: Fernando Luna @ 2018-04-24 18:47 UTC (permalink / raw)
To: John Kew <jkew@tableau.com>; pgsql-odbc
Hi John:
I'm actually implying that the issue is with the JDBC driver, rather than anything innate to Tableau. I checked with our BI group and they confirmed that when they select Postgres from the list of databases to connect to that it is, in fact, a JDBC driver, which is what I suspected and which prompted my diving into the source code for it.
Listing tables for select grants in other databases seems to be default behavior for some databases and not for others. In the case of Postgres, it should fall to the JDBC driver to manage this rather than a third party tool like Tableau.
At least that's my two cents...
Regards,
Fernando Luna
Fernando.Luna@Tideworks.com<mailto:Fernando.Luna@Tideworks.com>
Senior SDE/Data Engineering
[cid:image001.png@01CF6B5B.9BA017B0]
From: John Kew [mailto:jkew@tableau.com]
Sent: Tuesday, April 24, 2018 11:38 AM
To: Fernando Luna <Fernando.Luna@Tideworks.com>; 'pgsql-odbc@postgresql.org' <pgsql-odbc@postgresql.org>
Cc: Inoue, Hiroshi <h-inoue@dream.email.ne.jp>
Subject: Re: [ODBC] Question regarding accessing only tables to which the user has access
Fernando,
I'm with the connectivity team at Tableau and we are responsible for the postresql connector. First off if you are using Tableau you are probably using ODBC. We do have JDBC implemented, but it isn't turned on for general customers.
Materialized Views
As you have noticed, when connecting to PostgreSQL using ODBC we use SQLTablesW rather than issue a custom query ourselves. In an ideal world we would support materialized views through the information schema but this has not made it into the spec:
https://www.postgresql.org/message-id/3794.1412980686@sss.pgh.pa.us
We actually have a feature open to support this because honestly there are lots of people at Tableau who want to use materialized views as well. To do this we would essentially stop calling SQLTablesW and make a direct query. I'll talk with our team to figure out if this is something we can schedule given that it is probably unlikely that materialized views will be a standard part of the information schema any time soon.
Select Grants
Listing tables for select grants is a little more complicated, but really only for other databases which make use of libpq but have more complicated role models. This requires more consideration, it is not a oft requested feature, and it may have some performance impact on non-postgres libpq compatible databases.
-John
________________________________
From: Fernando Luna <Fernando.Luna@Tideworks.com<mailto:Fernando.Luna@Tideworks.com>>
Sent: Monday, April 23, 2018 10:36:36 AM
To: 'pgsql-odbc@postgresql.org'
Cc: Inoue, Hiroshi
Subject: RE: [ODBC] Question regarding accessing only tables to which the user has access
Hello:
I broached this subject a couple of years ago. Basically, Tableau, the product we use for Business Intelligence uses the Postgres JDBC driver and we were puzzled as to why it seemed to allow users to view tables to which they didn't have permissions on the database. It made for a poor user experience and with some sleuthing I discovered that the query that the JDBC driver uses doesn't seem to take into account whether or not the connecting user has the SELECT privilege.
This is the query the JDBC driver is issuing:
select relname, nspname, relkind
from pg_catalog.pg_class c, pg_catalog.pg_namespace n
where relkind in ('r', 'v')
and nspname not in ('pg_catalog', 'information_schema', 'pg_toast', 'pg_temp_1')
and n.oid = relnamespace
order by nspname, relname
Not only is this not taking into account the user's SELECT privilege but it completely excludes materialized views!
Now, I know that your source code provides for this under specific conditions:
IE:
if (!list_some)
{
if (CC_accessible_only(conn))
strcat(tables_query, " and has_table_privilege(c.oid, 'select')");
}
But this is an incomplete solution and it would not be desirable to present a list of tables to a user that they have no hope of accessing.
I propose that someone change this permanently (under all conditions) to something that makes more sense like this:
select c.relname, n.nspname, c.relkind
from pg_catalog.pg_class c, pg_catalog.pg_namespace n
where c.relkind in ('r', 'v', 'm')
and n.nspname not in ('pg_catalog', 'information_schema', 'pg_toast', 'pg_temp_1')
and has_table_privilege(c.oid, 'select')
and n.oid = c.relnamespace
order by n.nspname, c.relname
Note that I have added an extra condition for relkind ('m' for materialized views) and also an extra check (has_table_privilege).
This would help our problem and provide a solution for all Tableau users as Tableau is recommending creating dynamic views that do not perform well as a work-around (which suggests they don't know the solution to this is tied to the driver).
Let me know if this would be possible. While Hiroshi's solution below was appreciated, I don't think it's workable for us to require our customer base to make changes as to how the driver is engaged within Tableau.
Regards,
Fernando Luna
Fernando.Luna@Tideworks.com<mailto:Fernando.Luna@Tideworks.com>
Senior SDE/Data Engineering
[cid:image001.png@01CF6B5B.9BA017B0]
-----Original Message-----
From: Fernando Luna
Sent: Tuesday, March 29, 2016 8:33 AM
To: Inoue, Hiroshi <h-inoue@dream.email.ne.jp<mailto:h-inoue@dream.email.ne.jp>>
Cc: 'pgsql-odbc@postgresql.org' <pgsql-odbc@postgresql.org<mailto:pgsql-odbc@postgresql.org>>
Subject: RE: [ODBC] Question regarding accessing only tables to which the user has access
Hi Hiroshi!
I will definitely give that a shot. Thanks so much for your quick reply!
Fernando Luna
________________________________________
From: Inoue, Hiroshi [h-inoue@dream.email.ne.jp]
Sent: Monday, March 28, 2016 8:49 PM
To: Fernando Luna
Cc: 'pgsql-odbc@postgresql.org'
Subject: Re: [ODBC] Question regarding accessing only tables to which the user has access
Hi Fernando,
On 2016/03/29 2:40, Fernando Luna wrote:
I am using Tableau version 9.2 to connect to a PostgreSQL database (version 9.4). This database resides in a VM running Redhat CentOS and I am connecting from my Windows 7 box using the latest Windows driver found under http://www.postgresql.org/ftp/odbc/versions/msi/ . The zipfile name is psqlodbc_09_05_0100-x64.zip<https://ftp.postgresql.org/pub/odbc/versions/msi/psqlodbc_09_05_0100-x64.zip;
My question is this. When Tableau connects it retrieves a list of tables/views to use. My problem is that Tableau is listing tables to which the connected user has no privileges and it makes for a poor user experience to allow Tableau to do that in our case. We want to only list those tables/views to which the connected user has at the very least select privileges. At first I thought it was Tableau doing this and after a while I decided to turn on logging on PostgreSQL and found that the following query is issued whenever I connect using Tableau.
select relname, nspname, relkind
from pg_catalog.pg_class c, pg_catalog.pg_namespace n
where relkind in ('r', 'v')
and nspname not in ('pg_catalog', 'information_schema', 'pg_toast', 'pg_temp_1')
and n.oid = relnamespace
order by nspname, relname
I discovered that this query is executed by the postgres odbc driver on connect. I looked at the source code for the latest driver and found this code snippet in info.c:
if (!list_some)
{
if (CC_accessible_only(conn))
strcat(tables_query, " and has_table_privilege(c.oid, 'select')");
}
My question is, how can I get the driver to add this snippet to the query? Please bear in mind that I know nearly nothing about Postgres and ODBC and would appreciate being pointed in the right direction as to how to influence pgsql odbc to issue the query like this:
select relname, nspname, relkind
from pg_catalog.pg_class c, pg_catalog.pg_namespace n
where relkind in ('r', 'v')
and nspname not in ('pg_catalog', 'information_schema', 'pg_toast', 'pg_temp_1')
and has_table_privilege(c.oid, 'select')
and n.oid = relnamespace
order by nspname, relname
Please set the "Extra Opts" option of Advanced Options(Datasource) Page 2 using ODBC Data Source Administrator.
Try to set Extra Opts to 0x10.
regards,
Hiroshi Inoue
Attachments:
image001.jpg (image/jpeg, 3.8K) download
view image
^ permalink raw reply [nested|flat] 8+ messages in thread
end of thread, other threads:[~2018-04-24 18:47 UTC | newest]
Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-03-28 17:40 Question regarding accessing only tables to which the user has access Fernando Luna <Fernando.Luna@Tideworks.com>
2016-03-29 03:10 ` Tsunakawa, Takayuki <tsunakawa.takay@jp.fujitsu.com>
2016-03-29 03:27 ` Fernando Luna <Fernando.Luna@Tideworks.com>
2016-03-29 03:49 ` Inoue, Hiroshi <h-inoue@dream.email.ne.jp>
2016-03-29 15:33 ` Fernando Luna <Fernando.Luna@Tideworks.com>
2018-04-23 17:36 RE: [ODBC] Question regarding accessing only tables to which the user has access Fernando Luna <Fernando.Luna@Tideworks.com>
2018-04-24 18:38 ` John Kew <jkew@tableau.com>
2018-04-24 18:47 ` Fernando Luna <Fernando.Luna@Tideworks.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox