问题 SVN hook pre-revprop-change无法正常工作


我知道之前已经多次询问过,但我相信我的情况有所不同。

我正在尝试向SVN存储库添加一个pre-revprop-change挂钩,以便对日志消息进行更改。

在我添加之前 pre-revprop-change 文件我收到此错误:

$ svn propset -r 557 --revprop svn:log "New message!" https://myserver/repos/myrepo
svn: DAV request failed; it's possible that the repository's pre-revprop-change hook either failed or is non-existent
svn: At least one property change failed; repository is unchanged
svn: Error setting property 'log': 
Repository has not been enabled to accept revision propchanges;
ask the administrator to create a pre-revprop-change hook

没问题,我想。我会加上它:

$ cd /var/www/svn/myrepo/hooks

$ # Create the simplest hook possible
$ echo '#!/bin/sh' > pre-revprop-change
$ echo 'exit 0' >> pre-revprop-change

$ # Check that it looks correct
$ cat pre-revprop-change
#!/bin/sh
exit 0

$ # Looks good, now make it executable
$ chmod a+x pre-revprop-change

$ # Check the permissions
$ ls -al pre-revprop-change
-rwxr-xr-x 1 apache apache 17 2012-05-24 12:05 pre-revprop-change

$ # Run it, to make sure it runs, and check the error code
$ ./pre-revprop-change 
$ echo $?
0

所以,根据我在SO上阅读的其他内容,应该是我需要的全部工作。但是,当我再次尝试编辑日志消息时,我仍然会收到错误(这次是另一个错误):

$ svn propset -r 557 --revprop svn:log "New message!" https://myserver/repos/myrepo
svn: DAV request failed; it's possible that the repository's pre-revprop-change hook either failed or is non-existent
svn: At least one property change failed; repository is unchanged
svn: Error setting property 'log': 
Revprop change blocked by pre-revprop-change hook (exit code 255) with no output.

有几点需要注意:

1)存储库托管在SELinux服务器(Fedora核心10)上。也许在这些权限方面我需要做些什么?以下是钩子的SE权限:

$ ls -alZ pre-revprop-change
-rwxr-xr-x  apache apache unconfined_u:object_r:httpd_sys_content_rw_t:s0 pre-revprop-change

2)通过WebDAV访问存储库(注意 https:// 在存储库名称中)。我是否需要在WebDAV端设置一些内容以允许更改前的更改?


11441
2018-05-24 11:22


起源



答案:


经过几个小时的尝试,我找到了答案。而且,因为它似乎不存在于互联网上的任何其他地方,我会在这里发布...

这个问题是由SELinux引起的(那里没什么大惊喜)。看来阿帕奇(/usr/sbin/httpd)没有必要的权限来运行具有上述SE权限的钩子脚本。要使其执行,需要更改SELinux权限

$ chcon -t httpd_exec_t pre-revprop-change

(我首先尝试将其更改为 httpd_sys_script_exec_t,但这还不足以让脚本执行。但随着 httpd_exec_t 输入它。)

最后一个问题:这是一件安全的事吗?


9
2018-05-24 13:32



这是否安全取决于您的“安全”标准:) ...但是,SELinux可能会导致一些微妙的问题,但可以通过启用日志记录来诊断。 - 0xC0000022L
谢谢。是的,我不认为我们的服务器会成为黑客中心,但我只是想确保我没有打开一个巨大的安全漏洞!你知道为什么要使用 httpd_sys_script_exec_t 没用?从文档中可以看出它应该...... - Lee Netherton
我本以为这应该有效。不知道为什么一定要这样 httpd_exec_t 代替 httpd_sys_script_exec_t。但SELinux有可能以某种方式区分输出到Apache的脚本和其他位置的脚本。你在哪里使用Apache而不是 svnserve (即使Apache可以代理它),对吧? - 0xC0000022L
是的,肯定要经过阿帕奇。 svn WebDAV URL配置在 /etc/httpd/conf.d/ 目录。而我正通过它访问它 https:// 网址。 - Lee Netherton


答案:


经过几个小时的尝试,我找到了答案。而且,因为它似乎不存在于互联网上的任何其他地方,我会在这里发布...

这个问题是由SELinux引起的(那里没什么大惊喜)。看来阿帕奇(/usr/sbin/httpd)没有必要的权限来运行具有上述SE权限的钩子脚本。要使其执行,需要更改SELinux权限

$ chcon -t httpd_exec_t pre-revprop-change

(我首先尝试将其更改为 httpd_sys_script_exec_t,但这还不足以让脚本执行。但随着 httpd_exec_t 输入它。)

最后一个问题:这是一件安全的事吗?


9
2018-05-24 13:32



这是否安全取决于您的“安全”标准:) ...但是,SELinux可能会导致一些微妙的问题,但可以通过启用日志记录来诊断。 - 0xC0000022L
谢谢。是的,我不认为我们的服务器会成为黑客中心,但我只是想确保我没有打开一个巨大的安全漏洞!你知道为什么要使用 httpd_sys_script_exec_t 没用?从文档中可以看出它应该...... - Lee Netherton
我本以为这应该有效。不知道为什么一定要这样 httpd_exec_t 代替 httpd_sys_script_exec_t。但SELinux有可能以某种方式区分输出到Apache的脚本和其他位置的脚本。你在哪里使用Apache而不是 svnserve (即使Apache可以代理它),对吧? - 0xC0000022L
是的,肯定要经过阿帕奇。 svn WebDAV URL配置在 /etc/httpd/conf.d/ 目录。而我正通过它访问它 https:// 网址。 - Lee Netherton


在CentOS上有类似的事情。问题可能出在缓存的某个地方,就像我编辑文件然后将其更改回来一样,它开始工作。

所以,如果有人有类似的问题,只需尝试:

touch hooks/pre-revprop-change

1
2017-07-17 14:24