如何配置 apache 以接受客户端 ssl 证书(如果存在)或使用 ldap 进行身份验证(如果证书不存在)?

jmw*_*051 6 ssl configuration httpd

我有一个提供 mercurial 存储库的 Apache 服务器,它目前使用 ldap 凭据进行身份验证。

我想允许单个用户(开始时)使用 SSL 客户端证书,所有其余用户仍然可以使用 ldap 凭据身份验证方法。

我查看了 Stack Overflow 和其他更广泛的(谷歌)搜索,但找不到有关如何设置的信息/指南。

以下 vhost 配置仅允许客户端证书通过。我注释掉了与 SSL-client 相关的三个语句;ladp 会起作用。

<VirtualHost hg.mydomain.com:80>

    ServerName hg.mydomain.com:80
    RedirectMatch permanent ^(.*)$ https://hg.mydomain.com$1

</VirtualHost>

<VirtualHost hg.mydomain.com:443>

        ServerName hg.mydomain.com:443
        # ServerAdmin webmaster@yourdomain.com
        DocumentRoot "/var/hg"
        CustomLog /var/log/httpd/hg-access.log combined
        ErrorLog /var/log/httpd/hg-error.log

        ScriptAliasMatch        ^/(.*)        /var/hg/hgweb.cgi$1
  # SSL Stuff...
        SSLEngine on
        SSLCipherSuite AES+HIGH:3DES+HIGH:RC4:!MD5:!EXPORT:!SSLv2:!aNULL:!eNULL:!KRB5

        # Server Certificate:
        SSLCertificateFile ssl/hg.mydomain.com.crt
        # Server Private Key:
        SSLCertificateKeyFile ssl/hg.mydomain.com.key
        # SSL Protocol Adjustments:
        BrowserMatch ".*MSIE.*" nokeepalive ssl-unclean-shutdown downgrade-1.0 force-response-1.0

  <Directory /var/hg>
    Options ExecCGI FollowSymlinks
    AddHandler cgi-script .cgi

    AllowOverride AuthConfig
         Order deny,allow
        Allow from all

    #SSL-Client Statements
         SSLVerifyClient optional
         SSLVerifyDepth  1
         SSLRequire   %{SSL_CLIENT_S_DN_CN}  eq "robotuser"

     AuthName "Developers"
         AuthBasicProvider ldap
         # AuthLDAPEnabled On
         AuthLDAPUrl ldaps://ldap.applied.sec/dc=applied,dc=sec?uid
        AuthzLDAPAuthoritative On
        Require valid-user
  </Directory>

    # Taken from http://www.pmwiki.org/wiki/Cookbook/CleanUrls#samedir
    # Used at http://ggap.sf.net/hg/
    RewriteEngine On
    #write base depending on where the base url lives
    #RewriteBase /hg
    RewriteRule ^$ hgweb.cgi  [L]
    # Send requests for files that exist to those files.
    RewriteCond %{REQUEST_FILENAME} !-f
    # Send requests for directories that exist to those directories.
    RewriteCond %{REQUEST_FILENAME} !-d
    # Send requests to hgweb.cgi, appending the rest of url.
    RewriteRule (.*) /hgweb.cgi/$1  [QSA,L]

    Include repos.d/repos.*.conf
Run Code Online (Sandbox Code Playgroud)


似乎我需要以某种方式为目录块创建一个别名,然后应用逻辑来检查客户端证书的存在/不存在。我不知道如何去做。

如果有其他方法可以实现这一点。我很乐意听到它。

Chl*_*loe 0

您必须在后端服务器(PHP、Java 或 Perl)上执行此类逻辑。然后通过将标头设置Location:为实际的源代码管理来重定向。

如果您想要 if/then/else 类型的逻辑,则必须用编程语言来实现。

我不确定你的陈述是什么意思。您说此配置仅允许客户端证书通过,并且您还说 LDAP 可以工作。这听起来好像一切正​​常,一切都准备好了!

我会改为 . 目录通常用于文件系统特定的事物,尽管它们有点相似。

尝试使用两个不同的 并允许用户根据他们想要尝试的身份验证选择 URL。

SSLVerifyClient optional如果客户愿意的话,将只允许他们出示证书。您可能必须更改为require. 身份验证将在 Apache 级别进行,如果失败,则会收到服务器错误。

https://httpd.apache.org/docs/2.4/mod/mod_ssl.html#sslverifyclient

将 LDAP 放入另一个中,用户就可以转到那里。我没有使用过 Apache 的 LDAP 身份验证模块。

您可以修改错误文件以包含链接或在 SSL 链接失败时自动重定向到 LDAP 链接。