将 Postgres 超级用户限制为仅限本地连接

425*_*esp 6 postgresql authentication

我有一个包含多个用户的数据库:foobarsuper。我正在考虑pg_hba.conf锁定访问权限。

我希望允许foobar能够通过密码身份验证从任何 IP 进行连接。或者在本地使用信任身份验证。

我想允许super只能通过信任身份验证在本地登录。切勿来自非本地地址。

我就是从这个开始的。

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# Allow everything if you're on the same machine.
local   all             all                                     trust
host    all             all             127.0.0.1/32            trust
Run Code Online (Sandbox Code Playgroud)

但是,然后我陷入困境,因为我不知道如何说“所有用户,除了超级用户”。我正在寻找这样的东西。

host    all             not_super       all                     md5
Run Code Online (Sandbox Code Playgroud)

我认为我可以采取的一种方法是列出foobar明确。但是,我想知道是否还有其他方法。

host    all             foo             all                     md5
host    all             bar             all                     md5
Run Code Online (Sandbox Code Playgroud)

Phi*_* W. 3

pg_hba.conf 的处理在第一个匹配规则处停止,因此将您的超级用户放在第一位 - 仅限本地,信任 - 然后是其他人的规则。

host  all  super  127.0.0.1/32  trust   # super user, local only - trust
host  all  super  0.0.0.0/0     reject  # super user, non-local - reject
host  all  all    0.0.0.0/0     md5     # All other users, anywhere - password
Run Code Online (Sandbox Code Playgroud)

在我看来,这些地址规范太宽泛了。
您应该安排定义您的用户必须位于其中才能连接到这些数据库的网络子网。