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 1gwPVF-0003rI-HU for pgsql-hackers@arkaria.postgresql.org; Wed, 20 Feb 2019 10:53:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gwPVE-0006wg-9t for pgsql-hackers@arkaria.postgresql.org; Wed, 20 Feb 2019 10:53:24 +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 1gwPT8-0001bO-TK for pgsql-hackers@lists.postgresql.org; Wed, 20 Feb 2019 10:51:14 +0000 Received: from out2-smtp.messagingengine.com ([66.111.4.26]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gwPT6-0002ny-Sp for pgsql-hackers@postgresql.org; Wed, 20 Feb 2019 10:51:14 +0000 Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id 321232312E; Wed, 20 Feb 2019 05:51:11 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Wed, 20 Feb 2019 05:51:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=wskEQM ocpVYh8qSDxHvyo3MLUF0mB4VcMZNjtLn2r2I=; b=E9FilKBJ3hNy0c2QebeHNP /xOUeEDOq1rWzGibZpCmQ+YTXxYXJVbuBkSs6b7E6bof6hCXxpnSKYnemoJnnq7A lrniXe3G2Nt0AyJX/On+R7sI/5Xm6LhhnhrVYm21ssi+wyo1f8w/8MiV/vRDmV2Y oT9hwZcnEWtO692n4Mx5WljvIsrG/lkQYkxJO1EhEXV5M6IBcNVVF2JqEOA7uPKz S6CVLXp+NpVYVZSURdCws3CzJZ1GNvv//sFFyLyjzGPISqK3dmdBaPeMt7DKxZoK Rj5XivqSLJUWZZWWFnHy2sm8/HEB1X68ryhB0aYZFhphfX2QiqF57gsYnXEvH42g == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedutddrtdeigddvtdculddtuddrgedtledrtddtmd cutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfhuthen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepuffhvfhfohfkffgfgggjtgesmhdtreertdefheenucfhrhhomheprfgvthgv rhcugfhishgvnhhtrhgruhhtuceophgvthgvrhdrvghishgvnhhtrhgruhhtsedvnhguqh hurggurhgrnhhtrdgtohhmqeenucffohhmrghinhepvdhnughquhgrughrrghnthdrtgho mhenucfkphepleefrddvgeefrdejvddrudduleenucfrrghrrghmpehmrghilhhfrhhomh epphgvthgvrhdrvghishgvnhhtrhgruhhtsedvnhguqhhurggurhgrnhhtrdgtohhmnecu vehluhhsthgvrhfuihiivgeptd X-ME-Proxy: Received: from april.pezone.net (p5df34877.dip0.t-ipconnect.de [93.243.72.119]) by mail.messagingengine.com (Postfix) with ESMTPA id 0836BE44D4; Wed, 20 Feb 2019 05:51:09 -0500 (EST) Subject: Re: restrict pg_stat_ssl to superuser? From: Peter Eisentraut To: Michael Paquier References: <63117976-d02c-c8e2-3aef-caa31a5ab8d3@2ndquadrant.com> <20190212064007.GN1475@paquier.xyz> <71319f2d-a073-0499-4562-6003e026307e@2ndquadrant.com> <20190218035813.GH15532@paquier.xyz> <1d1bf3a7-955e-ce6b-de99-b900136ca789@2ndquadrant.com> Cc: pgsql-hackers Openpgp: preference=signencrypt Autocrypt: addr=peter.eisentraut@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+85FQGp9580DaeLio7YMFKy2bfEvwQJ/c9xD2QPB+ oSb3V8ueSznXBG5+dyfOsZFRPxceA0wA2rSWZSjxLdKxvyGTj9vsCjaDu13rABEBAAHCwV8E GAEIAAkFAlUUt6kCGwwACgkQoZ8SQ+xBJp+HJhAAxmSTsC5y7p9Zu+nnLpucv/h88oEx985e qWeXzQiwM3pfRZS+PdTH9TyzHK0KOgKoAiubk0vt+BrT91D9d0G5kVQaTctAErGBoMkTaZJT XVEcNphiPzysdSqvprjojMp1y7rG8AP+Xd6m0rE1LRnkRRm8HyI8vdXsuLQPITGWXDLMjaNq AOV3BUnzkgtjMuIYw7SCr+12ZOb5dEKvaG4kjC4kaJ/TLbuBhVANcXkC90yp0AOZLs/cB1Dj OAXno/RUUruJ3r27a+pFv768UAi9QWcdw58yPxreMNMLqAgsS9oTHwHfGNWcB2dJ4UW+GMLJ hTf9TjQ2f+N/sIx5XMQ9pYw6CAJMK29qPx6/ZayrPxf22EXf0D3zTwIEZgwfSkynFVwV25L7 awQq60fifdMYheSxq7GbhpsixmcD+e161cCmLIt75YDt5bQ0B1yf7EmxG8n7pGZAOM6LoNsU fkSldba5XVwh8LuN5mK0nQBELGW6Os4TDq4REggLpfcvFC215zpuo0iCGnmE/Bns4nowqUSP u4tkWL+nxW4qgv8wo8HJ52jd79EJ8iqfIBoidBfy9AIUiEUApGQzWPu6yWcI8fY0rN5D+tc+ Yw1Zt6Mm+huYJpgCRsTcfzEcahnBn521CWcWvhW1ff3KFileFMtNmnBBhMncmRKHphtTKEpN 3jI= Organization: 2ndQuadrant Message-ID: <3018acd9-e5d8-1e85-5ed7-47276cd77569@2ndquadrant.com> Date: Wed, 20 Feb 2019 11:51:08 +0100 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <1d1bf3a7-955e-ce6b-de99-b900136ca789@2ndquadrant.com> Content-Type: multipart/mixed; boundary="------------C4872B86007236D68CC45575" Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk This is a multi-part message in MIME format. --------------C4872B86007236D68CC45575 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit On 2019-02-19 16:57, Peter Eisentraut wrote: > On 2019-02-18 04:58, Michael Paquier wrote: >> On Fri, Feb 15, 2019 at 02:04:59PM +0100, Peter Eisentraut wrote: >>> We could remove default privileges from pg_stat_get_activity(). Would >>> that be a problem? >> >> I don't think so, still I am wondering about the impact that this >> could have for monitoring tools calling it directly as we document >> it.. > > Actually, this approach isn't going to work anyway, because function > permissions in a view are checked as the current user, not the view owner. So here is a patch doing it the "normal" way of nulling out all the rows the user shouldn't see. I haven't found any documentation of these access restrictions in the context of pg_stat_activity. Is there something that I'm not seeing or something that should be added? -- Peter Eisentraut http://www.2ndQuadrant.com/ PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services --------------C4872B86007236D68CC45575 Content-Type: text/plain; charset=UTF-8; x-mac-type="0"; x-mac-creator="0"; name="v1-0001-Hide-other-user-s-pg_stat_ssl-rows.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="v1-0001-Hide-other-user-s-pg_stat_ssl-rows.patch" From e164cc0d7fbd8d1e6de23219eed3dd038f99e557 Mon Sep 17 00:00:00 2001 From: Peter Eisentraut Date: Wed, 20 Feb 2019 11:38:44 +0100 Subject: [PATCH v1] Hide other user's pg_stat_ssl rows Change pg_stat_ssl so that an unprivileged user can only see their own rows; other rows will be all null. This makes the behavior consistent with pg_stat_activity, where information about where the connection came from is also restricted. --- src/backend/utils/adt/pgstatfuncs.c | 73 ++++++++++++++++------------- 1 file changed, 41 insertions(+), 32 deletions(-) diff --git a/src/backend/utils/adt/pgstatfuncs.c b/src/backend/utils/adt/pgstatfuncs.c index b6ba856ebe..69f7265779 100644 --- a/src/backend/utils/adt/pgstatfuncs.c +++ b/src/backend/utils/adt/pgstatfuncs.c @@ -645,38 +645,6 @@ pg_stat_get_activity(PG_FUNCTION_ARGS) else nulls[16] = true; - if (beentry->st_ssl) - { - values[18] = BoolGetDatum(true); /* ssl */ - values[19] = CStringGetTextDatum(beentry->st_sslstatus->ssl_version); - values[20] = CStringGetTextDatum(beentry->st_sslstatus->ssl_cipher); - values[21] = Int32GetDatum(beentry->st_sslstatus->ssl_bits); - values[22] = BoolGetDatum(beentry->st_sslstatus->ssl_compression); - - if (beentry->st_sslstatus->ssl_client_dn[0]) - values[23] = CStringGetTextDatum(beentry->st_sslstatus->ssl_client_dn); - else - nulls[23] = true; - - if (beentry->st_sslstatus->ssl_client_serial[0]) - values[24] = DirectFunctionCall3(numeric_in, - CStringGetDatum(beentry->st_sslstatus->ssl_client_serial), - ObjectIdGetDatum(InvalidOid), - Int32GetDatum(-1)); - else - nulls[24] = true; - - if (beentry->st_sslstatus->ssl_issuer_dn[0]) - values[25] = CStringGetTextDatum(beentry->st_sslstatus->ssl_issuer_dn); - else - nulls[25] = true; - } - else - { - values[18] = BoolGetDatum(false); /* ssl */ - nulls[19] = nulls[20] = nulls[21] = nulls[22] = nulls[23] = nulls[24] = nulls[25] = true; - } - /* Values only available to role member or pg_read_all_stats */ if (has_privs_of_role(GetUserId(), beentry->st_userid) || is_member_of_role(GetUserId(), DEFAULT_ROLE_READ_ALL_STATS)) @@ -854,6 +822,39 @@ pg_stat_get_activity(PG_FUNCTION_ARGS) else values[17] = CStringGetTextDatum(pgstat_get_backend_desc(beentry->st_backendType)); + + /* SSL information */ + if (beentry->st_ssl) + { + values[18] = BoolGetDatum(true); /* ssl */ + values[19] = CStringGetTextDatum(beentry->st_sslstatus->ssl_version); + values[20] = CStringGetTextDatum(beentry->st_sslstatus->ssl_cipher); + values[21] = Int32GetDatum(beentry->st_sslstatus->ssl_bits); + values[22] = BoolGetDatum(beentry->st_sslstatus->ssl_compression); + + if (beentry->st_sslstatus->ssl_client_dn[0]) + values[23] = CStringGetTextDatum(beentry->st_sslstatus->ssl_client_dn); + else + nulls[23] = true; + + if (beentry->st_sslstatus->ssl_client_serial[0]) + values[24] = DirectFunctionCall3(numeric_in, + CStringGetDatum(beentry->st_sslstatus->ssl_client_serial), + ObjectIdGetDatum(InvalidOid), + Int32GetDatum(-1)); + else + nulls[24] = true; + + if (beentry->st_sslstatus->ssl_issuer_dn[0]) + values[25] = CStringGetTextDatum(beentry->st_sslstatus->ssl_issuer_dn); + else + nulls[25] = true; + } + else + { + values[18] = BoolGetDatum(false); /* ssl */ + nulls[19] = nulls[20] = nulls[21] = nulls[22] = nulls[23] = nulls[24] = nulls[25] = true; + } } else { @@ -870,6 +871,14 @@ pg_stat_get_activity(PG_FUNCTION_ARGS) nulls[13] = true; nulls[14] = true; nulls[17] = true; + nulls[18] = true; + nulls[19] = true; + nulls[20] = true; + nulls[21] = true; + nulls[22] = true; + nulls[23] = true; + nulls[24] = true; + nulls[25] = true; } tuplestore_putvalues(tupstore, tupdesc, values, nulls); base-commit: 56fadbedbd2f697400b89e7b767cfa4ec67932d6 -- 2.20.1 --------------C4872B86007236D68CC45575--