pg_cron icon indicating copy to clipboard operation
pg_cron copied to clipboard

API inconsistency: `cron.unschedule(jobid)` can unschedule jobs of another user but `cron.unschedule(jobname)` cannot

Open Ngalstyan4 opened this issue 1 year ago • 0 comments

The API function cron.unschedule has two overloaded versions - one takes a jobid, the other takes a jobname.

The one taking jobid unschedules the job without looking at the current user column. As a result, one user can unschedule jobs created by another user so long as row level security rules allow for record visibility.

But, the version of cron.unschedule function that takes a job name behaves differently. It filters for jobs started by current user (source) and reports that task was not found if the task with the passed name was started by another user.

SET ROLE some_non_superuser;

SELECT cron.schedule('some_name', '1 second', $$SELECT 1$$) as some_name_jobid \gset

SET ROLE some_superuser;

\set ON_ERROR_STOP off
SELECT cron.unschedule('some_name'); --fails
\set ON_ERROR_STOP on

SELECT cron.unschedule(:some_name_jobid); --succeeds

The fix probably is to delete the mentioned lines above, or add them in cron_schedule, depending on intended API.

Ngalstyan4 avatar Apr 17 '24 03:04 Ngalstyan4