我在cron作业设置的ubuntu主机上有一个权限错误,以便使用pgbackrest进行数据库备份。
错误041::无法打开/var/lib/postgresql/10/main/global/pg_control
cron作业设置为在我的管理员帐户下运行。我看到解决这个问题的唯一选项是将目录权限更改为/var/lib/postgresql/10/main,以允许我的管理帐户进入,我不想这样做。
显然,只有postgres用户可以访问这个目录,我发现使用该用户设置cron作业是不可能的。即
postgres@host110:~/$ crontab -e
You (postgres) are not allowed to use this program (crontab)
See crontab(1) for more information我还能做什么?在pgbackrest手册中没有关于这一点的更多信息。
发布于 2019-09-24 17:18:25
只允许PostgreSQL OS用户(postgres)及其组访问PostgreSQL数据目录。从来源看到这段代码
/*
* Check if the directory has correct permissions. If not, reject.
*
* Only two possible modes are allowed, 0700 and 0750. The latter mode
* indicates that group read/execute should be allowed on all newly
* created files and directories.
*
* XXX temporarily suppress check when on Windows, because there may not
* be proper support for Unix-y file permissions. Need to think of a
* reasonable check to apply on Windows.
*/
#if !defined(WIN32) && !defined(__CYGWIN__)
if (stat_buf.st_mode & PG_MODE_MASK_GROUP)
ereport(FATAL,
(errcode(ERRCODE_OBJECT_NOT_IN_PREREQUISITE_STATE),
errmsg("data directory \"%s\" has invalid permissions",
DataDir),
errdetail("Permissions should be u=rwx (0700) or u=rwx,g=rx (0750).")));
#endif如果数据目录允许组进入,则该组通常也具有pg_control的权限。
因此,如果您给pgBackRest用户postgres的主用户组,就可以允许它进入。
如果相应地配置了系统,则允许postgres创建crontab。
来自man crontab
可以允许或不允许不同用户运行
cron作业。为此,请使用cron.allow和cron.deny文件。如果存在cron.allow文件,则必须列出其中的用户,如果cron.allow文件不存在,但cron.deny文件确实存在,则必须在其中列出用户才能使用cron.deny,那么为了使用cron,必须在cron.deny文件中列出用户。如果这两个文件都不存在,则只允许超级用户使用cron。限制对cron的访问的另一种方法是在/etc/security/access.conf中使用PAM身份验证来设置用户,允许或不允许用户在/etc/cron.d/目录中使用crontab或修改系统cron作业。
发布于 2019-09-24 17:36:09
如果您能够在提示符下sudo -u postgres,您也可以在您的cron作业中这样做。
您的问题并不显示您试图运行的实际命令,而是将thiscommand作为postgres运行,只是简单地
sudo -u postgres thiscommand如果您有su,但没有sudo,那么调整是次要的,但并不完全是微不足道的:
su -c thiscommand postgres使用sudo,您可以对作为另一个用户所能做的事情设置细粒度的限制,因此从这个意义上说,它比完全无限制的su更安全。
https://stackoverflow.com/questions/58084901
复制相似问题