pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Christian Ramseyer <rc@networkz.ch>
To: pgsql-general@lists.postgresql.org
To: ken.l.wolff@lmco.com
Subject: Re: Lock Postgres account after X number of failed logins?
Date: Wed, 6 May 2020 04:18:29 +0200
Message-ID: <80ee9b57-efea-9623-9107-f6c154391929@networkz.ch> (raw)
In-Reply-To: <61463e206b7c4c0ca17b03a59e890b78@lmco.com>
References: <61463e206b7c4c0ca17b03a59e890b78@lmco.com>



On 05.05.20 16:13, Wolff, Ken L wrote:
> Hi, everyone.  Wondering if there’s a way in PostgreSQL to automatically
> lock accounts after a number of failed logins (a security requirement
> for my organization).  
> 
> Locking accounts after X number of failed logins is an excellent way to
> defeat brute force attacks, so I’m just wondering if there’s a way to do
> this, other than the aforementioned hook.
> 
>  

Hi Ken

This doesn't seem mentioned in other replies so far: a very "unixy"
approach to bolt this feature onto almost any Linux server process is
the fail2ban (https://github.com/fail2ban/fail2ban) utility. This is a
daemon that reads arbitrary logfiles, and then triggers an action if
some failure condition is seen a number of times.

Typically this will scan the logfile for an IP and on failure add a
temporary firewall rule to block the source, but all of this is
configurable. So in your case you can lock the account instead, and then
decide if you want automatic unlocking after a while, if you want to
drop the IP that tried to login additionally on the firewall as well, etc.

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.

Cheers
Christian

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







view thread (20+ messages)  latest in thread

Message-ID: <80ee9b57-efea-9623-9107-f6c154391929@networkz.ch>
Permalink:  ../80ee9b57-efea-9623-9107-f6c154391929@networkz.ch/
Also on:    postgresql.org/message-id/80ee9b57-efea-9623-9107-f6c154391929@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, ken.l.wolff@lmco.com
  Subject: Re: Lock Postgres account after X number of failed logins?
  In-Reply-To: <80ee9b57-efea-9623-9107-f6c154391929@networkz.ch>
  References: <61463e206b7c4c0ca17b03a59e890b78@lmco.com> <80ee9b57-efea-9623-9107-f6c154391929@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