Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google cloud platform 对于除BigQuery之外的数据库,如何为DataStudio中的同一行授予多个用户访问权限?_Google Cloud Platform_Google Cloud Sql_Google Data Studio - Fatal编程技术网

Google cloud platform 对于除BigQuery之外的数据库,如何为DataStudio中的同一行授予多个用户访问权限?

Google cloud platform 对于除BigQuery之外的数据库,如何为DataStudio中的同一行授予多个用户访问权限?,google-cloud-platform,google-cloud-sql,google-data-studio,Google Cloud Platform,Google Cloud Sql,Google Data Studio,为了启用行级安全性,我按照建议使用了filterbysemail选项。但我想知道我能不能为多个用户启用对同一行的访问,以及如何启用能够查看所有行的超级用户。例如,如果下面是示例数据,那么我希望根据登录的用户有不同的输出 userId age email A 20 usera@gmail.com B 15 userb@gmail.com C 25 userc@gmail.com Z 30 admin@gmail.com 当登录时 user

为了启用行级安全性,我按照建议使用了
filterbysemail
选项。但我想知道我能不能为多个用户启用对同一行的访问,以及如何启用能够查看所有行的超级用户。例如,如果下面是示例数据,那么我希望根据登录的用户有不同的输出

userId  age email
A       20  usera@gmail.com
B       15  userb@gmail.com
C       25  userc@gmail.com
Z       30  admin@gmail.com
当登录时

userId  age email
A       20  usera@gmail.com
userId  age email
A       20  usera@gmail.com
B       15 userb@gmail.com
userId  age email
A       20  usera@gmail.com
B       15  userb@gmail.com
C       25  userc@gmail.com
Z       30  admin@gmail.com
当B登录时

userId  age email
A       20  usera@gmail.com
userId  age email
A       20  usera@gmail.com
B       15 userb@gmail.com
userId  age email
A       20  usera@gmail.com
B       15  userb@gmail.com
C       25  userc@gmail.com
Z       30  admin@gmail.com
当Z登录时

userId  age email
A       20  usera@gmail.com
userId  age email
A       20  usera@gmail.com
B       15 userb@gmail.com
userId  age email
A       20  usera@gmail.com
B       15  userb@gmail.com
C       25  userc@gmail.com
Z       30  admin@gmail.com

更新1:我正在使用postgres实例进行报告(不是bigQuery),因此使用
@DS\u USER\u EMAIL
的解决方案将不起作用

通过电子邮件进行过滤只会向您提供当前登录用户的电子邮件。您必须使用它来过滤查询。我设计了这样一个简单的测试

with sample as (
  select "a" as userId, 10 as age, "usera@gmail.com" as email
  UNION ALL
  select "b" as userId, 20 as age, "userb@gmail.com" as email
  UNION ALL
  select "c" as userId, 30 as age, "userc@gmail.com" as email
), auth as (
  select "usera@gmail.com" as user, "usera@gmail.com" as permission
  UNION ALL
  select "userb@gmail.com" as user, "usera@gmail.com" as permission
  UNION ALL
  select "userb@gmail.com" as user, "userb@gmail.com" as permission
  UNION ALL
  select "admin@gmail.com" as user, ".*" as permission
)
select * from sample
where REGEXP_CONTAINS(email,(select STRING_AGG(permission,"|") from auth where auth.user = @DS_USER_EMAIL))
我有
样本
表格和您的数据。我创建了一个
auth
表,其中包含用户电子邮件和查看授权之间的链接

在最后一个请求中,我使用正则表达式检查行是否被授权。管理员使用值
*
查看所有数据。另一种是所有行的简单聚合,由管道
|
分隔(或使用正则表达式语言)

编辑

BigQuery的强大之处在于符合SQL2011标准,postgres中的工作查询也类似。对于正则表达式模式使用。看看admin regex模式,它不是常规的regex,但它是有效的

查询可以工作,但不能与Datastudio一起使用,因为
@DS\u USER\u EMAIL
仅与BigQuery一起存在

解决方法是使用。最后一个请求是两个db引擎的混合

with sample as (
SELECT * FROM EXTERNAL_QUERY("gbl-imt-homerider-basguillaueb.us.vertx-postgres", """ select 'a' as userId, 10 as age, 'usera@gmail.com' as email
  UNION ALL
  select 'b' as userId, 20 as age, 'userb@gmail.com' as email
  UNION ALL
  select 'c' as userId, 30 as age, 'userc@gmail.com' as email""")), auth as (
SELECT * FROM EXTERNAL_QUERY("gbl-imt-homerider-basguillaueb.us.vertx-postgres", """ select 'usera@gmail.com' as user, 'usera@gmail.com' as permission
  UNION ALL
  select 'userb@gmail.com' as user, 'usera@gmail.com' as permission
  UNION ALL
  select 'userb@gmail.com' as user, 'userb@gmail.com' as permission
  UNION ALL
  select 'admin@gmail.com' as user, '.*' as permission"""))
select * from sample
where REGEXP_CONTAINS(email,(select STRING_AGG(permission,"|") from auth where auth.user = @DS_USER_EMAIL))

您如何知道用户B可以看到A行和B行?A只有A吗?这些规则在哪里?我将有一个映射表。但至少有一个超级用户可以查看所有数据,即使启用了“电子邮件过滤”。我会有一些电子邮件的列表,如果他们登录,那么他们应该能够看到所有行。有可能吗?虽然这会奏效,但我希望谷歌能更好地实现行级安全。将
IN
子句与
Regex
一起使用可能会降低报表的性能。我意识到您提供的解决方案只适用于BigQuery。在我的例子中,我使用一个googlecloudsqlpostgres实例作为后端数据库。因此,
@DS\u USER\u EMAIL
在那里不起作用。我已经更新了我的问题,添加了缺少的非bigquery解决方案的详细信息。好的,在Postgres中直接使用DS_用户_电子邮件是不可能的,但您仍然可以使用bigquery!!不是最强大的,但它正在工作。我们正在使用postgres作为OLTP,数据量不足以移动到BigQuery,因此希望使用postgres本身为一些报表提供支持。没有移动到BigQuery!BigQuery引擎使用外部连接来查询PostGres中的数据并将其呈现给Datastudio。无移动、无复制、无延迟。只有一个约束:它仅适用于云SQL。如果你把自己的Postgres数据库放在别处,你就不能