Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l8msV-0007Pg-Hd for pgsql-docs@arkaria.postgresql.org; Sun, 07 Feb 2021 16:25:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1l8msU-0003oR-76 for pgsql-docs@arkaria.postgresql.org; Sun, 07 Feb 2021 16:25:38 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l8msU-0003oK-1E for pgsql-docs@lists.postgresql.org; Sun, 07 Feb 2021 16:25:38 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1l8msS-0002CF-5F for pgsql-docs@lists.postgresql.org; Sun, 07 Feb 2021 16:25:37 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 117GPYqW443849; Sun, 7 Feb 2021 11:25:34 -0500 From: Tom Lane To: "David G. Johnston" cc: "samantaswarnava1@gmail.com" , "pgsql-docs@lists.postgresql.org" Subject: Re: Small correction in chown command to set the owner of the pgsql data dir correctly In-reply-to: References: <161268042200.663.5503825431641757282@wrigleys.postgresql.org> Comments: In-reply-to "David G. Johnston" message dated "Sun, 07 Feb 2021 08:32:13 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <443847.1612715134.1@sss.pgh.pa.us> Date: Sun, 07 Feb 2021 11:25:34 -0500 Message-ID: <443848.1612715134@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk "David G. Johnston" writes: > On Saturday, February 6, 2021, PG Doc comments form > wrote: >> "root# mkdir /usr/local/pgsql >> root# chown postgres /usr/local/pgsql >> root# su postgres >> postgres$ initdb -D /usr/local/pgsql/data" >> If these steps are followed then it still fails to initialize the DB as >> chown only gives ownership to the pgsql directory but not the child >> directories under pgsql, > If you follow those four steps exclusively then at the fourth step there > are no child directories since step one created the pgsql directory and > neither step two nor three created any other directories. Yeah. The OP must have followed some other process in order to get to >> fixing permissions on existing directory /usr/local/pgsql/data ... initdb: >> error: could not change permissions of directory "/usr/local/pgsql/data": >> Operation not permitted" More to the point, it seems to me that recommending "chown -R" on the *parent* directory is not merely unsafe but an actual security hole. There are plenty of scenarios where the data directory's parent ought not be owned by the postgres user, and any other child directories even less so. An example is where the parent is a filesystem mount point. (Admittedly, the manual does suggest adding an intermediate level of postgres-owned directory in such a case, but lots of people don't bother.) If we're going to have people picking and choosing which parts of that script they're going to follow exactly, having a step in it that's as dangerous as "chown -R" just seems like a really bad idea. regards, tom lane