2013-12-08 23 views
2

我只是在學習PostgreSQL。我每次創建用戶,他們似乎有充分的權限,在任何數據庫中做任何事情: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 

我試圖創建用戶通過the create user PostgreSQL command而不是command-line tool但它有完全一樣的效果。

如何創建只有權訪問自己的數據庫的用戶?或者,在創建用戶之後是否必須專門撤消所有權限? '因爲從安全角度來說這很有吸引力 - 很容易意外忘記(或者只是不知道它是否有必要)撤銷新用戶的權限。

+3

所有角色都是僞角色「PUBLIC」的「成員」。默認情況下'PUBLIC'有很多權限。我的做法是從我需要的'PUBLIC'撤銷所有特權,並將各種組合授予特定角色。最近的補充幫助 - ['ALTER DEFAULT PRIVILEGES'](http://www.postgresql.org/docs/current/static/sql-alterdefaultprivileges.html)。另一種不那麼靈活但更容易的方法是['CONNECT'](http://www.postgresql.org/docs/current/static/sql-grant.html)特權。 –

+0

其實我只是發現這個重複的問題(oops):http://stackoverflow.com/questions/6884020/why-new-user-in-postgresql-can-connect-to-all-databases –

+0

@ MilenA.Radev do you知道一篇文章可以引導我設置默認角色和權限,以便在創建新用戶時可以完全訪問他們自己的數據庫,但甚至無法連接到其他任何人? –

回答

3

所有角色都是僞角色PUBLIC的「成員」。並且默認PUBLIC有很多權限。我的做法是從PUBLIC中撤銷我需要的所有特權,並將各種組合授予特定角色。最近的一個補充幫助那 - ALTER DEFAULT PRIVILEGES。另一個不太靈活但更容易的方法是CONNECT特權。

相關問題