authelia / authelia

The Single Sign-On Multi-Factor portal for web apps
https://www.authelia.com
Apache License 2.0
20.45k stars 1.06k forks source link

User Password Reset #1493

Closed michaeljf closed 3 years ago

michaeljf commented 3 years ago

Hi,

I am excited to finish my Authelia setup and use it in production. It sits behind Nginx. I am able to launch the page (port 9091).

However, I am not able to sign in. The password is seen as invalid. I then try to reset the password. I receive the reset email and start the reset. The page prompts me to enter a new password. Afterwards, it fails. The logs contain:

time="2020-11-27T00:13:35-05:00" level=info msg="Logging severity set to debug" time="2020-11-27T00:13:35-05:00" level=debug msg="Storage schema is being checked to verify it is up to date" time="2020-11-27T00:13:35-05:00" level=debug msg="Storage schema is up to date" time="2020-11-27T00:13:35-05:00" level=debug msg="Notifier SMTP client initializing TLS configuration" time="2020-11-27T00:13:35-05:00" level=debug msg="Notifier SMTP client attempting connection to smtp.gmail.com:587" time="2020-11-27T00:13:35-05:00" level=debug msg="Notifier SMTP client connected successfully" time="2020-11-27T00:13:35-05:00" level=debug msg="Notifier SMTP server supports STARTTLS (disableVerifyCert: false, ServerName: smtp.gmail.com), attempting" time="2020-11-27T00:13:35-05:00" level=debug msg="Notifier SMTP STARTTLS completed without error" time="2020-11-27T00:13:35-05:00" level=debug msg="Notifier SMTP server supports authentication with the following mechanisms: LOGIN PLAIN XOAUTH2 PLAIN-CLIENTTOKEN OAUTHBEARER XOAUTH" time="2020-11-27T00:13:35-05:00" level=debug msg="Notifier SMTP client attempting AUTH PLAIN with server" time="2020-11-27T00:13:36-05:00" level=debug msg="Notifier SMTP client authenticated successfully with the server" time="2020-11-27T00:13:36-05:00" level=info msg="Authelia is listening for non-TLS connections on 0.0.0.0:9091" 2020/11/27 00:14:11 error when serving connection "172.18.0.2:9091"<->"70.39.111.213:51127": error when reading request headers: cannot find http request method in "\x16\x03\x01\x02\x00\x01\x00\x01\xfc\x03\x03\xddS4\x12j\x9b\xf1e\xb9\x18\x06\xf0\x18\n$\x02\x18\x1e\xbd\xf6\x05\x85\x87:\xb5\xa2\xf92ښ\xac\x90 t\xf6\x8b\xd9z\xb9C[\xa1\x80\v\xc9'}9\x15z\x908\xd8\xed\x8e\xe7\x8fh\x92:i90\x95\xcf\x00 \xfa\xfa\x13\x01\x13\x02\x13\x03\xc0+\xc0/\xc0,\xc00̨̩\xc0\x13\xc0\x14\x00\x9c\x00\x9d\x00/\x005\x01\x00\x01\x93ZZ\x00\x00\x00\x00\x00\x1c\x00\x1a\x00\x00\x17authelia.keytechlab.com\x00\x17\x00\x00\xff\x01\x00\x01\x00\x00\n\x00\n\x00\b\x8a\x8a\x00\x1d\x00\x17\x00\x18\x00\v\x00\x02\x01\x00\x00#\x00\x00\x00\x10\x00\x0e\x00\f\x02h2\bhttp/1.1\x00\x05\x00\x05\x01\x00\x00\x00\x00\x00\r\x00\x12\x00\x10\x04\x03\b\x04\x04\x01\x05\x03\b\x05\x05\x01\b\x06\x06\x01\x00\x12\x00\x00\x003\x00+\x00)\x8a\x8a\x00\x01\x00\x00\x1d\x00 \xd95jYI\x8aZl\xb8ސ\x15\x92k\xb0\x83\xa7kz\x1b\fK\x87\xdd\xff\f\x04e\xc6\x013\x00-\x00\x02\x01\x01\x00+\x00\v\nZZ\x03\x04\x03\x03\x03\x02\x03\x01\x00\x1b\x00\x03\x02\x00\x02\xda\xda\x00\x01\x00\x00\x15\x00\xc5\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00". Buffer size=517, contents: "\x16\x03\x01\x02\x00\x01\x00\x01\xfc\x03\x03\xddS4\x12j\x9b\xf1e\xb9\x18\x06\xf0\x18\n$\x02\x18\x1e\xbd\xf6\x05\x85\x87:\xb5\xa2\xf92ښ\xac\x90 t\xf6\x8b\xd9z\xb9C[\xa1\x80\v\xc9'}9\x15z\x908\xd8\xed\x8e\xe7\x8fh\x92:i90\x95\xcf\x00 \xfa\xfa\x13\x01\x13\x02\x13\x03\xc0+\xc0/\xc0,\xc00̨̩\xc0\x13\xc0\x14\x00\x9c\x00\x9d\x00/\x005\x01\x00\x01\x93ZZ\x00\x00\x00\x00\x00\x1c\x00\x1a\x00\x00\x17authelia.keytechlab.com\x00\x17\x00\x00\xff\x01\x00\x01\x00\x00\n\x00\n\x00\b\x8a\x8a\x00\x1d\x00\x17\x00\x18\x00\v\x00\x02\x01\x00\x00#\x00\x00\x00\x10\x00\x0e\x00\f\x02h2\bhttp/1."..."\x15\x00\xc5\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" 2020/11/27 00:14:41 error when serving connection "172.18.0.2:9091"<->"70.39.111.213:51128": error when reading request headers: EOF. Buffer size=517, contents: "\x16\x03\x01\x02\x00\x01\x00\x01\xfc\x03\x03\xfdV\x11\x81\x8e\x18\x97\xf8x\x97\xba\xc2Q\r\x99\x13\xb7\xc1\x9b\xf6\x99\xb9\xc2N\x99Ԝ\xf7\xf3/\xd1? \x00\x06R9\x86>\xd2\xd6h\xc3\xfdwt\xbd\x8d\x86\xf0\xef\xf4XP\xba\x11\x81ʾ\xc1\x95X4\xf1\xc0\x00\"\xda\xda\x13\x01\x13\x02\x13\x03\xc0+\xc0/\xc0,\xc00̨̩\xc0\x13\xc0\x14\x00\x9c\x00\x9d\x00/\x005\x00\n\x01\x00\x01\x91ZZ\x00\x00\x00\x00\x00\x1c\x00\x1a\x00\x00\x17authelia.keytechlab.com\x00\x17\x00\x00\xff\x01\x00\x01\x00\x00\n\x00\n\x00\bZZ\x00\x1d\x00\x17\x00\x18\x00\v\x00\x02\x01\x00\x00#\x00\x00\x00\x10\x00\x0e\x00\f\x02h2\bhttp/"..."\x00\x01\x00\x00\x15\x00\xc1\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" 2020/11/27 00:14:41 error when serving connection "172.18.0.2:9091"<->"70.39.111.213:51129": error when reading request headers: EOF. Buffer size=517, contents: "\x16\x03\x01\x02\x00\x01\x00\x01\xfc\x03\x03\x89xV\x1c\x14\x13v\xf4\x94\xf5\xe9\xc5m\a\xb5Fj\xb0\x92\xc1\xacCNf*&Q\x9be\x98\xae \x89\xc6\x10o\xf6(0UF\xaa\x88\x11\x14Ds\x96,\x87\xa2y\xb2\xab\x9b2_tT\xbc\n\xaf \xc2\x00 \x9a\x9a\x13\x01\x13\x02\x13\x03\xc0+\xc0/\xc0,\xc00̨̩\xc0\x13\xc0\x14\x00\x9c\x00\x9d\x00/\x005\x01\x00\x01\x93::\x00\x00\x00\x00\x00\x1c\x00\x1a\x00\x00\x17authelia.keytechlab.com\x00\x17\x00\x00\xff\x01\x00\x01\x00\x00\n\x00\n\x00\b\xda\xda\x00\x1d\x00\x17\x00\x18\x00\v\x00\x02\x01\x00\x00#\x00\x00\x00\x10\x00\x0e\x00\f\x02h2\bhttp/1."..."\x15\x00\xc5\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"

Thanks, Michael

michaeljf commented 3 years ago

Error message (attached) Screen Shot 2020-11-27 at 10 21 46 AM

james-d-elliott commented 3 years ago

Authelia version, and could you provide your nginx config? We've never seen an issue like this. That looks like an SSL issue, probably your listen 443 directive does not tell nginx to use SSL/TLS.

\x16\x03\x01\x02\x00\x01\x00\x01\xfc\x03\x03 is the start of a SSL handshake.

michaeljf commented 3 years ago

@james-d-elliott - Happily, I appreciate your help.

Authelia is running as a docker container instance. The version and build details are: Authelia version v4.23.3, build 9310cead9779035bd2ec4316af289faec013698c

The nginx config:

server {

        root /var/www/authelia._domain_.com/html;
        index index.html index.htm index.nginx-debian.html;

        server_name authelia._domain_.com www.authelia._domain_.com;

        location / {
#                try_files $uri $uri/ =404;
                set $upstream_authelia http://127.0.0.1:9091;
                proxy_pass $upstream_authelia;

                client_body_buffer_size 128k;

                #Timeout if the real server is dead
                proxy_next_upstream error timeout invalid_header http_500 http_502     http_503;

                # Advanced Proxy Config
                send_timeout 5m;
                proxy_read_timeout 360;
                proxy_send_timeout 360;
                proxy_connect_timeout 360;

                # Basic Proxy Config
                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-Proto $scheme;
                proxy_set_header X-Forwarded-Host $http_host;
                proxy_set_header X-Forwarded-Uri $request_uri;
                proxy_set_header X-Forwarded-Ssl on;
                proxy_set_header X-Forwarded-Host $http_host;
                proxy_redirect  http://  $scheme://;
                proxy_http_version 1.1;
                proxy_set_header Connection "";
                proxy_cache_bypass $cookie_session;
                proxy_no_cache $cookie_session;
                proxy_buffers 64 256k;

                # If behind reverse proxy, forwards the correct IP
                set_real_ip_from 10.0.0.0/8;
                set_real_ip_from 172.0.0.0/8;
                set_real_ip_from 192.168.0.0/16;
                set_real_ip_from fc00::/7;
                real_ip_header X-Forwarded-For;
                real_ip_recursive on;
        }

    listen [::]:443 ssl; # managed by Certbot
    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/authelia._domain_.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/authelia._domain_.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}
server {
    if ($host = authelia._domain_.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot

        listen 80;
        listen [::]:80;

        server_name authelia._domain_.com www.authelia._domain_.com;
    return 404; # managed by Certbot

}
james-d-elliott commented 3 years ago

Are you running nginx in a container too? I'm assuming not since http://127.0.0.1:9091. Also can you tell me the full url with scheme minus your domain when these errors occur? I can't seem to see any glaring issues with your config, the line I was concerned about was listen 443 ssl; and it not having the ssl, but it does.

michaeljf commented 3 years ago

@james-d-elliott - Sorry, I did not see your reply until now.

Correct, nginx is not running in a container. I think the URI you want is the one I get in the email requesting a password reset. It is: https://authelia._domain_.com/reset-password/step2?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2MDY3OTI3MjYsImlzcyI6IkF1dGhlbGlhIiwiYWN0aW9uIjoiUmVzZXRQYXNzd29yZCIsInVzZXJuYW1lIjoic2ltcGxlIn0.MKqvahGmvRieEpGK7xiOFy_QlsJmhKe7buZG_sX_dGw

michaeljf commented 3 years ago

@james-d-elliott This could be already know. Sharing to avoid the assumption.

The inspection tool (from the Chrome browser) provides the following details. This is presented after entering the reset password and clicking the button. POST https://authelia._domain_.com/api/reset-password 502 (Bad Gateway)

Error: Request failed with status code 502 at e.exports (createError.js:16) at e.exports (settle.js:17) at XMLHttpRequest.p.onreadystatechange (xhr.js:62)

Also, the nginx error log contains two errors: 2020/12/01 02:51:33 [error] 491181#491181: 34 upstream prematurely closed connection while reading response header from upstream, client: xxx.xxx.xxx.xxx, server: authelia.domain.com, request: "POST /api/firstfactor HTTP/1.1", upstream: "http://127.0.0.1:9091/api/firstfactor", host: "authelia.domain.com" 2020/12/01 02:52:05 [error] 491181#491181: 34 upstream prematurely closed connection while reading response header from upstream, client: xxx.xxx.xxx.xxx, server: authelia.domain.com, request: "POST /api/reset-password HTTP/1.1", upstream: "http://127.0.0.1:9091/api/reset-password", host: "authelia.domain.com"

james-d-elliott commented 3 years ago

Can you provide your docker-compose if applicable or your run command for authelia? Also can you provide the output of the following on the host running nginx: curl http://127.0.0.1/api/state.

Maybe @nightah can spot something in the nginx config that looks off, but I can't.

nightah commented 3 years ago

Other than the weird indenting the nginx config looks fine, I did notice the following header being set twice: proxy_set_header X-Forwarded-Host $http_host; but I don't believe that to be an issue.

Looking at the logs looks like all of the POST requests seem to be failing. If you can jump on Matrix and we can try actively troubleshoot with you.

michaeljf commented 3 years ago

Thanks for the suggestion. I’ll make it and try it again - just in case.

Matrix - Sounds great! I have not used it before and will start looking into it.

Thank you, Michael

On Dec 1, 2020, at 11:54 PM, Amir Zarrinkafsh notifications@github.com wrote:

Other than the weird indenting the nginx config looks fine, I did notice the following header being set twice: proxy_set_header X-Forwarded-Host $http_host; but I don't believe that to be an issue.

Looking at the logs looks like all of the POST requests seem to be failing. If you can jump on Matrix https://github.com/authelia/authelia#matrix and we can try actively troubleshoot with you.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/authelia/authelia/issues/1493#issuecomment-737009127, or unsubscribe https://github.com/notifications/unsubscribe-auth/AA22XBV7TUFMGJTM3EUZOV3SSXJBDANCNFSM4UEO2NUA.

michaeljf commented 3 years ago

First, big thank you to James and Amir!

The root cause was out of memory - fatal error: runtime: out of memory.

The fix was to add the following section to the authelia configuration file:

https://www.authelia.com/docs/configuration/authentication/file.html#memory

password: algorithm: argon2id iterations: 1 salt_length: 16 parallelism: 8

recommend 1024

  memory: 100

I am running on a very resource constrained host. You would not want such a resource constrained host in a production environment.

Again, thank you!