logto-io / logto

🧑‍🚀 The better identity infrastructure for developers and the open-source alternative to Auth0.
https://logto.io
Mozilla Public License 2.0
8.77k stars 442 forks source link

bug: use docker deploy logto v1.6 will always redirect to /unknown-session #4279

Closed TheresaQWQ closed 8 months ago

TheresaQWQ commented 1 year ago

Describe the bug

bug: use docker deploy logto v1.6.0 will always redirect to /unknown-session

Expected behavior

not redirect

How to reproduce?

image image image

Just like in the screenshot above.

Context

Screenshots

TheresaQWQ commented 1 year ago

Some Logs: image

xiaoyijun commented 1 year ago

Hi @TheresaQWQ , I'm quite curious about why you're using curl to access the auth endpoint. Authentication-related requests rely on the browser's session, and it's recommended to perform authentication using a web browser. Logto offers a variety of SDKs and guides that helps you integrating Logto into your application. https://docs.logto.io/docs/recipes/integrate-logto/

TheresaQWQ commented 1 year ago

Hi @TheresaQWQ , I'm quite curious about why you're using curl to access the auth endpoint. Authentication-related requests rely on the browser's session, and it's recommended to perform authentication using a web browser. Logto offers a variety of SDKs and guides that helps you integrating Logto into your application. https://docs.logto.io/docs/recipes/integrate-logto/

I got the same problem even with the browser

github-actions[bot] commented 1 year ago

This issue is stale because it has been open for 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

leopku commented 1 year ago

Same issue by logto 1.7 + docker compose + nginx proxy manager. ENV had set. as below

RUST_PROXY_HEADER=1
ENDPOINT=https://logto.local.dev
ADMIN_ENDPOINT=https://admin-logto.local.dev
petarordanoski commented 1 year ago

Same issue here. I've been trying to make this work all day long. I'm using latest logto + docker run + nginx proxy manager.

vordan commented 1 year ago

Oh, well, time to look for another authentication server... :(

charIeszhao commented 1 year ago

Same issue by logto 1.7 + docker compose + nginx proxy manager. ENV had set. as below

RUST_PROXY_HEADER=1
ENDPOINT=https://logto.local.dev
ADMIN_ENDPOINT=https://admin-logto.local.dev

The first env should be TRUST_PROXY_HEADER instead of RUST

charIeszhao commented 1 year ago

Same issue here. I've been trying to make this work all day long. I'm using latest logto + docker run + nginx proxy manager.

Can you share your nginx config with us?

wangsijie commented 1 year ago

Hi guys, as you are using "https" and reverse proxy, according to the offical doc, you should add X-Forwarded-Proto to your reverser proxy server.

proxy_set_header X-Forwarded-Proto https;
TheresaQWQ commented 1 year ago

Hi guys, as you are using "https" and reverse proxy, according to the offical doc, you should add X-Forwarded-Proto to your reverser proxy server.

proxy_set_header X-Forwarded-Proto https;

I have set all the headers mentioned in the documentation, and updated to latest version in dockerhub (1.9.0), I still got same error

TheresaQWQ commented 1 year ago

I tried requesting localhost:3002 in a Docker container using curl and it looks like it works fine, it seems to be a problem only when using docker port forwarding image

wangsijie commented 1 year ago

Could you try a http domain?

TheresaQWQ commented 1 year ago

Could you try a http domain?

image

wangsijie commented 1 year ago

And it matches ADMIN_ENDPOINT?

TheresaQWQ commented 1 year ago

And it matches ADMIN_ENDPOINT?

yes, It matches ADMIN_ENDPOINT.

wangsijie commented 1 year ago

@TheresaQWQ Can you share your Logto's env config and nginx config? In the screenshot, it seems that Logto is configured to a https endpoint.

TheresaQWQ commented 1 year ago

@TheresaQWQ Can you share your Logto's env config and nginx config? In the screenshot, it seems that Logto is configured to a https endpoint.

I'm using Caddy, and my env config is above

env:

ADMIN_ENDPOINT=https://auth-admin.local.dev/
ADMIN_PORT=43002
DB_URL=postgres://logto:logto@127.0.0.1:45134/logto
ENDPOINT=https://auth.local.dev/
PORT=43001
TRUST_PROXY_HEADER=1

Caddyfile:

auth.local.dev {
  reverse_proxy http://127.0.0.1:43001 {
    trusted_proxies private_ranges
  }
}

auth-admin.local.dev {
  reverse_proxy http://127.0.0.1:43002 {
    trusted_proxies private_ranges
  }
}
wangsijie commented 1 year ago

@TheresaQWQ You can refer to this doc, and add X-Forwarded-Proto https://caddyserver.com/docs/caddyfile/directives/reverse_proxy#defaults

Mohdsaleh939 commented 1 year ago

Any updates on this issue ? We are still blocked from installing Logto tool and got the same issue mentioned above.

wangsijie commented 1 year ago

@Mohdsaleh939 Is your Logto container behind a reverse proxy? Follow this doc to add X-Forwarded-Proto to your reverser proxy server.

heng4fun commented 10 months ago

I use the AWS alb ingress with https, got the same issue.

wangsijie commented 10 months ago

@heng4fun can you please share more details? especially the ingress configs

JackyTYang commented 10 months ago

I use the AWS alb ingress with https, got the same issue.

me too,and i don't know where and how can I set the header like x-forwarded-proto in alb console

JackyTYang commented 10 months ago

I want to make sure that logto can only support https, not http? If the x-forwarded-proto = "http", then it will redirect to unknown-session, right? So I need to make sure x-forwarded-proto= "https" is passed to the backend of logto then it will work.

JackyTYang commented 10 months ago

Solved,I added https 443 monitor to AWS ALB in which router rules are configed.

wangsijie commented 10 months ago

Logto employs a rigorous URL validation process that mandates the "https" protocol. This stringent requirement can lead to complications in environments based on reverse proxies. Configurations such as 'x-forwarded-proto' can mitigate these issues. However, we recognize that these solutions might not be straightforward for all users, particularly those new to Logto. In light of this, we are actively exploring options to allow the disabling of this strict URL check to facilitate a smoother initial setup experience. Please stay tuned for updates.

yixinBC commented 8 months ago

So any solusion to use logto with docker on development machine? I mean,HTTP connnection on localhost.

wangsijie commented 8 months ago

@yixinBC You can set ADMIN_ENDPOINT to http://localhost:3002

yixinBC commented 8 months ago

@yixinBC You can set ADMIN_ENDPOINT to http://localhost:3002

@wangsijie actually ADMIN_ENDPOINT on http://localhost:3002 works just fine.But when I tried to browse http://localhost:3001/ ,I'm just redirected to http://localhost:3001/unknown-session everytime.I'm sorry I havn't clarify.

ciphermenial commented 8 months ago

I am experiencing this issue too. I can access admin fine but anytime I go to logto.example.net I receive unknown-session.

I installed Logto using npm-init in an LXC container.

This is how traffic flows from Cloudflare, through HAProxy, to the web server.

graph TD
 EU[/External User\] -."http://logto.example.net".-> CF[Cloudflare]
 CF -.-> FE_HTTPS
 IU[/Internal User\] --"http://logto.example.net"--> FE_HTTP[HTTP Frontend]
 subgraph HAProxy
 FE_HTTPS -- "Internal User?" --> INT[Internal Backend]
 FE_HTTP --> FE_HTTPS[HTTPS Frontend]
 EXT -.-> FE_EXT[External Frontend]
 INT --> FE_INT[Internal Frontend]
 FE_HTTPS -. "External User?" .-> CS_DEC[(CrowdSec Decision)]
 subgraph CrowdSec
 CS_DEC ==Require CAPTCHA==> CS_CAPTCHA[CAPTCHA Page]
 CS_DEC ==Banned IP==> CS_BAN[Ban Page]
 CS_CAPTCHA ==CAPTCHA failed==> CS_DEC
 CS_DEC ==Captcha Remediated==> EXT[External Backend]
 end
 end
 CS_DEC -.Not In Decisions.-> EXT
 FE_EXT -.-> S[Web Service]
 FE_INT --> S

I have http-request set-header x-forwarded-proto https in the frontend configuration.

JackyTYang commented 8 months ago

Https is a must

ciphermenial commented 8 months ago

It seems this issue is universal. I have now tested using localhost and still get sent to unknown-session for the login. Admin page works fine.

wangsijie commented 8 months ago

@ciphermenial thanks for the detailed feedback, I'll revisit this issue.

ciphermenial commented 8 months ago

I should mention that I could log into the demo-app.

wangsijie commented 8 months ago

@ciphermenial Access to the default endpoint requires initiating the sign-in flow with OIDC tools, like our SDKs. Without this, you will be redirected to an "unknown session" page.

wangsijie commented 8 months ago

@fleuraly I think we can add some tips to the "unknown session" page?

wangsijie commented 8 months ago

I am closing this issue, the reason is that you can not access the OIDC sign in endpoint directly. Feel free to reopen if you guys have any other questions.

PeterChen1997 commented 7 months ago

same problem. the doc should notice the user if they set the reverse proxy...

clhey commented 6 months ago

I tried requesting localhost:3002 in a Docker container using curl and it looks like it works fine, it seems to be a problem only when using docker port forwarding image

I have the same setup, with all headers configured according to the documentation (https://docs.logto.io/docs/recipes/deployment/#reverse-proxy), and I've verified through actual testing that the headers are working properly. Can anyone help solve this issue?

I suspect that logto only allows requests from http://localhost:3002/ and the specified ADMIN_ENDPOINT for security reasons. My ADMIN_ENDPOINT is similar to https://user.example.com:8443/. Does logto only support port 443?

image

adrianwnuk commented 2 months ago

Unable to run with as nginx ingress on kubernetes. Same output like above "unknown-session"

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: ingress-logto
  namespace: logto
  annotations:
    nginx.ingress.kubernetes.io/ssl-redirect: "true"
    nginx.ingress.kubernetes.io/force-ssl-redirect: "true"
spec:
  ingressClassName: nginx
  tls:
  - hosts:
    - logto.logto.domain.com
    secretName: logto-domain-com-tls
  rules:
  - host: logto.domain.com
    http:
      paths:
      - pathType: Prefix
        path: "/"
        backend:
          service:
            name: logto-core
            port:
              number: 3001
      - pathType: Prefix
        path: "/admin"
        backend:
          service:
            name: logto-admin
            port:
              number: 3002
WooodHead commented 1 month ago

I encountered the same "unknown-session" issue. The solution was to open xxxx.logto.app and clear all cookies in the browser console, which resolved the problem.

nqcuong72 commented 1 month ago

Add environment setting: 'HOST=0.0.0.0' will solve the problem

jagyas commented 1 week ago

I am using traefik proxy. After setting TRUST_PROXY_HEADER to true, at least I am able to access admin UI.