如何限制只访问一个SVN子目录?

我试图为通过Apache 2访问的SVN存储库configuration权限。我想要的是让任何人访问根目录,同时限制authentication用户的子目录。 例:

/demo /demo/project1 /demo/project1/sensitive-data # This path should require user authentication. /demo/project2 

起初,我认为这很简单:

 <Location /demo> DAV svn SVNPath /home/svn/demo AuthType Basic AuthName demo AuthUserFile /etc/subversion/passwd <LimitExcept GET PROPFIND OPTIONS REPORT> Require valid-user </LimitExcept> </Location> <Location /demo/project1/sensitive-data> DAV svn Require valid-user </Location> 

当通过HTTP(例如CURL)使用时,Apache符合configuration:我可以访问:

  • http://example.com/demo/ ,
  • http://example.com/demo/project1/和:
  • http://example.com/demo/project2/ ,

并且如我所料,在尝试检索http://example.com/demo/project1/sensitive-data时,得到了HTTP 401 Unauthorized

另一方面,做:

  • svn checkout http://example.com/demo/ . 要么:
  • svn checkout http://example.com/demo/project1/ .

检索整个目录树,包括demo/project1/sensitive-data

至less, svn checkout http://example.com/demo/project1/sensitive-data/ . 请求密码。

在执行svn checkout http://example.com/demo/ .时,如何configuration权限来限制对sensitive-data目录的访问svn checkout http://example.com/demo/ .

执行结帐时, <Location /demo/project1/sensitive-data>块是无关紧要的:只有在直接访问http://example.com/demo/project1/sensitive-data时才使用它,这就是HTTP请求导&#x81F4;HTTP 401 Unauthorized并检查这个特定的目录需要authentication。

在Subversion文档中解释了configuration基于path的授权的正确方法:

  1. <Location /demo>指向一个访问文件:

     <Location /demo> ... AuthzSVNAccessFile /etc/subversion/access.conf ... </Location> 
  2. 访问文件定义谁可以访问特定的文件和目录。 基本示例:

     [/] * = r # Everyone should be able to access the repository. [/demo/project1/sensitive-data] # Note that there is no trailing slash. * = # Nobody should access the sensitive directory.