Re: Inserts restricted to a trigger

2019-06-21 Thread Adrian Klaver
On 6/20/19 3:30 PM, Miles Elam wrote: Thanks for the reply, Adrian. 1. The audit tables (plural) are recording the historical data for a table, ie., updates and deletes. All the same data as found in a given table along with the role that performed the operation, the transaction id, and the t

Re: Inserts restricted to a trigger

2019-06-20 Thread Miles Elam
Thanks for the reply, Adrian. 1. The audit tables (plural) are recording the historical data for a table, ie., updates and deletes. All the same data as found in a given table along with the role that performed the operation, the transaction id, and the time range where this data was in active use

Re: Inserts restricted to a trigger

2019-06-20 Thread Adrian Klaver
On 6/19/19 3:07 PM, Miles Elam wrote: Hi Adrian, thanks for responding. How would I restrict access to the SECURITY DEFINER function? If it can be called by the trigger, it can be called by the user as well I would think. Same issue as access to the table itself only now with a superuser inte

Re: Inserts restricted to a trigger

2019-06-20 Thread Adrian Klaver
On 6/19/19 3:07 PM, Miles Elam wrote: Hi Adrian, thanks for responding. How would I restrict access to the SECURITY DEFINER function? If it can be called by the trigger, it can be called by the user as well I would think. Same issue as access to the table itself only now with a superuser inte

Re: Inserts restricted to a trigger

2019-06-19 Thread Miles Elam
Hi Adrian, thanks for responding. How would I restrict access to the SECURITY DEFINER function? If it can be called by the trigger, it can be called by the user as well I would think. Same issue as access to the table itself only now with a superuser intermediary, right? On Tue, Jun 18, 2019 at

Re: Inserts restricted to a trigger

2019-06-18 Thread Adrian Klaver
On 6/18/19 10:14 AM, Miles Elam wrote: Thanks for the suggestion. Unfortunately we only have a single login role (it's a web app) and then we SET ROLE according to the contents of a JSON Web Token. So we end up with SESSION_USER as the logged in user and the active role as CURRENT_USER. Have

Re: Inserts restricted to a trigger

2019-06-18 Thread Miles Elam
Thanks for the suggestion. Unfortunately we only have a single login role (it's a web app) and then we SET ROLE according to the contents of a JSON Web Token. So we end up with SESSION_USER as the logged in user and the active role as CURRENT_USER. It may be that we're just stuck with a gap and ne

Re: Inserts restricted to a trigger

2019-06-18 Thread Torsten Förtsch
Have you tried session_user? create function xx() returns table (cur text, sess text) security definer language sql as $$ select current_user::text, session_user::text; $$; Then log in as different user and: => select (xx()).*; cur| sess --+--- postgres | write On Tue,

Re: Inserts restricted to a trigger

2019-06-18 Thread Miles Elam
That seems straightforward. Unfortunately I also want to know the user/role that performed the operation. If I use SECURITY DEFINER, I get the superuser account back from CURRENT_USER, not the actual user. Sorry, should have included that in the original email. How do I restrict access while still

Re: Inserts restricted to a trigger

2019-06-17 Thread raf
Adrian Klaver wrote: > On 6/17/19 4:54 PM, Miles Elam wrote: > > Is there are way to restrict direct access to a table for inserts but > > allow a trigger on another table to perform an insert for that user? > > > > I'm trying to implement an audit table without allowing user tampering > > with t

Re: Inserts restricted to a trigger

2019-06-17 Thread Adrian Klaver
On 6/17/19 4:54 PM, Miles Elam wrote: Is there are way to restrict direct access to a table for inserts but allow a trigger on another table to perform an insert for that user? I'm trying to implement an audit table without allowing user tampering with the audit information. Would the below