Skip to content

fix wrong base_url in reverse_proxy scenario to connect WSS#3855

Closed
nerzhul wants to merge 1 commit into
music-assistant:devfrom
nerzhul:feat/callback_url
Closed

fix wrong base_url in reverse_proxy scenario to connect WSS#3855
nerzhul wants to merge 1 commit into
music-assistant:devfrom
nerzhul:feat/callback_url

Conversation

@nerzhul
Copy link
Copy Markdown

@nerzhul nerzhul commented May 8, 2026

In reverse proxy scenario, like in Kubernetes, music-assistant cannot be reached through websocket, we got a 502 after setting the base_url parameter.

There is a dynamic configuration to handle base_url but in WebsocketClientHandler::handle_client we send the configured one and not the detected one

Copilot AI review requested due to automatic review settings May 8, 2026 10:59
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a configurable authentication callback URL so OAuth-style provider flows (e.g., Home Assistant) can redirect to a different externally reachable URL than the internally used base_url (useful behind reverse proxies / Kubernetes ingress).

Changes:

  • Add callback_url support to the base Webserver helper and expose it via a new property.
  • Add a new callback_url config entry to the Webserver core controller and pass it into webserver startup.
  • Switch provider/auth redirect construction to use callback_url instead of base_url.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
music_assistant/helpers/webserver.py Extends Webserver.setup and properties to include a callback URL.
music_assistant/helpers/auth.py Uses the configured callback URL when generating auth session callback URLs.
music_assistant/controllers/webserver/controller.py Adds callback_url to webserver config and startup wiring/logging.
music_assistant/controllers/webserver/auth.py Uses callback URL for OAuth redirect URI generation.

Comment thread music_assistant/helpers/webserver.py
Comment thread music_assistant/controllers/webserver/controller.py Outdated
Comment thread music_assistant/controllers/webserver/controller.py Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

Comment thread music_assistant/controllers/webserver/controller.py Outdated
Comment thread music_assistant/controllers/webserver/controller.py Outdated
Comment thread music_assistant/controllers/webserver/controller.py Outdated
Comment thread music_assistant/controllers/webserver/controller.py Outdated
Comment thread music_assistant/controllers/webserver/controller.py
Copilot AI review requested due to automatic review settings May 8, 2026 14:05
@nerzhul nerzhul changed the title feat: permit to customize callback_url permit to customize callback_url May 8, 2026
@nerzhul nerzhul force-pushed the feat/callback_url branch 2 times, most recently from 2359c9b to 8076433 Compare May 8, 2026 14:09
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

Comment thread music_assistant/controllers/webserver/controller.py Outdated
@marcelveldt
Copy link
Copy Markdown
Member

Why did you not simply set the URL in the webserver configuration?

@nerzhul
Copy link
Copy Markdown
Author

nerzhul commented May 8, 2026

@marcelveldt unfortunately it broke the websocket communication, for a reason i don't exaclty understand. I suspect that it don't listen anymore after that on the websocket, i got a 502 and it never recover until i remove the base_url from settings.json.
After editing the setting, the app goes to connection lost mode and try to reconnect forever. Maybe my fix is not the right way, it's one of the possible solutions

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.

Copy link
Copy Markdown
Member

@marcelveldt marcelveldt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change does not make sense as this is exactly why we have the setting for the base URL. So instead of introducing a duplicate config value, a user should just make sure that the base URL is correctly configured

@marcelveldt
Copy link
Copy Markdown
Member

@marcelveldt unfortunately it broke the websocket communication, for a reason i don't exaclty understand. I suspect that it don't listen anymore after that on the websocket, i got a 502 and it never recover until i remove the base_url from settings.json. After editing the setting, the app goes to connection lost mode and try to reconnect forever. Maybe my fix is not the right way, it's one of the possible solutions

Then we should instead fix that issue instead of adding a workaround.

@nerzhul
Copy link
Copy Markdown
Author

nerzhul commented May 11, 2026

@marcelveldt unfortunately it broke the websocket communication, for a reason i don't exaclty understand. I suspect that it don't listen anymore after that on the websocket, i got a 502 and it never recover until i remove the base_url from settings.json. After editing the setting, the app goes to connection lost mode and try to reconnect forever. Maybe my fix is not the right way, it's one of the possible solutions

Then we should instead fix that issue instead of adding a workaround.

You're right, i was going the wrong way, let's try to find why in reverse proxy context with a DNS record the WS fail to connect to the backend.

@nerzhul nerzhul force-pushed the feat/callback_url branch from 942f0b8 to 05614fd Compare May 11, 2026 14:23
@nerzhul nerzhul requested a review from marcelveldt May 11, 2026 14:24
@nerzhul
Copy link
Copy Markdown
Author

nerzhul commented May 11, 2026

ok i think i have the right fix, but i'm not able to build the image due do winedevine CDM, i hope the code is sufficient there

@MarvinSchenkel
Copy link
Copy Markdown
Contributor

MarvinSchenkel commented May 11, 2026

ok i think i have the right fix, but i'm not able to build the image due do winedevine CDM, i hope the code is sufficient there

If you are not using Apple Music during your test, you could simply temporarily comment out the widevine CDM part to build a docker image for testing on your k8s setup?

@nerzhul
Copy link
Copy Markdown
Author

nerzhul commented May 11, 2026

ok i think i have the right fix, but i'm not able to build the image due do winedevine CDM, i hope the code is sufficient there

If you are not using Apple Music during your test, you could simply temporarily comment out the widevine CDM part to build a docker image for testing on your k8s setup?

thanks, let's try, cross compiling for ARM64 :)

@nerzhul
Copy link
Copy Markdown
Author

nerzhul commented May 11, 2026

@MarvinSchenkel just tested it, it works very smoothly :)

@nerzhul nerzhul changed the title permit to customize callback_url fix wrong base_url in reverse_proxy scenario to connect WSS May 11, 2026
@nerzhul nerzhul force-pushed the feat/callback_url branch from 05614fd to c3725a6 Compare May 12, 2026 05:57
Copilot AI review requested due to automatic review settings May 12, 2026 05:57
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.

CommandMessage,
ErrorResultMessage,
MessageType,
ServerInfoMessage,
Comment on lines +103 to 107
# otherwise fall back to the configured base_url
server_info = self.mass.get_server_info()
if self.base_url:
server_info.base_url = self.base_url
await self._send_message(server_info)
@nerzhul nerzhul force-pushed the feat/callback_url branch from c3725a6 to 0796c06 Compare May 12, 2026 06:41
@MarvinSchenkel
Copy link
Copy Markdown
Contributor

Please undo your test changes to the docker files

@MarvinSchenkel
Copy link
Copy Markdown
Contributor

Marking this PR as draft so we can keep track of which PRs needs our attention. Please mark as 'Ready for review' when you want us to have another look 🙏 .

@MarvinSchenkel MarvinSchenkel marked this pull request as draft May 13, 2026 10:52
@nerzhul nerzhul force-pushed the feat/callback_url branch from 0796c06 to 69913bb Compare May 13, 2026 13:21
There is a dynamic configuration to handle base_url but in handle_client
we send the configured one and not the detected one
@nerzhul nerzhul force-pushed the feat/callback_url branch from 69913bb to ca9928e Compare May 13, 2026 13:21
@nerzhul nerzhul marked this pull request as ready for review May 13, 2026 13:21
Copilot AI review requested due to automatic review settings May 13, 2026 13:21
@nerzhul
Copy link
Copy Markdown
Author

nerzhul commented May 13, 2026

@marcelveldt rebased & removed my junk, my bad

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment on lines 103 to +105
server_info = self.mass.get_server_info()
if self.base_url:
server_info.base_url = self.base_url
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot has a good point here

@OzGav OzGav added this to the 2.10.0 milestone May 18, 2026
@nerzhul
Copy link
Copy Markdown
Author

nerzhul commented May 18, 2026

i just identified this PR is not required anymore. I found the cullprint. This may required for some other things, but in my case it's not required anymore.

@nerzhul nerzhul closed this May 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants