在我的系统上,/home
和/etc
具有完全相同的权限:
$ ls -ld /home /etc
drwxr-xr-x 67 root root 4096 Nov 13 15:59 /etc
drwxr-xr-x 3 root root 4096 Oct 18 13:45 /home
但是,Postgres可以读取其中一个,而不能读取其他内容:
test=# select count(*) from (select pg_ls_dir('/etc')) a;
count
-------
149
(1 row)
test=# select count(*) from (select pg_ls_dir('/home')) a;
ERROR: could not open directory "/home": Permission denied
即使数据库正在正常运行的用户,实际上也运行ls /home
:
$ sudo -u postgres ls /home > /dev/null && echo "ls succeeded"
ls succeeded
这是怎么回事?
我的postgres版本是11.5,可以在Arch Linux上运行。
答案 0 :(得分:2)
我发现这是因为Arch捆绑的postgresql.service
文件集ProtectHome=true
,导致systemd使用Linux挂接名称空间来阻止postgres进程访问/home
。