Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iV7Cv-00058H-0r for pgsql-general@arkaria.postgresql.org; Thu, 14 Nov 2019 04:58:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iV7Ct-00069O-4e for pgsql-general@arkaria.postgresql.org; Thu, 14 Nov 2019 04:58:11 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iV3DD-0000cm-E8 for pgsql-general@lists.postgresql.org; Thu, 14 Nov 2019 00:42:15 +0000 Received: from smtp.umanwizard.com ([54.203.248.109]) by magus.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iV3DA-0004K2-Iy for pgsql-general@lists.postgresql.org; Thu, 14 Nov 2019 00:42:15 +0000 X-Fes-Encrypted: true X-Fes-Ehlo-Domain: [10.30.91.165] Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.11\)) Subject: Re: `pg_ls_dir` can query some directories, but not others From: Brennan Vincent In-Reply-To: Date: Wed, 13 Nov 2019 19:41:57 -0500 Cc: pgsql-general@lists.postgresql.org Content-Transfer-Encoding: quoted-printable Message-Id: References: <52753F90-45C7-4BE5-BF0A-BEB02B74628F@umanwizard.com> <65AAD7CD-27DA-480E-A691-E530464278F2@umanwizard.com> To: Adrian Klaver X-Mailer: Apple Mail (2.3445.104.11) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk > On Nov 13, 2019, at 6:33 PM, Adrian Klaver = wrote: >=20 > On 11/13/19 2:32 PM, Brennan Vincent wrote: >> Copying here a question I asked on StackOverflow: >> https://stackoverflow.com/questions/58846076 >> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >> 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=3D# select count(*) from (select pg_ls_dir('/etc')) a; >> count >> ------- >> 149 >> (1 row) >> test=3D# 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? >=20 > Works here(Postgres 11.5, openSuSE Leap 15): >=20 > drwxr-xr-x 149 root root 12288 Nov 13 15:24 etc/ > drwxr-xr-x 4 root root 4096 Jun 7 2018 home/ >=20 > production_(postgres)# select count(*) from (select pg_ls_dir('/etc')) = a; > count > ------- > 339 > (1 row) >=20 > production_(postgres)# select count(*) from (select = pg_ls_dir('/home')) a; > count > ------- > 2 > (1 row) >=20 > SELinux (or equivalent) in play? >=20 >=20 >> My postgres version is 11.5, running on Arch Linux. >=20 >=20 > --=20 > Adrian Klaver > adrian.klaver@aklaver.com Mystery solved: Arch=E2=80=99s bundled systemd service file for = postgresql sets `ProtectHome=3Dtrue`, which runs the daemon in a file = system namespace that blocks access to /home .=