Undefined (code: 1006), Nginx reverse proxy, authentik

Anexgohan

Member
Sep 25, 2022
21
1
8
Hello,
I tried to get help on authentik forum but got no response so posting here in hopes of a resolution.
I recently set up Nginx for sweet names and everything works fine, so I got authentik to protect my setup and everything work fine except when I open the console of any of my containers or even host, basically preventing me to use console over proxmox.<domain name>.com , I can still connect and use the console if I access proxmox by <IP>:8006,
If I remove authentik configuration from nginx everything works again including the console:
All other apps and containers like portainer, nginx, filebrowser work just fine going through nginx and authentik just proxmox is having some weird issue and i cant figure out why?

This is the error I get trying to use console:
Undefined (code: 1006)

This is whats been shown in "Tasks" panel in red at the bottom:
Code:
failed waiting for client: timed out
TASK ERROR: command '/usr/bin/termproxy 5900 --path /nodes/pve1 --perm Sys.Console -- /bin/login -f root' failed: exit code 1

This is whats been shown in "Cluster log" panel in red at the bottom :
Code:
end task UPIDve1:00012849:000ACCB5:63C25CC0:vncshell::root@pam:  command '/usr/bin/termproxy 5900 --path /nodes/pve1 --perm Sys.Console -- /bin/login -f root' failed: exit code 1

Nginx setup for proxmox:
chrome_2nSZuDYDcP.png

chrome_ff5VAdRYP5.png

chrome_9Q5b3hmOw6.png

the advanced tab has the following configuration:

Code:
# Increase buffer size for large headers
# This is needed only if you get 'upstream sent too big header while reading response
# header from upstream' error when trying to access an application protected by goauthentik
proxy_buffers 8 16k;
proxy_buffer_size 32k;

# Make sure not to redirect traffic to a port 4443
port_in_redirect off;

location / {
    # Put your proxy_pass to your application here
    proxy_pass          $forward_scheme://$server:$port;
    # Set any other headers your application might need
    # proxy_set_header Host $host;
    # proxy_set_header ...

    ##############################
    # authentik-specific config
    ##############################
    auth_request     /outpost.goauthentik.io/auth/nginx;
    error_page       401 = @goauthentik_proxy_signin;
    auth_request_set $auth_cookie $upstream_http_set_cookie;
    add_header       Set-Cookie $auth_cookie;

    # translate headers from the outposts back to the actual upstream
    auth_request_set $authentik_username $upstream_http_x_authentik_username;
    auth_request_set $authentik_groups $upstream_http_x_authentik_groups;
    auth_request_set $authentik_email $upstream_http_x_authentik_email;
    auth_request_set $authentik_name $upstream_http_x_authentik_name;
    auth_request_set $authentik_uid $upstream_http_x_authentik_uid;

    proxy_set_header X-authentik-username $authentik_username;
    proxy_set_header X-authentik-groups $authentik_groups;
    proxy_set_header X-authentik-email $authentik_email;
    proxy_set_header X-authentik-name $authentik_name;
    proxy_set_header X-authentik-uid $authentik_uid;
}

# all requests to /outpost.goauthentik.io must be accessible without authentication
location /outpost.goauthentik.io {
    proxy_pass              http://192.168.100.200:7000/outpost.goauthentik.io;
    # ensure the host of this vserver matches your external URL you've configured
    # in authentik
    proxy_set_header        Host $host;
    proxy_set_header        X-Original-URL $scheme://$http_host$request_uri;
    add_header              Set-Cookie $auth_cookie;
    auth_request_set        $auth_cookie $upstream_http_set_cookie;
    proxy_pass_request_body off;
    proxy_set_header        Content-Length "";
}

# Special location for when the /auth endpoint returns a 401,
# redirect to the /start URL which initiates SSO
location @goauthentik_proxy_signin {
    internal;
    add_header Set-Cookie $auth_cookie;
    return 302 /outpost.goauthentik.io/start?rd=$request_uri;
    # For domain level, use the below error_page to redirect to your authentik server with the full redirect path
    # return 302 https://auth.anexcore.com/outpost.goauthentik.io/start?rd=$scheme://$http_host$request_uri;
}


My authentik is running healthy on docker with the following ports:
http://192.168.100.200:7000
https://192.168.100.200:7443

If I remove the above code from the advanced tab and access proxmox.<domain name>.com , then the console works fine, so i guess somewhere in this code its having issues. BTW this code is provided by Authentik itself to put in nginx proxy manager advanced tab so nginx routes to authentik first for authentication.

Please help me out how to get console working from outside.
 
Last edited:
anyone having issue with this add the following lines in your proxy_host <ID>.conf or advanced tab with authentik code
under

# proxy_set_header ...
<-------------------paste the following lines------------------->
Code:
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_http_version 1.1;
 
Last edited:
  • Like
Reactions: LeLuc
anyone having issue with this add the following lines in your proxy_host <ID>.conf or advanced tab with authentik code
under

# proxy_set_header ...
<-------------------paste the following lines------------------->
Code:
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_http_version 1.1;
Could you post your complete code for the advanced tab? I cannot get this working …
 
Could you post your complete code for the advanced tab? I cannot get this working …
here it is :


Code:
# Increase buffer size for large headers
# This is needed only if you get 'upstream sent too big header while reading response
# header from upstream' error when trying to access an application protected by goauthentik
proxy_buffers 8 16k;
proxy_buffer_size 32k;

# Make sure not to redirect traffic to a port 4443
port_in_redirect off;

location / {
    # Put your proxy_pass to your application here
    proxy_pass          $forward_scheme://$server:$port;
    # Set any other headers your application might need
    # proxy_set_header Host $host;
    # proxy_set_header ...
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_http_version 1.1;

    ##############################
    # authentik-specific config
    ##############################
    auth_request     /outpost.goauthentik.io/auth/nginx;
    error_page       401 = @goauthentik_proxy_signin;
    auth_request_set $auth_cookie $upstream_http_set_cookie;
    add_header       Set-Cookie $auth_cookie;

    # translate headers from the outposts back to the actual upstream
    auth_request_set $authentik_username $upstream_http_x_authentik_username;
    auth_request_set $authentik_groups $upstream_http_x_authentik_groups;
    auth_request_set $authentik_email $upstream_http_x_authentik_email;
    auth_request_set $authentik_name $upstream_http_x_authentik_name;
    auth_request_set $authentik_uid $upstream_http_x_authentik_uid;

    proxy_set_header X-authentik-username $authentik_username;
    proxy_set_header X-authentik-groups $authentik_groups;
    proxy_set_header X-authentik-email $authentik_email;
    proxy_set_header X-authentik-name $authentik_name;
    proxy_set_header X-authentik-uid $authentik_uid;
}

# all requests to /outpost.goauthentik.io must be accessible without authentication
location /outpost.goauthentik.io {
    proxy_pass              http://192.168.100.200:7000/outpost.goauthentik.io;
    # ensure the host of this vserver matches your external URL you've configured
    # in authentik
    proxy_set_header        Host $host;
    proxy_set_header        X-Original-URL $scheme://$http_host$request_uri;
    add_header              Set-Cookie $auth_cookie;
    auth_request_set        $auth_cookie $upstream_http_set_cookie;
    proxy_pass_request_body off;
    proxy_set_header        Content-Length "";
}

# Special location for when the /auth endpoint returns a 401,
# redirect to the /start URL which initiates SSO
location @goauthentik_proxy_signin {
    internal;
    add_header Set-Cookie $auth_cookie;
    return 302 /outpost.goauthentik.io/start?rd=$request_uri;
    # For domain level, use the below error_page to redirect to your authentik server with the full redirect path
    # return 302 https://auth.anexcore.com/outpost.goauthentik.io/start?rd=$scheme://$http_host$request_uri;
}


This is the code that makes the console work in nginx with Authentik:

Code:
    proxy_pass $forward_scheme://$server:$port;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_http_version 1.1;
 
Last edited:
Hello thimplicity,
I had the same issue but using Anexgohan's response I was able to get my config working for proxmox in addition to octoprint, etc. The lines they are talking about adding are bolded in my full config below. Hope this helps!

NGINX:
# Increase buffer size for large headers
# This is needed only if you get 'upstream sent too big header while reading response
# header from upstream' error when trying to access an application protected by goauthentik
proxy_buffers 8 16k;
proxy_buffer_size 32k;

# Make sure not to redirect traffic to a port 4443
port_in_redirect off;

location / {
    # Put your proxy_pass to your application here
    proxy_pass          $forward_scheme://$server:$port;
    # Set any other headers your application might need
    # proxy_set_header Host $host;
    # proxy_set_header ...
[B]    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_http_version 1.1;[/B]

    ##############################
    # authentik-specific config
    ##############################
    auth_request     /outpost.goauthentik.io/auth/nginx;
    error_page       401 = @goauthentik_proxy_signin;
    auth_request_set $auth_cookie $upstream_http_set_cookie;
    add_header       Set-Cookie $auth_cookie;

    # translate headers from the outposts back to the actual upstream
    auth_request_set $authentik_username $upstream_http_x_authentik_username;
    auth_request_set $authentik_groups $upstream_http_x_authentik_groups;
    auth_request_set $authentik_email $upstream_http_x_authentik_email;
    auth_request_set $authentik_name $upstream_http_x_authentik_name;
    auth_request_set $authentik_uid $upstream_http_x_authentik_uid;

    proxy_set_header X-authentik-username $authentik_username;
    proxy_set_header X-authentik-groups $authentik_groups;
    proxy_set_header X-authentik-email $authentik_email;
    proxy_set_header X-authentik-name $authentik_name;
    proxy_set_header X-authentik-uid $authentik_uid;
}

# all requests to /outpost.goauthentik.io must be accessible without authentication
location /outpost.goauthentik.io {
    proxy_pass              https://192.168.0.110/outpost.goauthentik.io;

    # ensure the host of this vserver matches your external URL you've configured
    # in authentik
    proxy_set_header        Host $host;
    proxy_set_header        X-Original-URL $scheme://$http_host$request_uri;
    add_header              Set-Cookie $auth_cookie;
    auth_request_set        $auth_cookie $upstream_http_set_cookie;
    proxy_pass_request_body off;
    proxy_set_header        Content-Length "";
}

# Special location for when the /auth endpoint returns a 401,
# redirect to the /start URL which initiates SSO
location @goauthentik_proxy_signin {
    internal;
    add_header Set-Cookie $auth_cookie;
    return 302 /outpost.goauthentik.io/start?rd=$request_uri;
    # For domain level, use the below error_page to redirect to your authentik server with the full redirect path
    # return 302 https://auth.yourcooldomain.com/outpost.goauthentik.io/start?rd=$scheme://$http_host$request_uri;
}
 
Correction to my previous post, if you want to run octoprint you will need this config:
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Scheme $scheme;
proxy_http_version 1.1;
client_max_body_size 0;

https://community.octoprint.org/t/c...t-can-reach-from-another-raspberry-pi/17283/6

May not apply to your original question but is a helpful nugget of information!
Have a great day!
 
  • Like
Reactions: thimplicity
Hello thimplicity,
I had the same issue but using Anexgohan's response I was able to get my config working for proxmox in addition to octoprint, etc. The lines they are talking about adding are bolded in my full config below. Hope this helps!

NGINX:
# Increase buffer size for large headers
# This is needed only if you get 'upstream sent too big header while reading response
# header from upstream' error when trying to access an application protected by goauthentik
proxy_buffers 8 16k;
proxy_buffer_size 32k;

# Make sure not to redirect traffic to a port 4443
port_in_redirect off;

location / {
    # Put your proxy_pass to your application here
    proxy_pass          $forward_scheme://$server:$port;
    # Set any other headers your application might need
    # proxy_set_header Host $host;
    # proxy_set_header ...
[B]    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-Proto $scheme;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_http_version 1.1;[/B]

    ##############################
    # authentik-specific config
    ##############################
    auth_request     /outpost.goauthentik.io/auth/nginx;
    error_page       401 = @goauthentik_proxy_signin;
    auth_request_set $auth_cookie $upstream_http_set_cookie;
    add_header       Set-Cookie $auth_cookie;

    # translate headers from the outposts back to the actual upstream
    auth_request_set $authentik_username $upstream_http_x_authentik_username;
    auth_request_set $authentik_groups $upstream_http_x_authentik_groups;
    auth_request_set $authentik_email $upstream_http_x_authentik_email;
    auth_request_set $authentik_name $upstream_http_x_authentik_name;
    auth_request_set $authentik_uid $upstream_http_x_authentik_uid;

    proxy_set_header X-authentik-username $authentik_username;
    proxy_set_header X-authentik-groups $authentik_groups;
    proxy_set_header X-authentik-email $authentik_email;
    proxy_set_header X-authentik-name $authentik_name;
    proxy_set_header X-authentik-uid $authentik_uid;
}

# all requests to /outpost.goauthentik.io must be accessible without authentication
location /outpost.goauthentik.io {
    proxy_pass              https://192.168.0.110/outpost.goauthentik.io;

    # ensure the host of this vserver matches your external URL you've configured
    # in authentik
    proxy_set_header        Host $host;
    proxy_set_header        X-Original-URL $scheme://$http_host$request_uri;
    add_header              Set-Cookie $auth_cookie;
    auth_request_set        $auth_cookie $upstream_http_set_cookie;
    proxy_pass_request_body off;
    proxy_set_header        Content-Length "";
}

# Special location for when the /auth endpoint returns a 401,
# redirect to the /start URL which initiates SSO
location @goauthentik_proxy_signin {
    internal;
    add_header Set-Cookie $auth_cookie;
    return 302 /outpost.goauthentik.io/start?rd=$request_uri;
    # For domain level, use the below error_page to redirect to your authentik server with the full redirect path
    # return 302 https://auth.yourcooldomain.com/outpost.goauthentik.io/start?rd=$scheme://$http_host$request_uri;
}
Thanks! three questions:

1. Do you need to create a separate nginx outpost in authetik for this?
2. Do I only need to add my IP:port behind proxy_pass twice or only for the authentik specific portion?
3. Do I need to create an additional proxmox proxy provider in addition to the OpenID provider I already have?
 
Last edited:
I'm having trouble with the above advanced config: I used Authentik's instructions for setup (link), and I can successfully authenticate with Authentik directly (e.g., using the Authentik realm in PVE login). But that of course doesn't 'force' a potential visitor to use Authentik. So, as soon as I add the above advanced config to NPM, I get a 500 error trying to connect to proxmox.mydomain.com. I use my IP: Port in the advanced config, and have no 500 error with my other npm + Authentik apps. That being said PVE is the only one using OpenID so I may be missing something. Any ideas/suggestions? Thanks all
 
I'm having trouble with the above advanced config: I used Authentik's instructions for setup (link), and I can successfully authenticate with Authentik directly (e.g., using the Authentik realm in PVE login). But that of course doesn't 'force' a potential visitor to use Authentik. So, as soon as I add the above advanced config to NPM, I get a 500 error trying to connect to proxmox.mydomain.com. I use my IP: Port in the advanced config, and have no 500 error with my other npm + Authentik apps. That being said PVE is the only one using OpenID so I may be missing something. Any ideas/suggestions? Thanks all
How did you get the direkt OpenID connection work? I think I have tried everything, but I cannot get it wo work.
 
Thanks! three questions:

1. Do you need to create a separate nginx outpost in authetik for this?
2. Do I only need to add my IP:port behind proxy_pass twice or only for the authentik specific portion?
3. Do I need to create an additional proxmox proxy provider in addition to the OpenID provider I already have?
In Authentik it's very simple:



1. Under Providers:

create provider with

name: proxmox

Authorization flow: default-provider-authorization-implicit-consent (Authorize Application)

Forward auth (single application)

external host:https://proxmox.domain.com



2. Under Applications:

create application with

name: proxmox

slug: proxmox

provider: proxmox

engine policy+any

Launch URL:https://proxmox.domain.com



3. In Outpost

in you current working "Outpost" enable under "Applications" select "proxmox"

make sure under "Configuration" authentik_host: https://example.domain.com or ip adress is set properly

where https://example.domain.com is where you can reach the authentik page



4. Under Providers:

copy the text under Setup>Nginx(Proxy Manager)

adding under "# Set any other headers your application might need"

the required proxy configurations like :



Code:
proxy_pass $forward_scheme://$server:$port;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-Proto $scheme;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_set_header Upgrade $http_upgrade;

proxy_set_header Connection "upgrade";

proxy_http_version 1.1;



and also change the following line

Code:
proxy_pass              http://outpost.company:9000/outpost.goauthentik.io;

to

Code:
proxy_pass              http://<ip adress of authentik>:<port>/outpost.goauthentik.io;


paste this modified code in the Nginx Proxy Manager advanced tab of your proxmox host entry
 
Last edited:
I'm having trouble with the above advanced config: I used Authentik's instructions for setup (link), and I can successfully authenticate with Authentik directly (e.g., using the Authentik realm in PVE login). But that of course doesn't 'force' a potential visitor to use Authentik. So, as soon as I add the above advanced config to NPM, I get a 500 error trying to connect to proxmox.mydomain.com. I use my IP: Port in the advanced config, and have no 500 error with my other npm + Authentik apps. That being said PVE is the only one using OpenID so I may be missing something. Any ideas/suggestions? Thanks all
read my comment above, hopefully it will solve your issues.
 
How did you get the direkt OpenID connection work? I think I have tried everything, but I cannot get it wo work.
read my comment above, hopefully it will solve your issues.
Thanks so much for that! Can I clarify: would creating this forwardauth provider/app/outpost be in addition to the openID/OpenAuth2 provider/app that I already created? The OpenID pathway allows for single-sign-on with promox PVE (and works well) - here’s the link for the setup, it’s brief (https://goauthentik.io/integrations/services/proxmox-ve/). Would I just essentially have two providers/apps then?
 
Thanks so much for that! Can I clarify: would creating this forwardauth provider/app/outpost be in addition to the openID/OpenAuth2 provider/app that I already created? The OpenID pathway allows for single-sign-on with promox PVE (and works well) - here’s the link for the setup, it’s brief (https://goauthentik.io/integrations/services/proxmox-ve/). Would I just essentially have two providers/apps then?
I had the same thought. You will need to get both working separately. The only advantage (at least in my eyes) with two providers is that when you do both, when you open proxmox, you get the authentik login first and then you can login into proxmox with one click. If you only do OpenID and not the proxy, you will see proxmox first and then after clicking on login, you will be redirected to authentik to log in. I like it more to have the login first and then the app login, because it is cleaner from a user experience in my eyes to have the login first across all applications.
 
I had the same thought. You will need to get both working separately. The only advantage (at least in my eyes) with two providers is that when you do both, when you open proxmox, you get the authentik login first and then you can login into proxmox with one click. If you only do OpenID and not the proxy, you will see proxmox first and then after clicking on login, you will be redirected to authentik to log in. I like it more to have the login first and then the app login, because it is cleaner from a user experience in my eyes to have the login first across all applications.

To follow-up:

As far as I can tell I have Authentik working with NPM to access the Proxmox VE using both OpenID and Forward Authentication. My desired outcome is to put Proxmox VE behind Authentik (forwardauth), and have a convenient openID login (OpenID). This makes it almost single-sign-on with Authentik.

1. Setup ForwardAuth as above (called the provider Proxmox ForwardAuth)
2. Setup OpenID per the guide linked above (called the provider Proxmox), though I omitted (did not include) the port number where it says to in the guide since I mapped the port in NPM to proxmox.mydomain.com already.

Noting that there are two apps, two providers, and one outpost in Authentik now for Proxmox, but it seems to work as expected. I'm not sure if there's a 'smarter' way to do this.

@thimplicity, your OpenID issue may be Let's Encrypt. I recall reading somewhere that PVE might not like Let's Encrypt (I don't remember the source, so I may be wrong). My certs are cloudflare SSL origin certs
 
@thimplicity, your OpenID issue may be Let's Encrypt. I recall reading somewhere that PVE might not like Let's Encrypt (I don't remember the source, so I may be wrong). My certs are cloudflare SSL origin certs
I got this fixed with the help of the Authentik discord channel. At the end I just had to leave the redirect URI in authentik empty and it pulled in the correct one from the provider.
 
Thanks so much for that! Can I clarify: would creating this forwardauth provider/app/outpost be in addition to the openID/OpenAuth2 provider/app that I already created? The OpenID pathway allows for single-sign-on with promox PVE (and works well) - here’s the link for the setup, it’s brief (https://goauthentik.io/integrations/services/proxmox-ve/). Would I just essentially have two providers/apps then?
well, this is new i guess, it was not there when i switched to authentik, seems easy enough, but I cant help you with it, since i've already set it up the other way. Give it a try let me know how goes.
 
I had the same thought. You will need to get both working separately. The only advantage (at least in my eyes) with two providers is that when you do both, when you open proxmox, you get the authentik login first and then you can login into proxmox with one click. If you only do OpenID and not the proxy, you will see proxmox first and then after clicking on login, you will be redirected to authentik to log in. I like it more to have the login first and then the app login, because it is cleaner from a user experience in my eyes to have the login first across all applications.
it will be authenticate with authentik first or no access. I cant say about the other way ( openID/OpenAuth).
 
Last edited:
well, this is new i guess, it was not there when i switched to authentik, seems easy enough, but I cant help you with it, since i've already set it up the other way. Give it a try let me know how goes.
Tried and working! In simple terms I go to https://promox.mydomain.com -> Authentik login screen pops up -> enter password, success -> PVE login -> click openID login button -> PVE (no need to enter second password).

So it basically captures and forces an Authentik login and it is almost a single-sign on from there, with the exception of having to manually click the OpenID login button (no need for a separate login here which is nice). As a result I have two proxmox apps and providers in authentik, and I just named them proxmox forwardauth and proxmox openID.

Tl;dr yes, can have almost an SSO experience on with authentik, NPM, and proxmox pve with an OpenID provider and a ForwardAuth provider in Authentik
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!