pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
And I thought I had this solved.
4+ messages / 2 participants
[nested] [flat]

* And I thought I had this solved.
@ 2019-11-22 23:52 stan <stanb@panix.com>
  2019-11-22 23:58 ` Re: And I thought I had this solved. Adrian Klaver <adrian.klaver@aklaver.com>
  2019-11-23 00:06 ` Re: And I thought I had this solved. Adrian Klaver <adrian.klaver@aklaver.com>
  0 siblings, 2 replies; 4+ messages in thread

From: stan @ 2019-11-22 23:52 UTC (permalink / raw)
  To: pgsql-general@lists.postgresql.org

A while back I ran into problems caused by  security fix related to the
search path. I wound up adding a line to. for instance, this function:

REATE FUNCTION
work_hours
(
    start_date date,
	end_date date
)
RETURNS decimal(10,4) stable
language sql as $$

	/* workaround for secuirty "feature" */
	SET search_path TO ica, "user" , public;

	SELECT
	sum(case when
	extract(isodow from d)
	between 1 and 5 then
	8.0 else
	+0.0 end)
	from

	generate_series($1,
	$2, interval
	'24 hours') d;

$$;

And walked away happy, or so I thought. Now I just got this error:

[local] stan@stan=# select * from ttl_avail_hours_by_project_and_employee ;
ERROR:  SET is not allowed in a non-volatile function
CONTEXT:  SQL function "work_hours" during startup

How can I solve this issue?


-- 
"They that would give up essential liberty for temporary safety deserve
neither liberty nor safety."
						-- Benjamin Franklin





^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: And I thought I had this solved.
  2019-11-22 23:52 And I thought I had this solved. stan <stanb@panix.com>
@ 2019-11-22 23:58 ` Adrian Klaver <adrian.klaver@aklaver.com>
  1 sibling, 0 replies; 4+ messages in thread

From: Adrian Klaver @ 2019-11-22 23:58 UTC (permalink / raw)
  To: stan <stanb@panix.com>; pgsql-general@lists.postgresql.org

On 11/22/19 3:52 PM, stan wrote:
> A while back I ran into problems caused by  security fix related to the
> search path. I wound up adding a line to. for instance, this function:
> 
> REATE FUNCTION
> work_hours
> (
>      start_date date,
> 	end_date date
> )
> RETURNS decimal(10,4) stable
> language sql as $$
> 
> 	/* workaround for secuirty "feature" */
> 	SET search_path TO ica, "user" , public;
> 
> 	SELECT
> 	sum(case when
> 	extract(isodow from d)
> 	between 1 and 5 then
> 	8.0 else
> 	+0.0 end)
> 	from
> 
> 	generate_series($1,
> 	$2, interval
> 	'24 hours') d;
> 
> $$;
> 
> And walked away happy, or so I thought. Now I just got this error:
> 
> [local] stan@stan=# select * from ttl_avail_hours_by_project_and_employee ;
> ERROR:  SET is not allowed in a non-volatile function
> CONTEXT:  SQL function "work_hours" during startup
> 
> How can I solve this issue?

If the above is the entire function I am not seeing that you need to SET 
search_path as there is no object that needs schema qualification. I 
would comment it out and run it.

If that fails then set the function volatile.



-- 
Adrian Klaver
adrian.klaver@aklaver.com





^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: And I thought I had this solved.
  2019-11-22 23:52 And I thought I had this solved. stan <stanb@panix.com>
@ 2019-11-23 00:06 ` Adrian Klaver <adrian.klaver@aklaver.com>
  2019-11-23 14:28   ` Re: And I thought I had this solved. stan <stanb@panix.com>
  1 sibling, 1 reply; 4+ messages in thread

From: Adrian Klaver @ 2019-11-23 00:06 UTC (permalink / raw)
  To: stan <stanb@panix.com>; pgsql-general@lists.postgresql.org

On 11/22/19 3:52 PM, stan wrote:
> A while back I ran into problems caused by  security fix related to the
> search path. I wound up adding a line to. for instance, this function:
> 
> REATE FUNCTION
> work_hours
> (
>      start_date date,
> 	end_date date
> )
> RETURNS decimal(10,4) stable
> language sql as $$
> 
> 	/* workaround for secuirty "feature" */
> 	SET search_path TO ica, "user" , public;
> 
> 	SELECT
> 	sum(case when
> 	extract(isodow from d)
> 	between 1 and 5 then
> 	8.0 else
> 	+0.0 end)
> 	from
> 
> 	generate_series($1,
> 	$2, interval
> 	'24 hours') d;
> 
> $$;
> 
> And walked away happy, or so I thought. Now I just got this error:
> 
> [local] stan@stan=# select * from ttl_avail_hours_by_project_and_employee ;
> ERROR:  SET is not allowed in a non-volatile function
> CONTEXT:  SQL function "work_hours" during startup
> 
> How can I solve this issue?


I thought I was missing something. Third option. As example:

https://www.postgresql.org/docs/11/sql-createfunction.html

Writing
SECURITY DEFINER
Functions Safely


...

$$  LANGUAGE plpgsql
     SECURITY DEFINER
     -- Set a secure search_path: trusted schema(s), then 'pg_temp'.
     SET search_path = admin, pg_temp;

Put the SET outside the function body.
-- 
Adrian Klaver
adrian.klaver@aklaver.com





^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: And I thought I had this solved.
  2019-11-22 23:52 And I thought I had this solved. stan <stanb@panix.com>
  2019-11-23 00:06 ` Re: And I thought I had this solved. Adrian Klaver <adrian.klaver@aklaver.com>
@ 2019-11-23 14:28   ` stan <stanb@panix.com>
  0 siblings, 0 replies; 4+ messages in thread

From: stan @ 2019-11-23 14:28 UTC (permalink / raw)
  To: Adrian Klaver <adrian.klaver@aklaver.com>; +Cc: pgsql-general@lists.postgresql.org

On Fri, Nov 22, 2019 at 04:06:14PM -0800, Adrian Klaver wrote:
> On 11/22/19 3:52 PM, stan wrote:
> > A while back I ran into problems caused by  security fix related to the
> > search path. I wound up adding a line to. for instance, this function:
> > 
> > REATE FUNCTION
> > work_hours
> > (
> >      start_date date,
> > 	end_date date
> > )
> > RETURNS decimal(10,4) stable
> > language sql as $$
> > 
> > 	/* workaround for secuirty "feature" */
> > 	SET search_path TO ica, "user" , public;
> > 
> > 	SELECT
> > 	sum(case when
> > 	extract(isodow from d)
> > 	between 1 and 5 then
> > 	8.0 else
> > 	+0.0 end)
> > 	from
> > 
> > 	generate_series($1,
> > 	$2, interval
> > 	'24 hours') d;
> > 
> > $$;
> > 
> > And walked away happy, or so I thought. Now I just got this error:
> > 
> > [local] stan@stan=# select * from ttl_avail_hours_by_project_and_employee ;
> > ERROR:  SET is not allowed in a non-volatile function
> > CONTEXT:  SQL function "work_hours" during startup
> > 
> > How can I solve this issue?
> 
> 
> I thought I was missing something. Third option. As example:
> 
> https://www.postgresql.org/docs/11/sql-createfunction.html
> 
> Writing
> SECURITY DEFINER
> Functions Safely
> 
> 
> ...
> 
> $$  LANGUAGE plpgsql
>     SECURITY DEFINER
>     -- Set a secure search_path: trusted schema(s), then 'pg_temp'.
>     SET search_path = admin, pg_temp;
> 
> Put the SET outside the function body.

OH, that seems the cleanest way to do this.

Thanks.

-- 
"They that would give up essential liberty for temporary safety deserve
neither liberty nor safety."
						-- Benjamin Franklin





^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2019-11-23 14:28 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-11-22 23:52 And I thought I had this solved. stan <stanb@panix.com>
2019-11-22 23:58 ` Adrian Klaver <adrian.klaver@aklaver.com>
2019-11-23 00:06 ` Adrian Klaver <adrian.klaver@aklaver.com>
2019-11-23 14:28   ` stan <stanb@panix.com>

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