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 1hFViv-0007nD-PX for pgsql-general@arkaria.postgresql.org; Sun, 14 Apr 2019 03:22:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hFVis-00069E-AF for pgsql-general@arkaria.postgresql.org; Sun, 14 Apr 2019 03:22:26 +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 1hFVir-00063p-RU for pgsql-general@lists.postgresql.org; Sun, 14 Apr 2019 03:22:26 +0000 Received: from mail-ot1-x341.google.com ([2607:f8b0:4864:20::341]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hFVil-0001Sd-EZ for pgsql-general@postgresql.org; Sun, 14 Apr 2019 03:22:24 +0000 Received: by mail-ot1-x341.google.com with SMTP id d24so11653628otl.11 for ; Sat, 13 Apr 2019 20:22:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=0bMRDXLZ4/mtAaDk8TOcjqNzpzqufds0sVT4hEIX0Ko=; b=Y0rlroEXp8CZkrgCP6x/qD+tsMoKwOTH1u3og7UkKQN5TkPZ47+8OtGpH795gYsJ52 hOeNQXpSJlpM2DsGh8MwBYr2N0wNHBIp06YAlLht6GrGKsxWx/RWvWRA1PVOHfHFg/w5 5C8zGA2/YzKt/9QyHW35N01U0XJF2aIwHL/eWG8/DRVtU4DJ8DeIreuGzmMNffOvl4MK fIGqLjjqZq+zSlVa7mjNYmI0D+Ppdhs3kcFZSV0fs1AdfmZ/1gLkjLMrkmdnE4kXEAx6 KNVVIKdwBlapdfCSEJ+iaiYhBntvkUjdIkllnP95UuULHr1CHeC8CZ5ZaCfrU7zgFYG4 MQrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=0bMRDXLZ4/mtAaDk8TOcjqNzpzqufds0sVT4hEIX0Ko=; b=MPe/0tH0+KqtgBNwvwIXaECXPNkomHyavRW4UNEmwabGtKfurA2jN1zrsb8ZeDr1vr 55gQXZfDs4ztLxUVtBm/GFVk4z+YWaWgCijQNLN9CYkqFR30INfpCULd5sSc6hyT6GDV 6FuImtewPVx0v61AQWWcjeSUe7Ehsr/OtJPaK4oOGz0LdvJceIjOy7Uho3mqPfCr6IS+ TVTcyxXQNgIaA57Dddeb7Vrqd2MW0kahi+bexSsej3da5K1Bc+3m+1L9bsA3nMuSsxo3 5Z2WTajhJjBf9APqDUXPeekFfI4lMhrVPOJ+lI0KwifO3GUUg7IXW4vqxcJLMIYH3cck fTsg== X-Gm-Message-State: APjAAAVr9heY7VbRzw2z25WeiuU0DILttlZcc5QrGM+eQa7Rlqdm4doN 98qJI91RISUSsyH21+dVWBfxUtoWoiM= X-Google-Smtp-Source: APXvYqyjUK3C2uJv5jXkry+JDUKOtn41tQ4fIA3J1Q1UTZdyzv+9QL6hppWGKN7WCk8j1sQQAXsjuw== X-Received: by 2002:a9d:6844:: with SMTP id c4mr42628272oto.188.1555212138159; Sat, 13 Apr 2019 20:22:18 -0700 (PDT) Received: from [192.168.1.10] (ip70-171-116-89.no.no.cox.net. [70.171.116.89]) by smtp.googlemail.com with ESMTPSA id w10sm17955546oiw.48.2019.04.13.20.22.16 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 13 Apr 2019 20:22:17 -0700 (PDT) Subject: Re: Trigger when user logs in To: Forums postgresql References: <21272.1555035161@sss.pgh.pa.us> <22830.1555037562@sss.pgh.pa.us> <46D55D2C-5496-4867-9B87-3D865D71BCD2@amazon.com> From: Ron Message-ID: <6f77e98b-49f3-ecaa-f9d4-ef699999143a@gmail.com> Date: Sat, 13 Apr 2019 22:22:16 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 In-Reply-To: <46D55D2C-5496-4867-9B87-3D865D71BCD2@amazon.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 4/13/19 7:28 PM, Schneider, Jeremy wrote: >> On Apr 11, 2019, at 19:52, Tom Lane wrote: >> >> Ron writes: >>> I bet requests like this will start to make it onto the beaten path. >> Meh. I'm not that excited about inventing our own versions of wheels >> that already exist, especially when there's nothing very Postgres-specific >> about the requirements. Notice that the example I pointed you at is for >> sshd not Postgres. IMO the fact that you can use the same tool to solve >> both cases is a good thing. > This might work for sending an email, but not very useful if I want to do something in the database. > > For example, one very common use of logon triggers in other databases is to look at various connection parameters (like username or source IP) and enable sql logging or debugging for only certain cases 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. Oracle is able to do this, and the auditors expect other RDBMSs to do it to. > (not always doing the same thing for a particular user). Another common use case is to do something like running plpgsql or manipulating data in db tables - but again looking at some combination of things at a database level to make a decision about what to do; for example the application itself might enable or disable certain behaviors by setting values in a configuration table. > > I’m still trying to work out the best approach for solving these sorts of use cases in current versions of PostgreSQL... I’m curious how others are solving this? > > -Jeremy > > Sent from my TI-83 -- Angular momentum makes the world go 'round.