Rob*_*low 4 postgresql privileges roles
我只是在学习 PostgreSQL。每次我创建用户时,他们似乎都拥有在任何数据库中执行任何操作的完全权限:
$ sudo useradd fool # create the user "fool" in the system
# And in postgresql, as restrictively as possible
$ sudo -u postgres createuser fool --no-superuser --no-createdb --no-createrole --no-inherit
$ sudo -u fool psql postgres # but it can still connect to the "postgres" db
postgres=> drop table ids; # and delete tables
DROP TABLE
Run Code Online (Sandbox Code Playgroud)
我试图创建通过用户的create userPostgreSQL的命令,而不是命令行工具,但它有完全一样的效果。
如何创建仅有权访问其自己的数据库的用户?还是我必须在创建用户后专门撤销所有权限?'因为从安全角度来看这有点糟糕 - 很容易不小心忘记(或只是不知道这是必要的)撤销新用户的权限。
所有角色都是伪角色的“成员” PUBLIC。并且默认PUBLIC有很多权限。我的做法是从PUBLIC我需要的地方撤消所有权限,并为特定角色授予各种组合。最近添加的内容对此有所帮助 - ALTER DEFAULT PRIVILEGES。另一种不太灵活但更简单的方法是CONNECT特权。