繁体   English   中英

使用Apache和mod_macro设置私有的多个公共/私有Git存储库

[英]Setting up private multiple public/private Git repositories with Apache and mod_macro

我一直在私有服务器上运行SVN存储库。 我有几个项目要维护,所有项目都使用标准配置模式维护,这些模式后来被用作Apache macro 基本上我的结构很简单

映射到

  • /家/我的/ srv / SVN /回购
    • / repo1
    • / repo2

有多个宏,因为每个存储库都有自己的身份验证方案(公共读取,已验证提交或完全私有)

现在我要去Git

即使我发现了一些使用Apache和Git的配置指令,我也无法正确理解它们。 以下是我的问题:


我希望我的虚拟主机( https://git.example.com )托管多个Git存储库,所有存储库都可以从shell轻松配置(例如,添加mod_macroUse指令并通过SSH运行git init )。 每个人都有自己的权限系统,例如,根据.htpasswd 典型的存储库路径可以是https://git.example.com/[projects-or-whatever]/myProject.git映射到/home/me/srv/git/repos/myProject

如何在Apache中做到这一点?


到目前为止很糟糕

我尝试构建如下所示的Git配置(尚未经过测试,因为它暂时不会起作用)

<VirtualHost *:443>
    ServerName git.example.com
    ServerAlias www.git.example.com
    ServerAdmin me@example.com
    AssignUserID me myself

    # Use HTTP Strict Transport Security to force client to use secure connections only
    Header always set Strict-Transport-Security "max-age=500000000"

    ErrorLog /path/to/error_log
    CustomLog /path/to/access_log "vhost_combined"

    DocumentRoot /srv/www/default

    SSLEngine on
    SSLOptions +StrictRequire
    #SSLPassPhraseDialog builtin
    SSLCertificateFile /path/to.crt
    SSLCertificateKeyFile /path/to.key
    SSLCertificateChainFile /path/to.ca-bundle
    SSLVerifyClient none
    SSLProxyEngine on

    #Used for system login instead of .htaccess
    AddExternalAuth pwauth /usr/bin/pwauth
    SetExternalAuthMethod pwauth pipe

    <IfModule mime.c>
        AddType application/x-x509-ca-cert      .crt
        AddType application/x-pkcs7-crl         .crl
    </IfModule>



    ScriptAliasMatch \
       "(?x)^/git/(.*/(HEAD | \
       info/refs | \
       objects/(info/[^/]+ | \
       [0-9a-f]{2}/[0-9a-f]{38} | \
       pack/pack-[0-9a-f]{40}\.(pack|idx)) | \
       git-(upload|receive)-pack))$" \
       "/usr/lib/git/git-http-backend/$1"

    ScriptAlias /git /usr/share/gitweb/gitweb.cgi
    SetEnv GIT_PROJECT_ROOT /home/me/srv/git/repos/
    SetEnv GIT_HTTP_EXPORT_ALL


    #In this directory, specific repositories are configured
    Include "/home/hosting/vhosts.d/me/git/*.git.conf"

    <Directory "/home/me/srv/git/repos">
        Allow from all
        Options +ExecCGI
        AllowOverride All
    </Directory>


    <Directory "/usr/lib/git/">
        Options ExecCGI Indexes
        Order allow,deny
        Allow from all
    </Directory>

    AddHandler cgi-script cgi
    DirectoryIndex gitweb.cgi

    <Files gitweb.cgi>
        SetHandler cgi-script
    </Files>
</VirtualHost>

但是,让我们专注于我目前无法理解的以下内容

 ScriptAliasMatch \
       "(?x)^/git/(.*/(HEAD | \
       info/refs | \
       objects/(info/[^/]+ | \
       [0-9a-f]{2}/[0-9a-f]{38} | \
       pack/pack-[0-9a-f]{40}\.(pack|idx)) | \
       git-(upload|receive)-pack))$" \
       "/usr/lib/git/git-http-backend/$1"

根据我的理解 ,上面的正则表达式匹配绝对路径,例如

/git/sdf/HEAD
/git/blablabla/blabla/objects/info/sdfs
/git/daf/git-receive-pack

好的,如果不进行更改,看来我所有的项目都将放在/git/下,这是正确的吗?

但是然后,由于我目前不知道HTTP上的Git的工作方式, 我如何独立地保护每个存储库的安全

可能会提供答案。 这是我尝试之前的候选答案。

基本上,上述全局配置告诉所有以给定模式(例如git-receive-pack )结尾的内容都发送到Git CGI。 好。

但是使用正确的LocationMatchAlias<Directory>指令应该可以工作。 这是草稿:

  • 使用Alias将文件系统目录映射到某个位置
  • 如果需要,使用<Directory>设置.htaccess SVN使用HTTP verbs来区分读/写操作,Git使用git-receive-pack进行写操作。 该书建议使用LocationMatch指令
  • 将所有内容包装在Macro

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM