mirror of
https://github.com/postgres/postgres.git
synced 2025-10-18 04:29:09 +03:00
Allow group access on PGDATA
Allow the cluster to be optionally init'd with read access for the group. This means a relatively non-privileged user can perform a backup of the cluster without requiring write privileges, which enhances security. The mode of PGDATA is used to determine whether group permissions are enabled for directory and file creates. This method was chosen as it's simple and works well for the various utilities that write into PGDATA. Changing the mode of PGDATA manually will not automatically change the mode of all the files contained therein. If the user would like to enable group access on an existing cluster then changing the mode of all the existing files will be required. Note that pg_upgrade will automatically change the mode of all migrated files if the new cluster is init'd with the -g option. Tests are included for the backend and all the utilities which operate on the PG data directory to ensure that the correct mode is set based on the data directory permissions. Author: David Steele <david@pgmasters.net> Reviewed-By: Michael Paquier, with discussion amongst many others. Discussion: https://postgr.es/m/ad346fe6-b23e-59f1-ecb7-0e08390ad629%40pgmasters.net
This commit is contained in:
@@ -79,7 +79,7 @@ main(int argc, char **argv)
|
||||
|
||||
set_pglocale_pgservice(argv[0], PG_TEXTDOMAIN("pg_upgrade"));
|
||||
|
||||
/* Ensure that all files created by pg_upgrade are non-world-readable */
|
||||
/* Set default restrictive mask until new cluster permissions are read */
|
||||
umask(PG_MODE_MASK_OWNER);
|
||||
|
||||
parseCommandLine(argc, argv);
|
||||
@@ -100,6 +100,16 @@ main(int argc, char **argv)
|
||||
|
||||
check_cluster_compatibility(live_check);
|
||||
|
||||
/* Set mask based on PGDATA permissions */
|
||||
if (!GetDataDirectoryCreatePerm(new_cluster.pgdata))
|
||||
{
|
||||
pg_log(PG_FATAL, "unable to read permissions from \"%s\"\n",
|
||||
new_cluster.pgdata);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
umask(pg_mode_mask);
|
||||
|
||||
check_and_dump_old_cluster(live_check);
|
||||
|
||||
|
||||
|
@@ -20,9 +20,9 @@ unset MAKELEVEL
|
||||
# Run a given "initdb" binary and overlay the regression testing
|
||||
# authentication configuration.
|
||||
standard_initdb() {
|
||||
# To increase coverage of non-standard segment size without
|
||||
# increase test runtime, run these tests with a lower setting.
|
||||
"$1" -N --wal-segsize 1
|
||||
# To increase coverage of non-standard segment size and group access
|
||||
# without increasing test runtime, run these tests with a custom setting.
|
||||
"$1" -N --wal-segsize 1 -g
|
||||
if [ -n "$TEMP_CONFIG" -a -r "$TEMP_CONFIG" ]
|
||||
then
|
||||
cat "$TEMP_CONFIG" >> "$PGDATA/postgresql.conf"
|
||||
@@ -230,14 +230,14 @@ standard_initdb 'initdb'
|
||||
|
||||
pg_upgrade $PG_UPGRADE_OPTS -d "${PGDATA}.old" -D "${PGDATA}" -b "$oldbindir" -B "$bindir" -p "$PGPORT" -P "$PGPORT"
|
||||
|
||||
# make sure all directories and files have correct permissions
|
||||
if [ $(find ${PGDATA} -type f ! -perm 600 | wc -l) -ne 0 ]; then
|
||||
echo "files in PGDATA with permission != 600";
|
||||
# make sure all directories and files have group permissions
|
||||
if [ $(find ${PGDATA} -type f ! -perm 640 | wc -l) -ne 0 ]; then
|
||||
echo "files in PGDATA with permission != 640";
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
if [ $(find ${PGDATA} -type d ! -perm 700 | wc -l) -ne 0 ]; then
|
||||
echo "directories in PGDATA with permission != 700";
|
||||
if [ $(find ${PGDATA} -type d ! -perm 750 | wc -l) -ne 0 ]; then
|
||||
echo "directories in PGDATA with permission != 750";
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
|
Reference in New Issue
Block a user