mirror of
https://github.com/pikvm/pikvm.git
synced 2026-03-02 18:16:56 -05:00
Cannot login behind reverse proxy #945
Labels
No labels
component:documentation
help wanted
resolution:delayed
resolution:duplicate
resolution:fixed
resolution:invalid
resolution:rejected
resolution:wontfix
success story
type:bug
type:bug
type:feature
type:question
type:question
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/pikvm-pikvm#945
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Andrew17856 on GitHub (Sep 22, 2024).
Originally assigned to: @mdevaev on GitHub.
When attempting to login behind a https based reverse proxy, typing in the correct username and password just takes you back to the login screen.
If you enter wrong credential, it'll show "Invalid credentials". So the password is being sent, but once validated, it appears the redirection to the main screen is not working.
If you manually type in the PiKVM web address, having entered in the correct username/password, with the suffix /kvm then you can get to the main screen.
It therefore appears the login is working, but the redirection once logged in does not.
To Reproduce
Expected behavior
It should login, and redirect to the main screen. But doesn't.
Desktop (please complete the following information):
Windows 10 - does it on Chrome, Firefox and Edge
PiKVM info:
KVMD: 4.8
Streamer: 6.13 (ustreamer)
HAS_PDEATHSIG: Yes
WITH_GPIO: Yes
WITH_PTHREAD_NP: Yes
WITH_SETPROCTITLE: Yes
WITH_SYSTEMD: Yes
Linux kernel:
Machine: armv7l
Release: 6.6.45-4-rpi
Version: #1 SMP Wed Aug 28 12:37:41 UTC 2024
@mdevaev commented on GitHub (Sep 22, 2024):
Please share the proxy config.
@Andrew17856 commented on GitHub (Sep 23, 2024):
There isn't really much configuration for the proxy.
There is an external domain, let's call it www.mydomain.com
I connect to that via a browser, and authenticate into the reverse proxy and then I'm presented with the various resources behind it, including the PiKVM.
If I click on the PiKVM icon, I'm taken to pikvm.mydomain.com, which then shows the login screen of the PiKVM.
Behind the scenes, you configure in VPNPlus (the reverse proxy) the custom subdomain (i.e. pikvm.mydomain.com), and the private IP address of the resource, say 192.168.1.100
VPNPlus takes care of the rest, and tunnels traffic from one to the other.
The issue is that when I login, the PiKVM doesn't redirect to the main screen, it just loops around to the login screen again.
If I manually type in pikvm.mydomain.com/kvm, then I can successfully get to the main KVM page.
@mdevaev commented on GitHub (Sep 23, 2024):
Based on the fact that other reverse proxies do not cause similar problems, I'm inclined to believe that this is a problem on the VPNPlus side.
You can try the developer's tool in the browser to track the cause of the loop.
Also you should contact our Discord support with such questions, because Github is only for bugs.
@Andrew17856 commented on GitHub (Sep 24, 2024):
Thanks. I've checked, and the issue is what I thought it would be.
The PiKVM doesn't recognise it's behind a reverse proxy - which means I doubt it will work on any other reverse proxy software. Can you give some examples of reverse proxies where it's confirmed working and I can try them if it would help?
When you click login, the redirect is to the PiKVM's local address, not the external proxied address.
So, using my example above, when you click login, the redirect (that you can see in the developer console in the browser) is as below:
https://pikvm.mydomain.com/webportal.cgi?go=http://192.168.1.100/share/site.webmanifest
(note the local address for the redirect) ... whereas to work behind the proxy it needs to be:
https://pikvm.mydomain.com/webportal.cgi?go=https://pikvm.mydomain.com/share/site.webmanifest
@mdevaev commented on GitHub (Sep 24, 2024):
The regular nginx is working fine. Tailscale also working fine too.
Ah, I see. Your proxy breaks addressing and argument handling. Of course, nothing will work in this case.
@Andrew17856 commented on GitHub (Sep 24, 2024):
Thanks. I think we're using terminology differently.
I'm talking here about secure gateways - a web based proxy that you log into first (eg with 2FA), before being presented with a web page with the various resources. You click the one you want, and then the resource (eg the PiKVM) is channeled through the same web portal. Importantly, (i) it's clientless - you just need a browser; (ii) you only need one port eg https no matter how many or what type of resource you're accessing and (iii) you have to authenticate first (it's not just exposing the PiKVM to the Internet.
Cf Tailscale - that's Wireguard based and you need to install a client. It basically creates a VPN tunnel.
Cf nginx, that is a proxy as you say, but it's basically a fancy way of simultaneously exposing multiple resources to the Internet. There are addons (eg auth portal) that get closer but it still doesn't have the gateway type functionality.
Neither dynamically remap the https requests which is what a genuine web based reverse proxy/portal tries to do.
Re the "nothing will work in this case", if you have a look at how other products deal with it, there's an option to specify whether it's behind a portal, where you can specify the externally facing address (see eg ReadyNAS devices) - it's usually called domain masquerading, "masquerade as" or something similar). So in the case of the PiKVM, you'd enter pikvm.mydomain.com as an option in the PiKVM UI, and then on the redirect on login the PiKVM would substitute that address for the local one.
Obviously this is a feature request rather than a bug, so entirely up to you if you want to implement it to bring the PiKVM into line with other remote access solutions that work behind portals (eg Lantronix etc).
In the meantime, the workaround is to enter the redirect manually once logged in.
The PiKVM is a great bit of kit by the way, so thank you for that. It's a much more pleasant experience (eg low latency) than other solutions out there.
@mdevaev commented on GitHub (Nov 30, 2024):
Is there any easy way to reproduce your proxy environment locally? I'm ready to look at it if you show me how to do it.
@Andrew17856 commented on GitHub (Dec 10, 2024):
Sorry for the delay in replying to this.
It would be quite difficult to reproduce the proxy environment without actually buying the hardware.
Hopefully there's enough information in the above to be able to build the required functionality? It's effectively recognising when the PiKVM is behind a proxy and then remapping the redirect post login so that it uses the pubicly routable domain.
It occurred to me afterwards that you might actually be able to use javascript in the end-user page to get the public facing domain, which can then be used by the PiKVM as the basis of the redirect. That would be best, as it would mean that the PiKVM could detect when it's behind a proxy - bearing in mind that a user could also be accessing it from the LAN (in which case you wouldn't need to remap the redirect).
I'm very happy to test any implementation if that would assist.
Thank you for your help.
@MichaelWoodc commented on GitHub (Jan 21, 2025):
Hey so on services like Navidrome, I can edit the base url inside their config files for it to return /navidrome, as a base path, for example. And that works great! If PiKVM had a similar way to append a base path / url to the paths / urls it sends out that would solve all of the problems or at least make it much easier. I have not had any luck due to various reasons with this url scheme, so, I just wend ahead and used a subdomain to forward to the pikvm to bypass the inability to change the base url.
Sorry I know this might not be the solution you're looking for. But absent an easy to change setting in pikvm it is not easy to implement with the nginx reverse proxy. Although this got me close:
@mdevaev commented on GitHub (Feb 2, 2025):
@Andrew17856 I made some changes in reverse proxy handling, please try the latest OS version. It should work now. Also check a new reverse proxy guide: https://docs.pikvm.org/reverse_proxy
@Andrew17856 commented on GitHub (Feb 9, 2025):
Many thanks for updating this. Can I check whether this has been pushed to release or still in beta? I updated my pikvm in the usual way (i.e. pikvm-update) but it still exhibits the same behaviour.
I've read the new explanatory section in the link, but I don't think any further proxy configuration is needed at my end. The pikvm is allocated its own subdomain, which is what the proxy uses to route traffic through the reverse proxy. As mentioned above, the issue before was that the pikvm wasn't aware of that, and so doesn't use the right url in the redirect post login.
@mdevaev commented on GitHub (Feb 9, 2025):
Can you send me to email (mdevaev@gmail.com) the network log from devtools, when you're logging in? I don't understand where it breaks. Or, alternatively, we can contact Discord and you could set up a Teamviewer (or RustDesk) session for me so that I can debug it in your environment.
@Andrew17856 commented on GitHub (Feb 9, 2025):
I'll share the full unedited har file over e-mail, but the issue is the same as before. The http go request that is fired off post login isn't tailored to the external url.
So e.g. (from the HAR file, redacted for privacy)
"request": { "method": "GET", "url": "https://www.[myurl].co.uk/webportal.cgi?go=http://192.168.x.x:80/share/site.webmanifest", "httpVersion": "HTTP/1.1", "headers": [The bit after the "go" needs to have the external url substituted.
The neatest way to do it would be to use the "window.location" property in JavaScript to read the current url client-side, then do some string manipulation to get the redirect address.
@mdevaev commented on GitHub (Feb 9, 2025):
Did you remove cookies/auth tokens too? If so, you should have changed the values to fake ones instead of deleting them altogether, because what I see so far hints at a lack of authorization, and I don't understand who is to blame for this.
@Andrew17856 commented on GitHub (Feb 9, 2025):
No I haven't changed anything in the logs in relation to cookies.
I think it is authorising ok, in that if I manually redirect by typing in
pikvm.[myurl].co.uk/kvm after typing in the password, I get straight in.
If it's doing that without properly authorising then that's a different issue!
Andrew
--- Original message ---
From: Maxim Devaev @.***
Sent: 9 February 2025 14:16:43
To: pikvm/pikvm @.***
CC: Andrew17856 @., Mention @.
Subject: Re: [pikvm/pikvm] Cannot login behind reverse proxy (Issue #1404)
--194eb16eea72c08286546db447
<html> <head>Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
--194eb16eea72c08286546db447--
@mdevaev commented on GitHub (Feb 9, 2025):
So the problem is an incorrect redirect after login?
Let me clarify. Please confirm or deny the following:
@Andrew17856 commented on GitHub (Feb 9, 2025):
Yes, I think that's the most likely explanation. However, having had a closer look, I think the webportal.cgi is actually coming from the proxy rather than the pikvm. So, for whatever reason, they're not playing nicely together.
Re your bullets (and some other things I've checked too):
Hope this helps.
@mdevaev commented on GitHub (Feb 9, 2025):
The
webportal.cgiis not a part of PiKVM code. Probably it's something in your proxy.I have a strong feeling that your proxy is caching a 302 redirect from
/ to/login`. Please logout, open devtools and set "Disable cache" checkbox on the network tab. Then try to login again. Will it work?@Andrew17856 commented on GitHub (Feb 9, 2025):
Yes, that looks to be it - it works with the cache disabled.
Is the reason that the landing page (i.e. when you navigate to the pikvm initially) is the same page to which the user is redirected post login? So if it's cached, it takes you back to login.
If the menu had a distinct url (e.g. /menu) that would prevent the cache from being confused by the fact that the previous time it saw the url (without any slash) it redirected to login.
So in other words, / redirects to /login, but after signing in with the password, the PiKVM does a redirect to /menu ... which won't previously be cached.
@mdevaev commented on GitHub (Feb 9, 2025):
Let's try to hotfix it. Find file
/etc/kvmd/nginx/kvmd.ctx-server.confand edit it (it is read-only, so you will need to make it writable first).Find this section:
And make it like this:
After that run
systemctl restart kvmd-nginx. Please note that you should NEVER edit read-only configs in usual cases. It's only for debugging. Check if everything is working with devtools and without after that. If so, revert changes and restore permissions to avoid update problems.@mdevaev commented on GitHub (Feb 10, 2025):
@Andrew17856 I've released the fix above so you can take it from
pikvm-update. Please let me know if something is not working.@Andrew17856 commented on GitHub (Feb 11, 2025):
Many thanks - this works now. Thank you for taking the time to resolve this.
--- Original message ---
From: Maxim Devaev @.***
Sent: 10 February 2025 19:57:07
To: pikvm/pikvm @.***
CC: Andrew17856 @., Mention @.
Subject: Re: [pikvm/pikvm] Cannot login behind reverse proxy (Issue #1404)
--194f3e16e684b652865eb65b79
<html> <head>Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
--194f3e16e684b652865eb65b79--
@stappersg commented on GitHub (Feb 11, 2025):
On Mon, Feb 10, 2025 at 11:21:06PM -0800, Andrew17856 wrote:
Elsewhere in this project, "pikvm", I did read something like
} } I clicked on donate button to express my gratitude,
} } I hope it buys you a beer.
}
} Thank you!
}
Where is that button?
@mdevaev commented on GitHub (Feb 11, 2025):
Awesome!
You can donate me with two ways (it's on the main page https://github.com/pikvm/pikvm):
Thank you!