使用LDAP作为认证方法来管理git存储库



有人有使用LDAP作为认证方法来管理Git仓库的经验吗?我的老板更喜欢使用LDAP而不是其他工具。任何建议都会有所帮助!

您可以轻松地向Apache Httpd服务器添加LDAP身份验证。
你可以很容易地添加一个智能http cgi脚本'git-http-backend'(由git打包)

这意味着您可以推送到https地址,前提是您确实先输入了LDAP凭据。您被授权访问Apache页面,但根本不使用身份验证。
参考"mod_authn_ldap和mod_authz_ldap的区别"

然而:

  • 与您签署提交的方式无关
  • 不关心Git的授权端(如果你通过了身份验证,你可以访问Git的仓库),正如分布式版本控制系统和企业-一个很好的组合?

实际使用认证并结合Git 授权访问的唯一方法是使用Gitolite

请参见"使存储库对ssh和http模式客户端都可用"。

我已经用(多个)LDAP身份验证设置了gitolite,在Apache配置文件中进行身份验证步骤,然后使用已识别的用户作为参数调用gitolite:

首先声明LDAP别名:

<AuthnProviderAlias ldap myldap>
  AuthLDAPBindDN cn=Manager,dc=example,dc=com
  AuthLDAPBindPassword secret
  AuthLDAPURL ldap://localhost:@PORT_LDAP_TEST@/dc=example,dc=com?uid?sub?(objectClass=*)
</AuthnProviderAlias>
<AuthnProviderAlias ldap companyldap>
  AuthLDAPBindDN "@LDAP_BINDDN@"
  AuthLDAPBindPassword @LDAP_PASSWORD@
  AuthLDAPURL @LDAP_URL@
</AuthnProviderAlias>

(' @xx@ '是要用测试值或生产值替换的模板)

然后我在VirtualHost中使用这些别名,其中我调用gitolite(如果身份验证成功)

# GitHttp on @PORT_HTTP_HGIT@ (extract)
Listen @PORT_HTTP_HGIT@
<VirtualHost @FQN@:@PORT_HTTP_HGIT@>
    ServerName @FQN@
    ServerAlias @HOSTNAME@
    SetEnv GIT_PROJECT_ROOT @H@/repositories
    SetEnv GIT_HTTP_EXPORT_ALL
    SetEnv GITOLITE_HTTP_HOME @H@
    ScriptAlias /hgit/ @H@/sbin/gitolite-shell/  # <=== will call gitolite
    SetEnv GIT_HTTP_BACKEND "@H@/usr/local/apps/git/libexec/git-core/git-http-backend"
    <Location /hgit>
        Options ExecCGI +FollowSymLinks +SymLinksIfOwnerMatch
        #AllowOverride All
        order allow,deny
        Allow from all
        AuthName "LDAP authentication for ITSVC Smart HTTP Git repositories"
        AuthType Basic
        # Authentication against one ldap, then a second
        AuthBasicProvider myldap companyldap
        AuthzLDAPAuthoritative Off
        Require valid-user
        AddHandler cgi-script cgi
    </Location>
</VirtualHost>

既然您提到了OpenLDAP,我假设您希望在Unix/Linux环境下使其工作。

Git本身不做身份验证。您需要设置ldap来管理用于访问git存储库的服务。例如,如果您使用SSH,那么将SSH守护进程配置为根据ldap进行身份验证。

如何准确地配置取决于您正在使用的确切设置。如果你需要帮助,我建议你在serverfault.com上发布一个详细的问题。

你可能也会觉得这个相关的问题很有趣