Skip to content

Commit 7f67723

Browse files
committed
Adjust server-side backup to depend on pg_write_server_files.
I had made it depend on superuser, but that seems clearly inferior. Also document the permissions requirement in the straming replication protocol section of the documentation, rather than only in the section having to do with pg_basebackup. Idea and patch from Dagfinn Ilmari Mannsåker. Discussion: http://postgr.es/m/87bkzw160u.fsf@wibble.ilmari.org
1 parent 51891d5 commit 7f67723

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

doc/src/sgml/protocol.sgml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2647,6 +2647,11 @@ The commands accepted in replication mode are:
26472647
<literal>blackhole</literal>, the backup data is not sent
26482648
anywhere; it is simply discarded.
26492649
</para>
2650+
2651+
<para>
2652+
The <literal>server</literal> target requires superuser privilege or
2653+
being granted the <literal>pg_write_server_files</literal> role.
2654+
</para>
26502655
</listitem>
26512656
</varlistentry>
26522657

doc/src/sgml/ref/pg_basebackup.sgml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@ PostgreSQL documentation
237237
<literal>server:/some/path</literal>, the backup will be stored on
238238
the machine where the server is running in the
239239
<literal>/some/path</literal> directory. Storing a backup on the
240-
server requires superuser privileges. If the target is set to
240+
server requires superuser privileges or being granted the
241+
<literal>pg_write_server_files</literal> role. If the target is set to
241242
<literal>blackhole</literal>, the contents are discarded and not
242243
stored anywhere. This should only be used for testing purposes, as you
243244
will not end up with an actual backup.

src/backend/replication/basebackup_server.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@
1010
*/
1111
#include "postgres.h"
1212

13+
#include "catalog/pg_authid.h"
1314
#include "miscadmin.h"
1415
#include "replication/basebackup.h"
1516
#include "replication/basebackup_sink.h"
1617
#include "storage/fd.h"
18+
#include "utils/acl.h"
1719
#include "utils/timestamp.h"
1820
#include "utils/wait_event.h"
1921

@@ -65,10 +67,10 @@ bbsink_server_new(bbsink *next, char *pathname)
6567
sink->base.bbs_next = next;
6668

6769
/* Replication permission is not sufficient in this case. */
68-
if (!superuser())
70+
if (!is_member_of_role(GetUserId(), ROLE_PG_WRITE_SERVER_FILES))
6971
ereport(ERROR,
7072
(errcode(ERRCODE_INSUFFICIENT_PRIVILEGE),
71-
errmsg("must be superuser to create server backup")));
73+
errmsg("must be superuser or a member of the pg_write_server_files role to create server backup")));
7274

7375
/*
7476
* It's not a good idea to store your backups in the same directory that

0 commit comments

Comments
 (0)