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 1ne4OG-0003oH-Bt for pgsql-general@arkaria.postgresql.org; Tue, 12 Apr 2022 00:28:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ne4OE-0008Sk-Ts for pgsql-general@arkaria.postgresql.org; Tue, 12 Apr 2022 00:28:14 +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 1ne4OD-0008Sa-LY for pgsql-general@lists.postgresql.org; Tue, 12 Apr 2022 00:28:14 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ne4OA-0007Il-7r for pgsql-general@lists.postgresql.org; Tue, 12 Apr 2022 00:28:12 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id 51CF15C026D; Mon, 11 Apr 2022 20:28:08 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute4.internal (MEProxy); Mon, 11 Apr 2022 20:28:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm3; t=1649723288; x= 1649809688; bh=FkA9CstMc5mAELVCcEw0gPJzWRpwOLiZ3cPTfxp3vNs=; b=Y vQuufHf8bBv1bqPkmapgJG0rl5hUO9RiOcFBormuVSnXjz5DHvccJoM4//kfTNEZ MokFvjhisqQayhtjq9Z2BnfAV17dERJ/E33I6h/dCISvA11QpVuqkUMRVGipTaUR U0S3iM6k6Om5ZA2azpadHWR3DV2do4ci8UCK6ovcRbdBslf85ds9HqDF3XGMmq2r 7n5B259HaBAXTnl/jAYl1N/2CqZ4p+EUNknx3yW34sD+gQj8sEjeFuj7Z6fD8cRh o4IJPv7/0K3+a/XFMZcsxUGFaCu6wC+7ONPLx0JNPbKlCSP78hip/5IYL5spRvsO TTcNhNYBvtDC05rrNGRew== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:date:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1649723288; x=1649809688; bh=FkA9CstMc5mAELVCcEw0gPJzWRpw OLiZ3cPTfxp3vNs=; b=n4Ussf6zvLKm2K7XofvuvDZYJ7bVUe2c9B+/ggPEeU5r 50NrVwHlER1EmiRT9IZQ3N/9gSaO2A95J01Yg7mcrAYEtvFGOQro/wbfmlvjl8IZ dILy1bWIHDX2uZZRknpjWoty3JnM63DLzSwYQ3QDE5BhEZCJ2bZWQWp2TPjxxu8g ZlfwVfjPfnpVFMlS/ZrkESfbpvvOV3nWX3LPJ286Wixjy1uC+3FjLY7MjiXtNLbC VBMSZeSdKSxny6aYF8cDXTKPH6zvl3J2A4IRKpRBa6ielxBn5ESMxSsE0OVwKif8 RPqCjAqt8IjxAzAtId/0zCcyVttGCWsDW8H3VuTurw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrudekjedgfeehucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepkfffgggfuffvfhfhjggtgfesthekredttdefjeenucfhrhhomheptegurhhi rghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtoh hmqeenucggtffrrghtthgvrhhnpeelkeegjefhkeetheefudevteehiedvudehkeduleet fedvffeuhedtvdegtdeffeenucffohhmrghinhepphhoshhtghhrvghsqhhlrdhorhhgne cuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomheprggurhhi rghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 11 Apr 2022 20:28:07 -0400 (EDT) Message-ID: <50012a11-e91b-48d0-4944-b725d06624d6@aklaver.com> Date: Mon, 11 Apr 2022 17:28:06 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.8.0 Subject: Re: How easy is it to lose permissions in 'public' schema? Content-Language: en-US To: Rob Sargent , "pgsql-generallists.postgresql.org" References: From: Adrian Klaver In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 4/11/22 16:10, Rob Sargent wrote: > I'm using postgres 14 in a database recently brought over from postgres > 10.  (I did not do the bringing over.) > > In my set-up, I partition datasets by schema, create a role per schema > and part of that is this explicit permission granting (from superuser): > > p\g > grant all on all tables in schema base, bulk, sgstemplate to > sgstemplate\p\g > --where sgstemplate is sedded to the real deal by the installer > > there is no explicit 'public' in that set-up and here-to-fore the new > grantee has been able to see into public stuff just fine, in particular > to public functions which rely on getting grantee's version of tables > (replicated in sister schema). > > I've just bumped into this. > > barnard=> select public.genome_threshold_mono('a'::text,'b'::text); > ERROR:  permission denied for schema public > LINE 1: select public.genome_threshold_mono('a'::text,'b'::text); > > I know I haven't intentionally removed 'public' from grantee's purview > and short of the code block above not actually getting run, any guesses > as to how access to 'public' got removed from grantee? I'm going to say someone read this: https://wiki.postgresql.org/wiki/A_Guide_to_CVE-2018-1058:_Protect_Your_Search_Path And did something along the line of this: " Next Steps: How Can I Protect My Databases? Do not allow users to create new objects in the public schema As a superuser, run the following command in all of your databases: REVOKE CREATE ON SCHEMA public FROM PUBLIC; Running REVOKE CREATE ON SCHEMA public FROM PUBLIC; prevents all non-superusers from creating objects in the public schema. This setting will protect a PostgreSQL database from the problem described in CVE-2018-1058. Once this command is run, certain operations could fail within your database. For example, a non-superuser will not be able to create tables or functions anymore with the public schema, which may affect how a user manages application schema migrations. Note that the REVOKE command is more powerful than running DROP SCHEMA public; as pg_dump does not preserve the public schema removal. After running this command, you should strongly consider auditing your public schema to see if any users have created functions that have names similar to ones in the pg_catalog. From the command-line tool (e.g. psql), you can see a list of functions available in the public schema by running: \df public.* To see a full list of functions defined In the pg_catalog schema, please run: \df pg_catalog.* " Probably should take a look at what permissions the functions in public have? > > > I've run those grants specifically naming public and all is well. Do I > need to add that to the installer script? > > > > > > -- Adrian Klaver adrian.klaver@aklaver.com