pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Christian Ramseyer <rc@networkz.ch>
To: Guillaume Lelarge <guillaume@lelarge.info>
To: ken.l.wolff@lmco.com
Cc: pgsql-generallists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: Lock Postgres account after X number of failed logins?
Date: Thu, 7 May 2020 19:01:47 +0200
Message-ID: <cec31a7c-b16b-d746-711d-1e2cc0b02135@networkz.ch> (raw)
In-Reply-To: <CAECtzeV4cxGGA2J6zizkVR1boo_9DeirLTrbT1i-_jc=MMhPZg@mail.gmail.com>
References: <61463e206b7c4c0ca17b03a59e890b78@lmco.com>
	<80ee9b57-efea-9623-9107-f6c154391929@networkz.ch>
	<CAECtzeV4cxGGA2J6zizkVR1boo_9DeirLTrbT1i-_jc=MMhPZg@mail.gmail.com>



On 06.05.20 13:48, Guillaume Lelarge wrote:
> Le mer. 6 mai 2020 à 04:18, Christian Ramseyer <rc@networkz.ch
> <mailto:rc@networkz.ch>> a écrit :
> 
>     Here is a quick, rough example with still some blanks to fill in - I put
>     it on github for readability:
>     <https://gist.github.com/rc9000/fd1be13b5c8820f63d982d0bf8154db1;
> 
>     The main blanks are in the postgres-action.conf section. The called
>     scripts in /usr/local/bin would need to be written. It can be as simple
>     as "psql -c alter role xxx nologin", but you might add some features
>     like connecting to the primary server if fail2ban triggered on the
>     standby. Also I'm not sure if setting nologin is the best way to disable
>     an account, but I'm sure somebody on here could tell you.
> 
> 
> I already knew about fail2ban, but didn't know it could be set up this
> way. That's pretty impressive. I've just finished testing your config
> files, and it works really well (well, when you finally get rid of the
> selinux permission errors :) ). Anyway, thanks a lot for sharing this.
> 

Thanks for trying it out and the kind words, Guillaume & Ken !

There are some rough corners, I think to make it useful we would need to
do at least:

1. Write reasonable scripts for account locking/unlocking

2. Currently the lockout will also be executed for non-existing user
names and thus make the DOS worse, so we'd need a smart solution for
that (config file with valid users, or cached queries into PG from time
to time to get the existing users, or just being smarter on the log
parsing DETAILS line)

3. Examples how to combine with
https://www.postgresql.org/docs/current/auth-delay.html and/or firewall
drops, so that an attacker gets slowed down. Even if the account is
locked already, the system will still be harmed otherwise.


I'm happy to host this project if it helps enterprise adaption of
Postgres. I've converted the gist into an acutal repository, and you're
all very welcome to become contributors:
https://github.com/rc9000/postgres-fail2ban-lockout

Cheers
Christian


-- 
Christian Ramseyer, netnea ag
Network Management. Security. OpenSource.
https://www.netnea.com








view thread (20+ messages)

Message-ID: <cec31a7c-b16b-d746-711d-1e2cc0b02135@networkz.ch>
Permalink:  ../cec31a7c-b16b-d746-711d-1e2cc0b02135@networkz.ch/
Also on:    postgresql.org/message-id/cec31a7c-b16b-d746-711d-1e2cc0b02135@networkz.ch

 · 

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: rc@networkz.ch, guillaume@lelarge.info, ken.l.wolff@lmco.com
  Subject: Re: Lock Postgres account after X number of failed logins?
  In-Reply-To: <cec31a7c-b16b-d746-711d-1e2cc0b02135@networkz.ch>
  References: <61463e206b7c4c0ca17b03a59e890b78@lmco.com> <80ee9b57-efea-9623-9107-f6c154391929@networkz.ch> <CAECtzeV4cxGGA2J6zizkVR1boo_9DeirLTrbT1i-_jc=MMhPZg@mail.gmail.com> <cec31a7c-b16b-d746-711d-1e2cc0b02135@networkz.ch>

* 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