首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何禁用postgrest查询的匿名执行

如何禁用postgrest查询的匿名执行
EN

Stack Overflow用户
提问于 2021-12-25 05:19:29
回答 1查看 488关注 0票数 1

Postgrest是用于postgreeSQL数据库的rest。我使用postgrest v9.0.0的配置如下:

代码语言:javascript
复制
db-uri = "postgres://remote_worker:1HyiYai@localhost:5432/myDb"
db-schema = "public"
db-anon-role = "remote_worker"
jwt-secret = "1HyiYaiMTAAJ1pluZnBtAMnTUH19E3gg"
db-pool = 10
db-pool-timeout = 10
server-host = "!4"
server-port = 3000

我假设如果我在配置中输入 jwt秘密参数,它将自动导致只有jwt授权才能工作。

但是,我可以在没有授权的情况下提出请求,甚至只需输入浏览器-> http://localhost:3000/myTable ?Id=eq.2。或者在命令行-> curl http://localhost:3000/Kits

同时,当我使用授权参数发出请求时,例如curl http://localhost:3000/Kits -H“授权:承载-H”时,只有在令牌正确的情况下请求才会传递。

如何禁用请求的匿名执行?

EN

回答 1

Stack Overflow用户

发布于 2022-01-14 14:55:29

当您不使用jwt令牌时,所使用的角色总是db-anon-角色。因此,根据您的数据库设置,此角色可以对架构进行读取访问,并显示查询的响应。

如果您只想拥有授权用户,您需要在DB上创建一个新用户,删除db-anon用户的模式上的权限,只允许新用户在模式上使用。

以下postgres设置应该可以工作:

代码语言:javascript
复制
create role web_anon nologin;
create role authenticator
grant web_anon to authenticator;

create role rest_api nologin;
grant rest_api to authenticator;

create database "mydb" with owner rest_api

会议结束后:

代码语言:javascript
复制
db-uri = "postgres://authenticator:omni123@localhost:5432/mydb"
db-schema = "public"
db-anon-role = "web_anon"

如果在jwt中添加“角色”rest_api,则默认用户https://postgrest.org/en/stable/tutorials/tut1.html#tut1无法访问mybd请求,如postgrest https://postgrest.org/en/stable/tutorials/tut1.html#tut1文档中所述

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70478142

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档