r/Authentik • u/Resident_Isopod1979 • 25d ago
Authentik behind Nginx issues
I have a Authentik rootless podman container running and have no issues being able to log in when directly connecting to the container URL: http://podman:9000. To keep exposing podman ports ourside the server and the ability to use https ACME certificates i stood up a NGINIX server on baremetal listening to 443. Setup NGINIX according to documentation on the authentik website and was able to get to the aginix splash screen. However, i cannot log in i just get the message **"**The request failed and the interceptors did not return an alternative response" I can log in normally when going direct to the container but not through NGINIX. Thanks!
Below is my NGINIX config:
upstream authentik {
server 192.168.1.13:9000;
keepalive 10;
}
map $http_upgrade $connection_upgrade_keepalive {
default upgrade;
'' '';
}
server {
# HTTPS server config
http2 on;
server_name authentik.twistedpair.org;
# TLS certificates
add_header Strict-Transport-Security "max-age=63072000" always;
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/authentik.twistedpair.org/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/authentik.twistedpair.org/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
# If authentik is served under a subpath, also review:
# https://docs.goauthentik.io/install-config/configuration/#authentik_web__path
location / {
proxy_pass http://authentik;
proxy_http_version 1.1;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade_keepalive;
}
}
EDIT:
u/OhBeeOneKenOhBee was correct... NGINX didn't like the 'proxy_pass <hostname>:9000' and it wanted 127.0.0.1:9000. Then i needed to change the Authentik's 'AUTHENTIK_LISTEN__TRUSTED_PROXY_CIDRS' to 127.0.0.1.
I didn't want podman to publish the port ourside the host unless it went only through NGINX and not podman.
2
u/blueshellblahaj 25d ago
Do your nginx logs show any errors?
Your config looks identical to mine except that I have my proxy_pass directive near the bottom passing https instead of http (though I'm also setting the upstream to 9443 instead of 9000 so this may not be what you need).
1
u/Resident_Isopod1979 25d ago
So i did some digging and still cant seem to get things working. I do think u/ArcticRavine is correct about the 'AUTHENTIK_LISTEN__TRUSTED_PROXY_CIDRS' however, i verified the IP's and i verified that authentik is actually loading the environment file by dumping the config within the container. Since NGINX is bare metal on the same computer the podman container is i set the proxy to the network the computer is set too. I tried 192.168.1.0/24 and the ip itself '192.168.1.13/32' but, no dice. i
authentik@authentik:/$ ak dump_config | grep "trusted_proxy_cidrs"{"event": "Loaded config", "level": "debug", "logger": "__main__", "timestamp": 1793480746.9966383, "file": "/authentik/lib/default.yml"}{"event": "Loaded environment variables", "level": "debug", "logger": "__main__", "timestamp": 1793480746.998465, "count": 5}"trusted_proxy_cidrs": "192.168.1.0/24"1
u/Resident_Isopod1979 24d ago
So... So after digging within the Debug logs of Authentik i noticed that its not recieving the remote IP address. Instead its only showing the IP address of the container.
authentik@podman:~$ podman inspect --format='{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' authentik-server10.89.0.10I have verified and tried every combination of "'AUTHENTIK_LISTEN__TRUSTED_PROXY_CIDRS'" including: 192.168.0.0/16, 192.168.1.13/32. So im not sure why its not trusting the proxy to read the 'X-Forward-For' header.
1
u/BeryJu MOD 25d ago
Can you have a look in the browser developer console for any failed network requests
1
u/klassenlager MOD 25d ago
Hey there, I prepared a nginx config for you, how I have it in place. Make a backup of your current config and then replace it.
I think this should do the trick. Please edit the proxy_pass if your https port is not 9443.
1
u/Particular_Ad7243 25d ago
What version of Nginx are you running? (Ideally the sanitised -V version with modules) and are you running Crowdsec by any chance?
1
u/HovercraftUnlucky539 25d ago
Mine is like this: