Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.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
PostgreSQL/PostGraphile行权限不起作用_Postgresql_Permissions_Postgraphql - Fatal编程技术网

PostgreSQL/PostGraphile行权限不起作用

PostgreSQL/PostGraphile行权限不起作用,postgresql,permissions,postgraphql,Postgresql,Permissions,Postgraphql,我正在尝试使用PostGraphile(以前称为PostGraphQL)设置GraphQL服务器,但我无法使行权限正常工作,这意味着我会不断收到权限被拒绝的消息,尽管它应该可以正常工作。这是我的模式: create function app.current_user() returns app.profile as $$ select * from app.profile where id = current_setting('jwt.claims.person_id')::inte

我正在尝试使用PostGraphile(以前称为PostGraphQL)设置GraphQL服务器,但我无法使行权限正常工作,这意味着我会不断收到权限被拒绝的消息,尽管它应该可以正常工作。这是我的模式:

create function app.current_user() returns app.profile as $$
  select *
  from app.profile
  where id = current_setting('jwt.claims.person_id')::integer
$$ language sql stable;

comment on function app.current_user() is 'Gets the person who was identified by our JWT.';

grant select (name,about,created_at,updated_at) on table app.profile to app_user;
grant update (name,about) on table app.profile to app_user;
alter table app.profile enable row level security;


create policy select_profile on app.profile for select to app_user
  using (id = current_setting('jwt.claims.person_id')::integer);

create policy update_profile on app.profile for update to app_user
  using (id = current_setting('jwt.claims.person_id')::integer);
就我在调试输出中所见,一切正常。我可以进行身份验证,获得一个JWT令牌,当JWT令牌无效时,它会发出一条正确的错误消息,所以这不是问题

我做错了什么,或者如何更紧密地调试正在发生的事情


我正在使用PostGraphile v4和PostgreSQL 10.4,这是我自己发现的问题。事实证明,您必须对该id授予权限,即使您没有选择它,而只是在WHERE部分使用它

因此,在上面的示例中,将其修改为:

将表app.profile上的select(id、name、about、created_at、updated_at)授予app_用户


那么它应该会起作用。

你能更具体地说明什么不起作用吗?它是否允许您更新其他人的数据?(这意味着您正在以超级用户或数据库所有者的身份连接到数据库,这可能会绕过RLS。)它根本不允许您查看任何数据吗?(这意味着jwt.claims.person_id不正确;或者您没有通过jwt将角色设置为
app_user
,或者jwt角色路径设置是正确的。)也许您可以共享您的签名jwt和正在使用的
postgraphile
命令行?您能进一步解释一下吗?您如何授予该id的权限?