pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Peter J. Holzer <hjp-pgsql@hjp.at>
To: pgsql-general@lists.postgresql.org
Subject: Re: Trigger when user logs in
Date: Sun, 14 Apr 2019 11:05:52 +0200
Message-ID: <20190414090552.gopz6g2i3l2fruxm@hjp.at> (raw)
In-Reply-To: <6f77e98b-49f3-ecaa-f9d4-ef699999143a@gmail.com>
References: <eb44b902-9c08-8489-7d32-79d889d9e229@gmail.com>
	<21272.1555035161@sss.pgh.pa.us>
	<d0b376b1-dedf-64c7-8d00-8aaa132177d4@gmail.com>
	<22830.1555037562@sss.pgh.pa.us>
	<46D55D2C-5496-4867-9B87-3D865D71BCD2@amazon.com>
	<6f77e98b-49f3-ecaa-f9d4-ef699999143a@gmail.com>

On 2019-04-13 22:22:16 -0500, Ron wrote:
> In our case, another looming Auditor requirement is to be able to instantly
> kick off -- or at least send a warning email -- when certain roles log in
> from unapproved IP addresses or programs.  For example, service accounts
> should only be able to log in from IP addresses and certain applications. 
> 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

-- 
   _  | 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 <https://www.edge.org/;

Attachments:

  signature.asc (application/pgp-signature, 832B) download

view thread (12+ messages)  latest in thread

Message-ID: <20190414090552.gopz6g2i3l2fruxm@hjp.at>
Permalink:  ../20190414090552.gopz6g2i3l2fruxm@hjp.at/
Also on:    postgresql.org/message-id/20190414090552.gopz6g2i3l2fruxm@hjp.at

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: hjp-pgsql@hjp.at
  Subject: Re: Trigger when user logs in
  In-Reply-To: <20190414090552.gopz6g2i3l2fruxm@hjp.at>
  References: <eb44b902-9c08-8489-7d32-79d889d9e229@gmail.com> <21272.1555035161@sss.pgh.pa.us> <d0b376b1-dedf-64c7-8d00-8aaa132177d4@gmail.com> <22830.1555037562@sss.pgh.pa.us> <46D55D2C-5496-4867-9B87-3D865D71BCD2@amazon.com> <6f77e98b-49f3-ecaa-f9d4-ef699999143a@gmail.com> <20190414090552.gopz6g2i3l2fruxm@hjp.at>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox