Postgrest是用于postgreeSQL数据库的rest。我使用postgrest v9.0.0的配置如下:
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”时,只有在令牌正确的情况下请求才会传递。
如何禁用请求的匿名执行?
发布于 2022-01-14 14:55:29
当您不使用jwt令牌时,所使用的角色总是db-anon-角色。因此,根据您的数据库设置,此角色可以对架构进行读取访问,并显示查询的响应。
如果您只想拥有授权用户,您需要在DB上创建一个新用户,删除db-anon用户的模式上的权限,只允许新用户在模式上使用。
以下postgres设置应该可以工作:
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会议结束后:
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文档中所述
https://stackoverflow.com/questions/70478142
复制相似问题