Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fpV53-0004Gi-50 for pgsql-general@arkaria.postgresql.org; Tue, 14 Aug 2018 08:53:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fpV4y-0004In-JC for pgsql-general@arkaria.postgresql.org; Tue, 14 Aug 2018 08:53:28 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fpV4y-0004Ig-7e for pgsql-general@lists.postgresql.org; Tue, 14 Aug 2018 08:53:28 +0000 Received: from wurzelgnom.a-blast.org ([83.142.84.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fpV4u-0003x7-Uh for pgsql-general@postgresql.org; Tue, 14 Aug 2018 08:53:27 +0000 Received: from tmo-110-73.customers.d1-online.com ([80.187.110.73]:9165 helo=[172.20.10.3]) by wurzelgnom.a-blast.org with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.91 (FreeBSD)) (envelope-from ) id 1fpV4r-000171-SN for pgsql-general@postgresql.org; Tue, 14 Aug 2018 10:53:21 +0200 From: Alvar Freude Content-Type: multipart/signed; boundary="Apple-Mail=_8C41A62E-F969-4ED7-B66C-B4A3212CE964"; protocol="application/pgp-signature"; micalg=pgp-sha256 Mime-Version: 1.0 (Mac OS X Mail 11.5 \(3445.9.1\)) Subject: Best Practices for Extensions, limitations and recommended use for monitoring Message-Id: Date: Tue, 14 Aug 2018 10:53:19 +0200 To: Postgres General X-Mailer: Apple Mail (2.3445.9.1) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --Apple-Mail=_8C41A62E-F969-4ED7-B66C-B4A3212CE964 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Hi all, I have a question about best practices writing PostgreSQL extensions. Is = it OK to write extensions which create users and grant/revoke rights on = the created functions to this users? Is it possible to add options to = CREATE EXTENSION by the extension itself e.g. to make user names = configurable? I=E2=80=99m the author of Posemo (PostgreSQL Secure monitoring), a new = PostgreSQL monitoring framework for monitoring everything in PostgreSQL = in a secure way with an unprivileged user and a simple way to add new = checks. (In development and available here under PostgreSQL license: = https://github.com/alvar-freude/Posemo) The Posemo framework creates for each check a PostgreSQL function with = the SECURITY DEFINER option, which can (only) be called by an = unprivileged user, who only can call the functions and don=E2=80=99t = need access to any data, system table etc. A simple alive check looks like this (the author of the check has only = to write some meta data and the SQL, =E2=80=9CSELECT true=E2=80=9D in = this example here): CREATE FUNCTION posemo.alive() RETURNS boolean LANGUAGE sql STABLE SECURITY DEFINER SET search_path TO posemo, pg_temp AS $$ SELECT true $$; ALTER FUNCTION posemo.alive() OWNER TO posemo_admin; REVOKE ALL ON FUNCTION posemo.alive() FROM PUBLIC; GRANT ALL ON FUNCTION posemo.alive() TO posemo; For more complex checks I create Types, some checks can write something = into tables. CREATE TYPE posemo.transactions_type AS ( database character varying(64), xact_commit bigint, xact_rollback bigint ); ALTER TYPE posemo.transactions_type OWNER TO posemo_admin; At the moment I have an installation program, which creates everything = in a database/schema, which can be chosen by the admin. Of course, = it=E2=80=99s also possible to load a dump. Checks may have some tables = to store some data a (e.g. the writeable check inserts a row and deletes = old rows). The Posemo application calls the functions (depending a local config = file) and builds the result. If it=E2=80=99s easier to use an extension or install Posemo via = installation script depends on the environment. At the moment I think, that it would be a good idea to have (at least) = the option to use Posemo as Extension, but the need for two users is a = possible drawback: can and should the extension create the necessary = users and can a extension change the owner of it=E2=80=99s own objects? Or is this a bad idea because it breaks everything? Changing grants later should be not a good idea, because this is not = part of a dump. What about local checks of the user? It may use the =E2=80=9Crequires=E2=80= =9D parameter and should work without any problems. Thank you for all comments! :-) Ciao Alvar -- Alvar C.H. Freude | https://alvar.a-blast.org | af@alvar-freude.de https://blog.alvar-freude.de/ https://www.wen-waehlen.de/ --Apple-Mail=_8C41A62E-F969-4ED7-B66C-B4A3212CE964 Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP -----BEGIN PGP SIGNATURE----- Comment: GPGTools - http://gpgtools.org iQIzBAEBCAAdFiEEH1odQZsF76aW3d7UXGPWHH/HLscFAltymH8ACgkQXGPWHH/H LsdUlg//dqfSy+8xz1/D0WnDXtsAMHoTjThW6dkvJkXFHIpr/Wmariw7dUUYMfCz h2ky1jokDNAGZ4g3qA1beLuCOcYSnee4n14eVuLLG+yv4z1OMzHazmGllsqZMyH3 UpU1W7xBO3P5+llREYzS73oMqUGbA4p1gDLnkz3hlPVHhk4CTOj6QopPd3NhBomK lpCJMn65JaUPPu7oJ3+QcoUQsitQsp9ITEHA7XCN2gNlHx1zqSohU+pC3xfDH7mX L9ZGQhv6FuWK5vJRuZii2VbTs7ginSxvqq/LhmVYQw3UNe3UHhSWrtk+Q8xhUkx4 lzVNIIFZrVqkCP9zJWaxd9c3eHhiBXJI8gFzgq11ELRN3poGEHIhMI8k5sTpl6OA Y9Q1zkwjn8g/ApEi3liTrW6yqXO908EkN86IEU0B39ThZuLWX7N3I+mfckbeus4o 1alWnQQ7pqvraRvV2M+iUk3W2CAjkwWUV3GNLbKvFVdN+y8A/xXTIds9wbo9BFD/ 1H3vGRAS/F8Fy96PYUcTVCbLwnoAkPUQjc2xZNpEV/or3nSOcWAfnAjfmILucA6F oe9cUcmAIajIo47ZF5CKIXDhaIpA/S0yrSqQm4RL6TeyyXVIyJaWyYS9RY8VG82x xUHRFPSalGpIwOZ1HSQTdUcpKuTYrGoB3uYiQgBHzXKOKteIp9U= =RLDj -----END PGP SIGNATURE----- --Apple-Mail=_8C41A62E-F969-4ED7-B66C-B4A3212CE964--