Lucas Basquerotto
Lucas Basquerotto

Reputation: 8103

Error when accessing the Wildfly Management Console - Authentication required

I'm receiving the error Authentication required after I login in the Wildfly 13 Management Console.

If I type a user or password wrong, it asks again, but if I type correctly it shows the page with the error message (so I assume the user and password are correct, but something else after that gives the error).

enter image description here

I'm using docker to run a nginx container and a wildfly container.

The nginx listens externally on port 9991 and proxy pass the request to the wildfly container, but it shows the error described before.

It just happens with the Wildfly Console, every other request proxied, even request proxied to a websocket or to Wildfly on port 8080, are done successfully.

The Wildfly container listens externally on port 9990 and I can access the console successfully in this port. If on docker I map the port "9992:9990" I still can access the console successfully through port 9992.

So, it seems that this is not related to docker, but to the Wildfly Console itself. Probably some kind of authentication that is not happening successfully when using a reverse proxy in the middle.

I have a demo docker project on https://github.com/lucasbasquerotto/pod/tree/0.0.6, and you can download the tag 0.0.6 that has everything setup to work with Wildfly 13 and nginx, and to simulate this error.

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

Then, if you access the container directly in http://localhost:9990 with user monitor and password Monitor#70365 everything works.

But if you access http://localhost:9991 with the same credentials, through the nginx reverse proxy, you receive the error.

My nginx.conf file:

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;
}

I've also tried with:

proxy_set_header   X-Forwarded-Proto $scheme;

And also with the Authorization header (just the 2nd line and also with both):

proxy_set_header   Authorization $http_authorization;
proxy_pass_header  Authorization;

And also defining the host header with the port (instead of just $host):

proxy_set_header   Host $server_addr:$server_port;

I've tried the above configurations isolated and combined together. All to no avail.

Any sugestions?

Has anyone successfully accessed the Wildfly Console through a reverse proxy?

Update (2018-09-22)

It seems Wildfly uses a digest authentication (instead of basic).

I see the header in the console like the following:

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"

I don't see much documentation about using nginx to proxy pass requests with digest headers (but I think it should be transparent).

One question I saw here in SO is https://serverfault.com/questions/750213/http-digest-authentication-on-proxied-server, but there is no answer so far.

I saw that there is the nginx non-official module https://www.nginx.com/resources/wiki/modules/auth_digest/, but in the github repository (https://github.com/atomx/nginx-http-auth-digest) it says:

The ngx_http_auth_digest module supplements Nginx's built-in Basic Authentication module by providing support for RFC 2617 Digest Authentication. The module is currently functional but has only been tested and reviewed by its author. And given that this is security code, one set of eyes is almost certainly insufficient to guarantee that it's 100% correct. Until a few bug reports come in and some of the ‘unknown unknowns’ in the code are flushed out, consider this module an ‘alpha’ and treat it with the appropriate amount of skepticism.

Also it doesn't seem to me allright to hardcode the user and pass in a file to be used by nginx (the authentication should be transparent to the reverse proxy in this case).

In any case, I tried it and it correctly asks me to authenticate, even if the final destination does not have a digest authentication, like when trying to connect to the wildfly site (not console), it asks when trying to connect to nginx (before proxying the request), then it forwards successfully to the destination, except in the case of wildfly console, it keeps asking me to authenticate forever.

So I think this is not the solution. The problem seems to be in what the nginx is passing to the Wildfly Console.

Upvotes: 3

Views: 3012

Answers (1)

Andrei Matei
Andrei Matei

Reputation: 77

I had the same problem with the HAL management console v3.3 and 3.2 I could not get ngnix HTTPS working due to authentication errors, even though the page prompted http basic auth user and pass

This was tested in standalone mode on the same server

My setup was : outside (https) -> nginx -> http://halServer:9990/ This resulted in working https but with HAL authentication errors (seen in the browsers console) the webpage was blank. At first access the webpage would ask http basic auth credentials normally, but then almost all https requests would return an authentication error

I managed to make it work correctly by first enabling the HAL console https with a self signed certificate and then configuring nginx to proxy pass to the HAL HTTPS listener

Working setup is : outside (https) -> nginx (https) -> https://halServer:9993/

Here is the ngnix configuration

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;

The easiest way to enable https console is by using the console itself

  1. generate a java JKS keystore using either the command line keytool or a GUI program I like GUIs, so I used Key Store Explorer https://github.com/kaikramer/keystore-explorer

  2. copy keystore file on the halServer server where it has read access (no need to keep it secret) i placed mine inside wildfly data dir in a "keystore" directory.

# your file paths might differ, don't copy paste
cp /home/someUser/sftp_uploads/managementKS /opt/wildfly/standalone/data/keystore/managementKS
  1. set permissions
# your file paths might differ, don't copy paste
chown --recursive -H wildfly:wildfly /opt/wildfly/standalone/data/keystore
  1. (use vpn) login to cleartext console http://halServer:9990/

  2. add keystore : navigate :

     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
    

result in 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. add key manager : navigate :

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

result in standalone.xml

<key-manager name="managementKM" key-store="managementKS">
    <credential-reference clear-text="keystore-password"/>
</key-manager>
  1. add ssl context : navigate :

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

result in standalone.xml

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

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

     systemctl restart wildfly
    

Upvotes: 1

Related Questions