pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
`pg_ls_dir` can query some directories, but not others
3+ messages / 2 participants
[nested] [flat]

* `pg_ls_dir` can query some directories, but not others
@ 2019-11-13 22:32  Brennan Vincent <brennan@umanwizard.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Brennan Vincent @ 2019-11-13 22:32 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

Copying here a question I asked on StackOverflow:
https://stackoverflow.com/questions/58846076

=======================================

On my system, `/home` and `/etc` have exactly the same permissions:

```
$ 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
```

However, Postgres can read one, but not the other:

```
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
```

Even though the user the DB is running as can, in fact, run `ls /home`:
```
$ sudo -u postgres ls /home > /dev/null && echo "ls succeeded"
ls succeeded
```

What is going on?

My postgres version is 11.5, running on Arch Linux.







^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: `pg_ls_dir` can query some directories, but not others
@ 2019-11-13 23:33  Adrian Klaver <adrian.klaver@aklaver.com>
  parent: Brennan Vincent <brennan@umanwizard.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Adrian Klaver @ 2019-11-13 23:33 UTC (permalink / raw)
  To: Brennan Vincent <brennan@umanwizard.com>; pgsql-general@lists.postgresql.org

On 11/13/19 2:32 PM, Brennan Vincent wrote:
> Copying here a question I asked on StackOverflow:
> https://stackoverflow.com/questions/58846076
> 
> =======================================
> 
> On my system, `/home` and `/etc` have exactly the same permissions:
> 
> ```
> $ 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
> ```
> 
> However, Postgres can read one, but not the other:
> 
> ```
> 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
> ```
> 
> Even though the user the DB is running as can, in fact, run `ls /home`:
> ```
> $ sudo -u postgres ls /home > /dev/null && echo "ls succeeded"
> ls succeeded
> ```
> 
> What is going on?

Works here(Postgres 11.5, openSuSE Leap 15):

drwxr-xr-x 149 root root  12288 Nov 13 15:24 etc/
drwxr-xr-x   4 root root   4096 Jun  7  2018 home/

production_(postgres)# select count(*) from (select pg_ls_dir('/etc')) a;
  count
-------
    339
(1 row)

production_(postgres)# select count(*) from (select pg_ls_dir('/home')) a;
  count
-------
      2
(1 row)

SELinux (or equivalent) in play?


> 
> My postgres version is 11.5, running on Arch Linux.
> 
> 
> 
> 


-- 
Adrian Klaver
adrian.klaver@aklaver.com





^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: `pg_ls_dir` can query some directories, but not others
@ 2019-11-14 00:41  Brennan Vincent <brennan@umanwizard.com>
  parent: Adrian Klaver <adrian.klaver@aklaver.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Brennan Vincent @ 2019-11-14 00:41 UTC (permalink / raw)
  To: Adrian Klaver <adrian.klaver@aklaver.com>; +Cc: pgsql-general@lists.postgresql.org



> On Nov 13, 2019, at 6:33 PM, Adrian Klaver <adrian.klaver@aklaver.com> wrote:
> 
> On 11/13/19 2:32 PM, Brennan Vincent wrote:
>> Copying here a question I asked on StackOverflow:
>> https://stackoverflow.com/questions/58846076
>> =======================================
>> On my system, `/home` and `/etc` have exactly the same permissions:
>> ```
>> $ 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
>> ```
>> However, Postgres can read one, but not the other:
>> ```
>> 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
>> ```
>> Even though the user the DB is running as can, in fact, run `ls /home`:
>> ```
>> $ sudo -u postgres ls /home > /dev/null && echo "ls succeeded"
>> ls succeeded
>> ```
>> What is going on?
> 
> Works here(Postgres 11.5, openSuSE Leap 15):
> 
> drwxr-xr-x 149 root root  12288 Nov 13 15:24 etc/
> drwxr-xr-x   4 root root   4096 Jun  7  2018 home/
> 
> production_(postgres)# select count(*) from (select pg_ls_dir('/etc')) a;
> count
> -------
>   339
> (1 row)
> 
> production_(postgres)# select count(*) from (select pg_ls_dir('/home')) a;
> count
> -------
>     2
> (1 row)
> 
> SELinux (or equivalent) in play?
> 
> 
>> My postgres version is 11.5, running on Arch Linux.
> 
> 
> -- 
> Adrian Klaver
> adrian.klaver@aklaver.com

Mystery solved: Arch’s bundled systemd service file for postgresql sets `ProtectHome=true`, which runs the daemon in a file system namespace that blocks access to /home .





^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2019-11-14 00:41 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-11-13 22:32 `pg_ls_dir` can query some directories, but not others Brennan Vincent <brennan@umanwizard.com>
2019-11-13 23:33 ` Adrian Klaver <adrian.klaver@aklaver.com>
2019-11-14 00:41   ` Brennan Vincent <brennan@umanwizard.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox