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 1hFb5X-0006I9-0s for pgsql-general@arkaria.postgresql.org; Sun, 14 Apr 2019 09:06:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hFb5T-0008Cg-1S for pgsql-general@arkaria.postgresql.org; Sun, 14 Apr 2019 09:06:07 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hFb5S-0007yq-Ip for pgsql-general@lists.postgresql.org; Sun, 14 Apr 2019 09:06:06 +0000 Received: from mail.hjp.at ([212.17.106.138] helo=rorschach.hjp.at) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hFb5H-0000Or-2O for pgsql-general@lists.postgresql.org; Sun, 14 Apr 2019 09:06:04 +0000 Received: by rorschach.hjp.at (Postfix, from userid 1000) id 7986727B0; Sun, 14 Apr 2019 11:05:52 +0200 (CEST) Date: Sun, 14 Apr 2019 11:05:52 +0200 From: "Peter J. Holzer" To: pgsql-general@lists.postgresql.org Subject: Re: Trigger when user logs in Message-ID: <20190414090552.gopz6g2i3l2fruxm@hjp.at> References: <21272.1555035161@sss.pgh.pa.us> <22830.1555037562@sss.pgh.pa.us> <46D55D2C-5496-4867-9B87-3D865D71BCD2@amazon.com> <6f77e98b-49f3-ecaa-f9d4-ef699999143a@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="amzkkmuke4fqrcc4" Content-Disposition: inline In-Reply-To: <6f77e98b-49f3-ecaa-f9d4-ef699999143a@gmail.com> User-Agent: NeoMutt/20170113 (1.7.2) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --amzkkmuke4fqrcc4 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2019-04-13 22:22:16 -0500, Ron wrote: > In our case, another looming Auditor requirement is to be able to instant= ly > kick off -- or at least send a warning email -- when certain roles log in > from unapproved IP addresses or programs.=A0 For example, service accounts > should only be able to log in from IP addresses and certain applications.= =A0 > Humans logging in via service accounts using pgAdmin should, for example,= be > instantly kicked off. If you want to prevent a user from logging in (which is functionally equivalent but a bit stronger than "instantly kick off"), then this is definitely something that could and should be implemented via PAM (I'm not sure what information is passed to PAM, so you might get the IP address but not the application name (the latter can't be trusted anyway), for example). If you just want to send an email, I would just monitor the logs. Just run a cronjob every minute that checks for suspicious activity. Or if you collect your logfiles in something like ELKS (you probably want to do that if you have auditing requirements, you can probably configure that to send notifications. If the "instantly kick off" doesn't have to be really instantly, you could also monitor pg_stat_activity every second or so and terminate any suspicious session. But note that this rather insecure: A session which lasts for much less than a second has a good chance of flying under the radar. hp --=20 _ | Peter J. Holzer | we build much bigger, better disasters now |_|_) | | because we have much more sophisticated | | | hjp@hjp.at | management tools. __/ | http://www.hjp.at/ | -- Ross Anderson --amzkkmuke4fqrcc4 Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAlyy9+sACgkQ8g5IURL+ KF08kQ//T9jdeslPJAuEN3hgSLNRvbp2W3Oy8x7blpoP7I02XYnLpnQlskPcEz8H YgCAaZe8U4C6IlHclih3aGNvC/Q5AhbxQ6PKZUFLKcua6/KdNpDjSLp2gtwg3cT4 kW7U2QrtDWI26rdMJKCx34rnLDYQNcobBSrecMcSwUGm0ksLXvRvwx1nAZt3gPzy 5XF8JGpA0vuWpKp0iCgbWRMQYi3oaHsxbcdKdleYrUirJkaGKuzXIHlgSrZ+5kP5 z6l45hOJJmhZSbSCGNuMbQVV9MpNCda+ICvWHtKzKdtPN3ea1dCogrSnzaRH0a6t YOCJTb/lFW4+geIonRTxQfPvU4DKtWp8z5/qCKIiQYlaJ0poMlSlgLX4nMZhp4LC 0x05NdirxAdUGp/tREJgkJGKDGjXH4LCdst7hihh1ialVuUM41c2k1tkMY+/ZNqL XEroiEDe114aMcgcpFSEbPK3ocNwznArikvJ958HYoQB6f9sAd0ZKGadxVSn13Fo MG+4MniH4G9vFOXvyf3aNbpLFVy2XhTxfdr9iyTvgi+zHGAc8qD0OEsrvu8ItpDG q3IyndtavyC7HJHisVtwjAgoZAjQ6+d6tPPEL+4bkEs53yok4FVr3gz9H4pBRMA7 VqNYnumTjyn/PAuf9ude9pNqleXHGfPYWClTt85SWqcl7FQizQU= =pVo/ -----END PGP SIGNATURE----- --amzkkmuke4fqrcc4--