【问题标题】:Apache basic authentication issue with reverse proxy反向代理的 Apache 基本身份验证问题
【发布时间】:2012-10-17 10:27:40
【问题描述】:

我想为在 Ubuntu 服务器 12.04.1 上运行的 Apache 反向代理站点添加基本身份验证。

Web 应用程序是 Jenkins,它在 Java EE 容器上运行。

我在httpd.conf中添加了以下配置,

ProxyPass         /jenkins/  http://localhost:8080/jenkins/¬
ProxyPassReverse  /jenkins/  http://localhost:8080/jenkins/¬
ProxyRequests     Off¬
ProxyPreserveHost On¬ 
¬
<Proxy http://localhost:8080/jenkins*>¬
  Order deny,allow¬
  Deny from all¬
▸ AllowOverride AuthConfig¬
▸ AuthType Basic¬
  AuthName "jenkins"¬
▸ AuthBasicProvider file¬
  AuthUserFile /etc/apache2/passfile¬
▸ Require valid-user¬
▸ Satisfy any¬
</Proxy>

当我使用错误的密码或不存在的用户名进行身份验证时,我可以在 apache 的 error.log 中找到以下消息,

[2012 年 10 月 27 日星期六 17:51:59] [错误] [客户端 222.128.175.95] 用户凯恩: “/jenkins/”的身份验证失败:密码不匹配 [10 月 27 日星期六 17:52:04 2012] [错误] [客户端 222.128.175.95] 找不到用户阿拉丁: /詹金斯/

passfile 中使用正确的用户名和密码时不会记录任何消息。虽然我在网络浏览器中输入了正确的用户名和密码,但身份验证对话框会再次提示。 我还在 apache 的 access.log 中找到了以下输出,

222.128.175.95 - kane [27/Oct/2012:17:39:54 +0800] "GET /jenkins/ HTTP/1.1" 401 794 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.4(KHTML,如 Gecko)Chrome/22.0.1229.94 Safari/537.4"

有人知道如何让它工作吗?谢谢。

【问题讨论】:

    标签: apache authentication ubuntu jenkins reverse-proxy


    【解决方案1】:

    您是否也在 Jenkins 上启用了身份验证?有关设置的说明,请参阅此链接:https://wiki.jenkins-ci.org/display/JENKINS/Apache+frontend+for+security

    特别注意这行说您不能同时在 Jenkins 和 Apache 中启用安全性,因为两者会发生冲突,从而导致您看到无限提示。不幸的是,您必须选择其中之一。

    有关 Apache + Jenkins 设置的更一般性讨论,另请参阅此链接:https://wiki.jenkins-ci.org/display/JENKINS/Running+Jenkins+behind+Apache

    【讨论】:

    • 感谢分享链接。我的詹金斯确实也使用 OpenId 进行身份验证。由于 Jenkins CLI 的限制,我必须做一些工作才能被匿名用户读取。这就是为什么我想对 Apache 服务器后面的 jenkins 使用基本身份验证。看起来 jenkins 在其身份验证和 Apache 基本身份验证之间存在冲突。无论如何,它给了我一个解释。
    • 我知道这篇文章已有 3 年历史,但我在寻找解决方案时发现了它。如果您想阻止 Jenkins 显示无限的基本身份验证提示,只需在您的 Apache 配置中添加 RequestHeader unset Authorization。在此处查看完整解决方案:jenkins-ci.361315.n4.nabble.com/…
    【解决方案2】:

    试试这个配置

    ProxyPass         /jenkins/  http://localhost:8080/jenkins/
    ProxyPassReverse  /jenkins/  http://localhost:8080/jenkins/
    ProxyRequests     Off
    ProxyPreserveHost On
    
    <Proxy http://localhost:8080/jenkins*>
        AllowOverride None
        Order allow,deny
        allow from all
        AuthName            "jenkins"
        AuthBasicProvider   file
        AuthType            basic
        AuthUserFile        /etc/apache2/passfile
        <Limit GET POST>
            require valid-user      
        </Limit>
        Satisfy all
    </Proxy>
    

    【讨论】:

    • 浏览器不再需要认证。我认为这是由Order allow,deny allow from all 引起的,它允许所有访问。
    • deny from all:它阻止所有访问,包括身份验证,你可以看到这个链接httpd.apache.org/docs/2.0/mod/mod_access.html
    • 你可以把IP地址范围代替“all”来进行认证,例如:Allow from 10.1.0.0/16
    • 问题是由“满足任何”引起的,您可以删除它或用“满足所有”替换它
    • "Satisfy Any" 如果满足任何要求则允许请求,但 "Satisfy All" 仅在满足两个要求时才允许请求,您可以在上面看到我的更新
    猜你喜欢
    • 2011-06-28
    • 1970-01-01
    • 1970-01-01
    • 2021-08-21
    • 2011-11-12
    • 2016-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多