【问题标题】:Error when accessing the Wildfly Management Console - Authentication required访问 Wildfly 管理控制台时出错 - 需要身份验证
【发布时间】:2019-02-26 09:07:05
【问题描述】:

我在登录Wildfly 13 Management Console 后收到错误Authentication required

如果我输入了错误的用户名或密码,它会再次询问,但如果我输入正确,它会显示带有错误消息的页面(所以我假设用户名和密码是正确的,但之后的其他内容会给出错误)。

我正在使用 docker 来运行一个 nginx 容器和一个 wildfly 容器。

nginx在外部监听9991端口,proxy将请求传递给wildfly容器,但显示之前描述的错误。

Wildfly 控制台会发生这种情况,代理的所有其他请求,甚至代理到 websocket 或端口 8080 上的 Wildfly 的请求,都已成功完成

Wildfly 容器在端口9990 上进行外部侦听,我可以在此端口成功访问控制台。如果在 docker 上我映射端口 "9992:9990" 我仍然可以通过端口 9992 成功访问控制台

所以,这似乎与 docker 无关,而是与 Wildfly 控制台本身有关。在中间使用反向代理时,可能某种身份验证未成功进行。

我在https://github.com/lucasbasquerotto/pod/tree/0.0.6 上有一个演示 docker 项目,您可以下载标签 0.0.6,该标签包含所有设置以使用 Wildfly 13 和 nginx,并模拟此错误。

git clone -b 0.0.6 --single-branch --depth 1 https://github.com/lucasbasquerotto/pod.git
cd pod
docker-compose up -d

然后,如果您使用用户 monitor 和密码 Monitor#70365 直接在 http://localhost:9990 中访问容器一切正常

但是如果您使用相同的凭据访问http://localhost:9991通过 nginx 反向代理,您会收到错误

我的nginx.conf 文件:

upstream docker-wildfly {
  server wildfly:9990;
}

location / {
  proxy_pass         http://docker-wildfly;
  proxy_redirect     off;
  proxy_set_header   Host $host;
  proxy_set_header   X-Real-IP $remote_addr;
  proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
  proxy_set_header   X-Forwarded-Host $server_name;
}

我也试过:

proxy_set_header   X-Forwarded-Proto $scheme;

还有 Authorization 标头(只是第 2 行,也有两者):

proxy_set_header   Authorization $http_authorization;
proxy_pass_header  Authorization;

并且还使用端口定义 host 标头(而不仅仅是 $host):

proxy_set_header   Host $server_addr:$server_port;

我已尝试将上述配置隔离并组合在一起。一切都无济于事。

有什么建议吗?

有没有人通过反向代理成功访问 Wildfly 控制台?

更新 (2018-09-22)

Wildfly 似乎使用摘要身份验证(而不是基本身份验证)。

我在控制台中看到如下标题:

Authorization: Digest username="monitor", realm="ManagementRealm", nonce="AAAAAQAAAStPzpEGR3LxjJcd+HqIX2eJ+W8JuzRHejXPcGH++43AGWSVYTA=", uri="/console/index.html", algorithm=MD5, response="8d5b2b26adce452555d13598e77c0f63", opaque="00000000000000000000000000000000", qop=auth, nc=00000005, cnonce="fe0e31dd57f83948"

我没有看到太多关于使用 nginx 代理带有摘要标头的传递请求的文档(但我认为它应该是透明的)。

我在这里看到的一个问题是https://serverfault.com/questions/750213/http-digest-authentication-on-proxied-server,但到目前为止还没有答案。

我看到有nginx非官方模块https://www.nginx.com/resources/wiki/modules/auth_digest/,但是在github仓库(https://github.com/atomx/nginx-http-auth-digest)里面写着:

ngx_http_auth_digest 模块补充了 Nginx 的内置 Basic 通过提供对 RFC 2617 Digest 支持的身份验证模块 验证。该模块当前可用,但仅 由其作者测试和审查。鉴于这是安全性 代码,一套眼睛几乎可以肯定是不够保证的 它是 100% 正确的。直到出现一些错误报告和一些 代码中的“未知未知数”被清除,考虑一下 模块一个“alpha”并用适量的 怀疑。

在我看来,对用户进行硬编码并传入一个 nginx 使用的文件似乎也不好(在这种情况下,身份验证对反向代理应该是透明的)。

无论如何,我试过了,它正确地要求我进行身份验证,即使最终目的地没有摘要式身份验证,比如在尝试连接到 wildfly 站点(不是控制台)时,它也会在尝试连接时询问到nginx(在代理请求之前),然后成功转发到目的地,除了wildfly控制台,它一直要求我永远进行身份验证。

所以我认为这不是解决方案。问题似乎在于 nginx 传递给 Wildfly 控制台的内容。

【问题讨论】:

    标签: docker nginx wildfly


    【解决方案1】:

    我在使用 HAL 管理控制台 v3.3 和 3.2 时遇到了同样的问题 由于身份验证错误,我无法让 ngnix HTTPS 工作,即使页面提示 http 基本身份验证用户并通过

    这是在同一台服务器上以独立模式测试的

    我的设置是: 外部(https)-> nginx-> http://halServer:9990/ 这导致 https 正常工作,但出现 HAL 身份验证错误(在浏览器控制台中看到),网页为空白。 一开始访问网页会正常询问http基本认证凭据,但随后几乎所有https请求都会返回认证错误

    我首先使用自签名证书启用 HAL 控制台 https,然后将 nginx 配置为代理传递给 HAL HTTPS 侦听器,从而使其正常工作

    工作设置是: 外部(https)-> nginx(https)-> https://halServer:9993/

    这里是ngnix配置

    server {
        listen                  80;
        listen                  [::]:80;
        listen                  443 ssl;
        listen                  [::]:443 ssl;
        server_name             halconsole.mywebsite.com;
    
        # SSL
        ssl_certificate         /keys/hal_fullchain.pem;
        ssl_certificate_key     /keys/hal_privkey.pem;
        ssl_trusted_certificate /keys/hal_chain.pem;
    
        # security
        include                 nginxconfig.io/security.conf;
    
        # logging
        access_log              /var/log/nginx/halconsole.mywebsite.com.access.log;
        error_log               /var/log/nginx/halconsole.mywebsite.com.error.log warn;
    
        # reverse proxy
        location / {
            # or use static ip, or nginx upstream
            proxy_pass https://halServer:9993;
            include    nginxconfig.io/proxy.conf;
        }
    
        # additional config
        include nginxconfig.io/general.conf;
        include nginxconfig.io/letsencrypt.conf;
    }
    
    # subdomains redirect
    server {
        listen                  443 ssl;
        listen                  [::]:443 ssl;
        server_name             *.halconsole.mywebsite.com;
    
        # SSL
        ssl_certificate         /keys/hal_fullchain.pem;
        ssl_certificate_key     /keys/hal_privkey.pem;
        ssl_trusted_certificate /keys/hal_chain.pem;
        return                  301 https://halconsole.mywebsite.com$request_uri;
    }
    

    proxy.conf

    proxy_http_version                 1.1;
    proxy_cache_bypass                 $http_upgrade;
    
    # Proxy headers
    proxy_set_header Upgrade           $http_upgrade;
    proxy_set_header Connection        $connection_upgrade;
    proxy_set_header Host              $http_host;
    proxy_set_header X-Real-IP         $remote_addr;
    proxy_set_header Forwarded         $proxy_add_forwarded;
    proxy_set_header X-Forwarded-For   $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-Host  $host;
    proxy_set_header X-Forwarded-Port  $server_port;
    proxy_set_header X-Forwarded-By    $server_addr;
    
    # Proxy timeouts
    proxy_connect_timeout              60s;
    proxy_send_timeout                 60s;
    proxy_read_timeout                 60s;
    

    启用 https 控制台的最简单方法是使用控制台本身

    1. 使用命令行keytool 或 GUI 程序生成 java JKS 密钥库 我喜欢 GUI,所以我使用了 Key Store Explorer https://github.com/kaikramer/keystore-explorer

    2. 将密钥库文件复制到它具有读取权限的 halServer 服务器上(无需保密)

    # your file paths might differ, don't copy paste
    cp /home/someUser/sftp_uploads/managementKS /opt/wildfly/standalone/data/keystore/managementKS
    
    1. 设置权限
    # your file paths might differ, don't copy paste
    chown --recursive -H wildfly:wildfly /opt/wildfly/standalone/data/keystore
    
    1. (使用 vpn)登录明文控制台 http://halServer:9990/

    2. 添加密钥库:导航:

       configuration -> subsystems -> security (elytron) -> other settings (click view button)
       stores -> keystore -> add
       ...
       Name = managementKS
       Type = JKS
       Path = keystore/managementKS
       Relative to = jboss.server.data.dir
       Credential Reference Clear Text = keystore-password click Add
      

    生成standalone.xml

    <key-store name="managementKS">
        <credential-reference clear-text="keystore-password"/>
        <implementation type="JKS"/>
        <file path="keystore/managementKS" relative-to="jboss.server.data.dir"/>
    </key-store>
    
    1. 添加密钥管理器:导航:

       ssl -> key manager -> add
       ...
       Name = managementKM
       Credential Reference Clear Text = keystore-password
       Key Store = managementKS
      

    生成standalone.xml

    <key-manager name="managementKM" key-store="managementKS">
        <credential-reference clear-text="keystore-password"/>
    </key-manager>
    
    1. 添加 ssl 上下文:导航:

       ssl -> server ssl context -> add
       ...
       Name = managementSSC
       Key Manager = managementKM
       ...
       Edit added : Protocols = TLSv1.2
       save
      

    生成standalone.xml

    <server-ssl-contexts>
        <server-ssl-context name="managementSSC" protocols="TLSv1.2" key-manager="managementKM"/>
    </server-ssl-contexts>
    
    1. 返回

       runtime -> server (click view button)
       http management interface (edit)
       set secure socket binding = management-https
       set ssl context = managementSSC
       save
      
    2. 重启wildfly

       systemctl restart wildfly
      

    【讨论】:

    • 感谢您的回答!我没有使用管理控制台 ATM,也有一段时间没有使用 Wildfly 配置,因此无法测试您的建议。也就是说,我认为它不适用于我们的案例,因为如果我没记错的话,即使在非安全(http)环境中也会出现问题,所以我认为问题与密钥库无关(并且我认为它允许非安全连接,毕竟它有 HTTP 和 HTTPS 端口)。也许它可能与另一个配置有关,例如http_upgradeconnection_upgrade。无论如何,我为您的详细回答提供了 +1。
    • 我的nginx版本:nginx/1.18.0 ;;您尝试将 http(非安全)代理到 hal 控制台 http(非安全)?它没有工作?在我的设置中,明文 http 始终有效(即:外部 http -> nginx -> http hal)
    • 我不完全确定,我在 2018 年进行了设置,当时使用控制台放弃了,所以我不记得确切的设置。如果我没记错的话,我尝试了 HTTPS -> Nginx(输入 https -> 代理 http) -> HAL(http)。当时,我在外部暴露了 wildfly 端口(不通过 nginx)并且它可以工作(但我更喜欢在中间使用 nginx)。
    • 您在上一条评论中所描述的正是我所经历的。也就是说,直接在任何端口上公开控制台,无论是 http 还是 https 都有效。和你一样,我也不喜欢http的想法,希望https由nginx自动加密。场景 :: HTTPS -> Nginx (输入 https -> 代理 http) -> HAL (http) 暴露在 http 中的控制台不起作用,它返回 auth 错误。我通过将带有 https 的控制台和代理 nginx 暴露给 https 来修复它。即:HTTPS -> Nginx (输入 https -> 代理 https) -> HAL (https),​​其中 HAL(https) 使用自签名证书。
    猜你喜欢
    • 2016-09-23
    • 2018-05-11
    • 2023-04-02
    • 1970-01-01
    • 2018-10-25
    • 2019-05-15
    • 2019-02-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多