Commit 9544cc0d authored by Magnus Hagander's avatar Magnus Hagander

Move permissions check from do_pg_start_backup to pg_start_backup

And the same for do_pg_stop_backup. The code in do_pg_* is not allowed
to access the catalogs. For manual base backups, the permissions
check can be handled in the calling function, and for streaming
base backups only users with the required permissions can get past
the authentication step in the first place.

Reported by Antonin Houska, diagnosed by Andres Freund
parent b168c5ef
...@@ -9727,6 +9727,9 @@ XLogFileNameP(TimeLineID tli, XLogSegNo segno) ...@@ -9727,6 +9727,9 @@ XLogFileNameP(TimeLineID tli, XLogSegNo segno)
* *
* Every successfully started non-exclusive backup must be stopped by calling * Every successfully started non-exclusive backup must be stopped by calling
* do_pg_stop_backup() or do_pg_abort_backup(). * do_pg_stop_backup() or do_pg_abort_backup().
*
* It is the responsibility of the caller of this function to verify the
* permissions of the calling user!
*/ */
XLogRecPtr XLogRecPtr
do_pg_start_backup(const char *backupidstr, bool fast, TimeLineID *starttli_p, do_pg_start_backup(const char *backupidstr, bool fast, TimeLineID *starttli_p,
...@@ -9747,11 +9750,6 @@ do_pg_start_backup(const char *backupidstr, bool fast, TimeLineID *starttli_p, ...@@ -9747,11 +9750,6 @@ do_pg_start_backup(const char *backupidstr, bool fast, TimeLineID *starttli_p,
backup_started_in_recovery = RecoveryInProgress(); backup_started_in_recovery = RecoveryInProgress();
if (!superuser() && !has_rolreplication(GetUserId()))
ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("must be superuser or replication role to run a backup")));
/* /*
* Currently only non-exclusive backup can be taken during recovery. * Currently only non-exclusive backup can be taken during recovery.
*/ */
...@@ -10053,6 +10051,9 @@ pg_start_backup_callback(int code, Datum arg) ...@@ -10053,6 +10051,9 @@ pg_start_backup_callback(int code, Datum arg)
* *
* Returns the last WAL position that must be present to restore from this * Returns the last WAL position that must be present to restore from this
* backup, and the corresponding timeline ID in *stoptli_p. * backup, and the corresponding timeline ID in *stoptli_p.
*
* It is the responsibility of the caller of this function to verify the
* permissions of the calling user!
*/ */
XLogRecPtr XLogRecPtr
do_pg_stop_backup(char *labelfile, bool waitforarchive, TimeLineID *stoptli_p) do_pg_stop_backup(char *labelfile, bool waitforarchive, TimeLineID *stoptli_p)
...@@ -10085,11 +10086,6 @@ do_pg_stop_backup(char *labelfile, bool waitforarchive, TimeLineID *stoptli_p) ...@@ -10085,11 +10086,6 @@ do_pg_stop_backup(char *labelfile, bool waitforarchive, TimeLineID *stoptli_p)
backup_started_in_recovery = RecoveryInProgress(); backup_started_in_recovery = RecoveryInProgress();
if (!superuser() && !has_rolreplication(GetUserId()))
ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
(errmsg("must be superuser or replication role to run a backup"))));
/* /*
* Currently only non-exclusive backup can be taken during recovery. * Currently only non-exclusive backup can be taken during recovery.
*/ */
......
...@@ -56,6 +56,11 @@ pg_start_backup(PG_FUNCTION_ARGS) ...@@ -56,6 +56,11 @@ pg_start_backup(PG_FUNCTION_ARGS)
backupidstr = text_to_cstring(backupid); backupidstr = text_to_cstring(backupid);
if (!superuser() && !has_rolreplication(GetUserId()))
ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
errmsg("must be superuser or replication role to run a backup")));
startpoint = do_pg_start_backup(backupidstr, fast, NULL, NULL); startpoint = do_pg_start_backup(backupidstr, fast, NULL, NULL);
snprintf(startxlogstr, sizeof(startxlogstr), "%X/%X", snprintf(startxlogstr, sizeof(startxlogstr), "%X/%X",
...@@ -82,6 +87,11 @@ pg_stop_backup(PG_FUNCTION_ARGS) ...@@ -82,6 +87,11 @@ pg_stop_backup(PG_FUNCTION_ARGS)
XLogRecPtr stoppoint; XLogRecPtr stoppoint;
char stopxlogstr[MAXFNAMELEN]; char stopxlogstr[MAXFNAMELEN];
if (!superuser() && !has_rolreplication(GetUserId()))
ereport(ERROR,
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
(errmsg("must be superuser or replication role to run a backup"))));
stoppoint = do_pg_stop_backup(NULL, true, NULL); stoppoint = do_pg_stop_backup(NULL, true, NULL);
snprintf(stopxlogstr, sizeof(stopxlogstr), "%X/%X", snprintf(stopxlogstr, sizeof(stopxlogstr), "%X/%X",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment