FIEF (latest 0.28.5) SSL/TLS with real domain problem to get the admin page running #347
Replies: 5 comments 10 replies
-
Hi Claudio! That's lot of stuff 😅 If I understand you correctly, you're not able to reach your instance through HTTPS/SSL, right? Here are the things that looks weird to me and you should investigate:
UVICORN_SSL_KEYFILE=/etc/ssl/private/server.key
UVICORN_SSL_CERTFILE=/etc/ssl/certs/server.crt (maybe it's not needed, and maybe it's able to pick them automatically since it's in the default OS location, but worth to check) That said, I would recommend to setup a reverse proxy like Traefik to take care of SSL. I'll try to make the documentation more helpful around this.
|
Beta Was this translation helpful? Give feedback.
-
The problem is, that with PORT 443 it is not working:-( Instead Port 8000, i can also use e.g. Port 80 (http), this will also work, but https with Port 443 is not working, and i am wondering why:-( I know that best practice is to use a proxy like Traefik, but i like to find out the use of FIEF with and without having proxy:-) So this scenario here is without using a proxy. If you want to reproduce it, see below the whole configuration - with Port = 80 http://fiefdemo.mydomain.com/admin all is working fine, with Port 443 not - error message: "Invalid HTTP request received." and admin page is not reachable. All following files must be in the same folder!" And sure, search and replace mydomain.com with your real domain, search for email and change it to your email adress and search and change all xxx with your secret id's etc. Special: Check redis image - i use rasperry (arm64), if you use amd64, you have to change it before running (image: redis:alpine)! .env: SECRET=xxx DATABASE_TYPE=POSTGRESQL REDIS_URL=redis://redis:6379 CSRF_COOKIE_SECURE=False FIEF_SERVER_URL=http://mydomain.com UVICORN_SSL_KEYFILE=/etc/ssl/private/server.key Dockerfile: RUN pip install certbot-dns-cloudflare ENTRYPOINT ["certbot"] cloudflare.ini (set on Cloudflare SSL/TLS to "Full" not "Full (strict)" when using letsencrypt staging and in this demo staging is used): docker-compose.yml: version: "3" services: fief-worker: postgres: redis: dozzle: certbot: volumes: networks: run.sh: docker-compose -p "myfief" --env-file "./.env" up --build -d certbot stop_and_clean.sh: docker-compose -p "myfief" stop Hint: on Port 8080 you can use "dozzle for watching all logs from all containers running. |
Beta Was this translation helpful? Give feedback.
-
Ok, so I digged this up and it looks like I was wrong: we actually can't configure SSL certificates through environment variables like I suggested in my previous comment. This is because Fief's CLI wraps Uvicorn programmatically and don't explicitly support those options. I'll see how this can be improved on our side. Meanwhile, you can make it work by overriding the command of the command: uvicorn fief.app:app --port 443 --host 0.0.0.0 --ssl-keyfile /etc/ssl/private/server.key --ssl-certfile /etc/ssl/certs/server.crt Just note that migration and admin user won't be automatically created in this configuration. You'll have to manually call |
Beta Was this translation helpful? Give feedback.
-
Probably the SSL certificate was not correctly issued by Let's Encrypt. The example shows the TLS challenge, but it requires your server to be reachable on the internet. You should have a look at Traefik logs to see what's going on. Otherwise, for testing, you can uncomment the following lines:
This will use a test server to issue self-signed certificate from Let's Encrypt. I've tested this setup successfully on my end. |
Beta Was this translation helpful? Give feedback.
-
Setup for test
Just use FIEF-Server and Worker together with REDIS and PostgreSQL within a docker-compose.yml as shown in the FIEF-Docs!
Use a real domain, like in my example "mydomain.com" (replace it with yours)!
For https (SSL/TLS) i use Letsencrypt instead of self sign keys. You can use letsencrypt staging server for test, the behaviour is the same as you will use self signed certificates.
My DNS provider i use is Cloudflare, if you use another one, you have to setup similiar there.
.env
ROOT_DOMAIN=mydomain.com:
FIEF_DOMAIN=fiefdemo.mydomain.com
FIEF_SERVER_URL=http://mydomain.com
All Cookie Variables are False!
FORWARD_ALLOWED_IPS=*
FIEF_API_KEY="ABCD"
FIEF_MAIN_ADMIN_API_KEY="ABCD"
Cloudflare-DNS: noproxied
Cloudflare-SSL/TLS: "Full" only
Letsencrypt: Use of the Staging-Server
docker-compose.yml:
...
fief-server:
image: ghcr.io/fief-dev/fief:0.28.5
depends_on:
- redis
- postgres
- certbot
container_name: fiefserver
command: fief run-server
ports:
- ${PORT}:${PORT}
env_file:
- .env
volumes:
- "./data/letsencrypt/live/mydomain.com/fullchain.pem:/etc/ssl/certs/server.crt:ro"
- "./data/letsencrypt/live/mydomain.com/privkey.pem:/etc/ssl/private/server.key:ro"
...
Doing all following URL-Calls in a Private-Browser-Window!
Call# Status URL-Calls:
01 ok? https://fiefdemo.mydomain.com/ FIEFSERVER-Log: no message
02 ok? http://fiefdemo.mydomain.com/ FIEFSERVER-Log: no message
03 ok? https://fiefdemo.mydomain.com/login FIEFSERVER-Log: no message
04 ok? http://fiefdemo.mydomain.com/login FIEFSERVER-Log: no message
05 ok? https://fiefdemo.mydomain.com/admin FIEFSERVER-Log: no message
06 ok? http://fiefdemo.mydomain.com/admin FIEFSERVER-Log: no message
07 ok? https://fiefdemo.mydomain.com:8000 FIEFSERVER-Log: 2x: Invalid HTTP request received.
08 OK! http://fiefdemo.mydomain.com:8000/ Auto redirect to: http://fiefdemo.mydomain.com:8000/login
FIEFSERVER-Log:
INFO | uvicorn.protocols.http.httptools_impl:send:489 - 77.200.35.45:56787 - "GET / HTTP/1.1" 307 - {}
INFO | uvicorn.protocols.http.httptools_impl:send:489 - 77.200.35.45:56787 - "GET /login HTTP/1.1" 200 - {}
INFO | uvicorn.protocols.http.httptools_impl:send:489 - 77.200.35.45:56787 - "GET /static/auth.css HTTP/1.1" 200 - {}
INFO | uvicorn.protocols.http.httptools_impl:send:489 - 77.200.35.45:56787 - "GET /static/favicon.svg HTTP/1.1" 200 - {}
Typing in my login credentials (admin):
- Login successfull, auto redirect to: http://fiefdemo.mydomain.com:8000/
- See and could manage Email and Passwort!
INFO | uvicorn.protocols.http.httptools_impl:send:489 - 77.200.35.45:56795 - "POST /login HTTP/1.1" 302 - {}
INFO | uvicorn.protocols.http.httptools_impl:send:489 - 77.200.35.45:56795 - "GET /verify-request HTTP/1.1" 302 - {}
INFO | uvicorn.protocols.http.httptools_impl:send:489 - 77.200.35.45:56795 - "GET / HTTP/1.1" 200 - {}
09 ok? https://fiefdemo.mydomain.com:8000/login 4x: Invalid HTTP request received.
10 OK! http://fiefdemo.mydomain.com:8000/login Login-Seite wird angezeigt:
INFO | uvicorn.protocols.http.httptools_impl:send:489 - 77.200.35.45:56806 - "GET /login HTTP/1.1" 200 - {}
Typing in my login credentials (admin):
- Login successfull, auto redirect to: http://fiefdemo.mydomain.com:8000/
- See and could manage Email and Passwort!
INFO | uvicorn.protocols.http.httptools_impl:send:489 - 77.200.35.45:56812 - "POST /login HTTP/1.1" 302 - {}
INFO | uvicorn.protocols.http.httptools_impl:send:489 - 77.200.35.45:56812 - "GET /verify-request HTTP/1.1" 302 - {}
INFO | uvicorn.protocols.http.httptools_impl:send:489 - 77.200.35.45:56812 - "GET / HTTP/1.1" 200 - {}
11 ok? https://fiefdemo.mydomain.com:8000/admin 4x: Invalid HTTP request received.
12 NOK!! http://fiefdemo.mydomain.com:8000/admin Auto redirect (Browser tells page is not reachable) to:
http://fiefdemo.mydomain.com/authorize?response_type=code&client_id=xxxxxxxxxxxxxxxxxxxxxxxxxxxxx&redirect_uri=http%3A%2F%2Ffiefdemo.mydomain.com%3A8000%2Fadmin%2Fauth%2Fcallback&scope=openid&screen=login
INFO | uvicorn.protocols.http.httptools_impl:send:489 - 77.200.35.45:56825 - "GET /admin HTTP/1.1" 308 - {}
INFO | uvicorn.protocols.http.httptools_impl:send:489 - 77.200.35.45:56825 - "GET /admin/ HTTP/1.1" 307 - {}
INFO | uvicorn.protocols.http.httptools_impl:send:489 - 127.0.0.1:47458 - "GET /.well-known/openid-configuration HTTP/1.1" 200 - {}
INFO | httpx._client:_send_single_request:1758 - HTTP Request: GET http://localhost:8000/.well-known/openid-configuration "HTTP/1.1 200 OK" - {}
INFO | uvicorn.protocols.http.httptools_impl:send:489 - 77.200.35.45:56825 - "GET /admin/auth/login HTTP/1.1" 302 - {}
Conclusion:
Calls 01 til 07, 09 and 11 i am not sure if this is the expected behaviour?
Calls 08 and 10 are fine:-)
Call 12 Not OK, i am wondering why, what is/could the problem here?
Beta Was this translation helpful? Give feedback.
All reactions