Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for conneting to Navidrome behind a reverse proxy with basic authentication #16

Open
e1pex opened this issue Jan 29, 2023 · 7 comments
Assignees

Comments

@e1pex
Copy link

e1pex commented Jan 29, 2023

As it's a bit of best practice to protect your Navidrome installation behind an reverse proxy, preferably with authentication when it's exposed to internet it would be great to have Feishin support basic authentication as an option to the native Navidrome authentication.

@jeffvli jeffvli self-assigned this Jan 29, 2023
@jeffvli jeffvli linked a pull request Feb 5, 2023 that will close this issue
@jeffvli
Copy link
Owner

jeffvli commented Feb 5, 2023

I'm having a bit of trouble with the implementation on this.

I set up basic auth on one of my navidrome instances, but it's returning a CORS error when trying to authenticate from the frontend. When testing with basic auth using a HTTP client (Insomnia), it works fine.

Can you test on your side if you experience the same issues? You can use the build on #23 to test once it finishes.

My error:

Access to fetch at 'https://demo.sonixd.com/auth/login' from origin 'http://localhost:4343' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

image

@jeffvli jeffvli added the help wanted Extra attention is needed label Feb 5, 2023
Repository owner deleted a comment from e1pex Feb 6, 2023
@jeffvli
Copy link
Owner

jeffvli commented Feb 6, 2023

@e1pex I removed your comment since you may have accidently put your credentials in your comment. (From the logs).
Recopied it here without the logs.

Hi Jeff

I just did a quick test and I can't get it to work either. I get a 401 error with the new feishin build with CORS disabled (and a new config directory) but it works with a Sonixd instance with same credentials and server.

From the logs it seems sonixd newer does a POST for the auth/login as feishin does, i dont now if that is any clue?

192.168.xxx.129 - - [06/Feb/2023:07:01:46 +0100] "GET / HTTP/2.0" 401 172 "-""Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0""-"
192.168.xxx.129 - - [06/Feb/2023:07:02:18 +0100] "POST /auth/login HTTP/2.0" 401 574 "-""Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) feishin/0.0.1-alpha4 Chrome/106.0.5249.199 Electron/21.4.0 Safari/537.36""-"
192.168.xxx.129 - - [06/Feb/2023:07:04:08 +0100] "POST /auth/login HTTP/2.0" 401 574 "-""Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) feishin/0.0.1-alpha4 Chrome/106.0.5249.199 Electron/21.4.0 Safari/537.36""-"
192.168.xxx.129 - - [06/Feb/2023:07:08:28 +0100] "GET /rest/getMusicFolders.view?u=redacted&s=redacted&t=redacted&v=1.13.0&c=sonixd&f=json HTTP/2.0" 200 164 "-""Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Sonixd/0.15.3 Chrome/91.0.4472.164 Electron/13.6.3 Safari/537.36""-"
192.168.xxx.129 - - [06/Feb/2023:07:08:28 +0100] "GET /rest/getPlaylists.view?u=redacted&s=redacted&t=redacted&v=1.13.0&c=sonixd&f=json HTTP/2.0" 200 543 "-""Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Sonixd/0.15.3 Chrome/91.0.4472.164 Electron/13.6.3 Safari/537.36""-"

I'm of for work now but if needed I can do some more troubleshooting later this evening.

Regards
Torbjörn

@e1pex
Copy link
Author

e1pex commented Feb 6, 2023

No worries about the credentials in the previous post, they where not real ones.

I did some more testing, when first adding the server with basic authentication checked I get this in the nginx log when clicking Add,

192.168.xxx.129 - redacted [06/Feb/2023:19:44:29 +0100] "POST /auth/login HTTP/2.0" 200 375 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) feishin/0.0.1-alpha4 Chrome/106.0.5249.199 Electron/21.4.0 Safari/537.36" "-"
192.168.xxx.129 - - [06/Feb/2023:19:44:29 +0100] "GET /api/playlist?_end=100&_order=ASC&_sort=name&_start=0 HTTP/2.0" 401 574 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) feishin/0.0.1-alpha4 Chrome/106.0.5249.199 Electron/21.4.0 Safari/537.36" "-"

So it seems Feishin manages to log in once, the config is accepted and then Feishin is reloaded?

But after the reload the server shows up as disconnected and any attempt to get it to reconnect by readding the password results in a 401 in the nginx logs

Screenshot from 2023-02-06 19-57-04

192.168.xxx.129 - - [06/Feb/2023:19:52:26 +0100] "POST /auth/login HTTP/2.0" 401 574 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) feishin/0.0.1-alpha4 Chrome/106.0.5249.199 Electron/21.4.0 Safari/537.36" "-"

In the server config view the basic auth config is missing after the reload, could it be that the basic auth config is lost after the application reload?

Screenshot from 2023-02-06 19-57-50

Is the CORS error you get from the reverse proxy or from Navidrome? Because I don't se that at all on my side.

@jeffvli
Copy link
Owner

jeffvli commented Feb 6, 2023

Hmm, if you're not getting an error on the login, then it might just be an issue on my side.

I actually didn't pass-through the basic auth to all the API requests since I wanted to make sure that the login itself was working. Let me make some changes and then you can test again.

@jeffvli
Copy link
Owner

jeffvli commented Feb 6, 2023

I did a bit more testing but unfortunately it's probably not going to be feasible to get basic auth working.

While browsing through your server works, the audio player that's being used (mpv) has trouble accessing the audio stream.
Even adding credentials in the URL does not seem to work (e.g. http://username:[email protected]).

There's a feature request that I saw regarding this but unfortunately not updates in some time. mpv-player/mpv#2689

@jeffvli jeffvli removed a link to a pull request Feb 8, 2023
@e1pex
Copy link
Author

e1pex commented Feb 8, 2023

Ok I see, do you want to close this for now then? I might do some digging to see if its possible to find a solution but I can't make a promise on timeline for it.

@jeffvli
Copy link
Owner

jeffvli commented Feb 8, 2023

Actually I was wrong, apparently basic auth can work with mpv, just that there's no dedicated parameters to insert them.

It wasn't working when I was testing it previously... but trying the URL directly from the mpv commandline seems to work.
I'll try to implement this again when I have time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

No branches or pull requests

2 participants