PATCH: Configurable file mode mask
David Steele <david@pgmasters.net>
From: David Steele <david@pgmasters.net>
To: Pg Hackers <pgsql-hackers@postgresql.org>
Cc: Adam Brightwell <adam.brightwell@crunchydata.com>,
Stephen Frost <sfrost@snowman.net>
Date: 2017-03-01T01:58:00Z
Lists: pgsql-hackers
Attachments
- file-mode-mask-v1.patch (text/plain) patch v1
PostgreSQL currently requires the file mode mask (umask) to be 0077. However, this precludes the possibility of a user in the postgres group performing a backup (or whatever). Now that pg_start_backup()/pg_stop_backup() privileges can be delegated to an unprivileged user, it makes sense to also allow a (relatively) unprivileged user to perform the backup at the file system level as well. This patch introduces a new initdb param, -u/-file-mode-mask, and a new GUC, file_mode_mask, to allow the default mode of files and directories in the $PGDATA directory to be modified. This obviously required mode changes in a number of places, so at the same time the BasicOpenFile(), OpenTransientFile(), and PathNameOpenFile() have been split into versions that either use the default permissions or allow custom permissions. In the end there was only one call to the custom permission version (be-fsstubs.c:505) for all three variants. The following three calls (at the least) need to be reviewed: bin/pg_dump/pg_backup_directory.c:194 src/port/mkdtemp.c:190 bin/pg_basebackup.c:599:655:1399 And this call needs serious consideration: bin/pg_rewind/file_ops.c:214 Besides that there should be tests to make sure the masks are working as expected and these could be added to the initdb TAP tests, though no mask tests exist at this time. Making sure all file operations produce the correct modes would need to be placed in a new module, perhaps the new backup tests proposed in [1]. Adam Brightwell developed the patch based on an initial concept by me and Stephen Frost. I added the refactoring in fd.c and some additional documentation. This patch applies cleanly on 016c990 but may fare badly over time due to the number of files modified. -- -David david@pgmasters.net [1] https://www.postgresql.org/message-id/758e3fd1-45b4-5e28-75cd-e9e7f93a4c02@pgmasters.net
Commits
-
Allow group access on PGDATA
- c37b3d08ca68 11.0 landed
-
Refactor dir/file permissions
- da9b580d8990 11.0 landed
-
Revert "Add basic TAP test setup for pg_upgrade"
- 58ffe141eb37 11.0 cited
-
Add basic TAP test setup for pg_upgrade
- f41e56c76e39 11.0 cited