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

[caddy] proxy requests to port locations through ws proxy #4419

Merged
merged 2 commits into from
Jun 9, 2021

Conversation

akosyakov
Copy link
Member

@akosyakov akosyakov commented Jun 8, 2021

What it does

How to test

  • Start a workspace for https://github.com/vaadin/skeleton-starter-flow-spring
  • When the server is ready, try to create a web socket for port 35729 and connect to it from devtools. You can verify it in network tab.
    • Notice that live reloading won't work since they don't respect our preview env, only gitpod.io

@akosyakov akosyakov force-pushed the ak/fix_web_sockets branch 3 times, most recently from c6d6127 to e001a06 Compare June 8, 2021 08:48
@akosyakov akosyakov marked this pull request as ready for review June 8, 2021 09:09
@akosyakov akosyakov requested review from csweichel and aledbf June 8, 2021 09:09
@@ -216,7 +216,11 @@ https://*.*.{$GITPOD_DOMAIN} {

@workspace_port header_regexp host Host ^(webview-|browser-|extensions-)?(?P<workspacePort>[0-9]{2,5})-(?P<workspaceID>[a-z0-9][0-9a-z\-]+).ws(?P<location>-[a-z0-9]+)?.{$GITPOD_DOMAIN}
handle @workspace_port {
reverse_proxy ws-{re.host.workspaceID}-ports.{$KUBE_NAMESPACE}.{$KUBE_DOMAIN}:{re.host.workspacePort} {
Copy link
Member

Choose a reason for hiding this comment

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

why are you removing the mapping for workspace ports?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

As far as i understood without this change it does not go through ws-proxy at least in prev env?

Copy link
Member

Choose a reason for hiding this comment

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

Correct.

Just in case, I copied this configuration from what we had in NGINX previously.

Copy link
Member Author

Choose a reason for hiding this comment

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

I think in nginx we also delegated to ws-proxy:

server {
listen {{ $listen }};
# Matches:
# - (webview-|browser-|extensions-)?+ for now, we only support Theia webviews here! (TODO is there a - meaningful - way to generalize this?)
# - (?<port>[0-9]{2,5})- port to forward to
# - (?<wsid>[a-z][0-9a-z\-]+) workspace Id
# - \.ws(-[a-z0-9]+)? workspace base domain
# "" needed because of {} (nginx syntax wart)
server_name "~^(webview-|browser-|extensions-)?+(?<port>[0-9]{2,5})-(?<wsid>[a-z0-9][0-9a-z\-]+)\.ws-{{ .Values.components.proxy.withWsCluster.shortname }}\.${PROXY_DOMAIN_REGEX}$";
{{- if $useHttps }}
include lib.ssl.conf;
include lib.https_redirect.conf;
{{- end }}
# include lib.workspace-port-locations.conf;
include lib.region-headers.conf;
include lib.resolver.conf;
location / {
include lib.proxy.conf;
include lib.ws-sse.conf;
# Increase connect timeout
proxy_connect_timeout 10s;
# Set max body size to make big uploads work
client_max_body_size 2048m;
# disable the error log to not spam our logs when the kube DNS doesn't know about the service yet
error_log off;
proxy_pass http://ws-proxy.{{ .Values.components.proxy.withWsCluster.namespace }}.svc.cluster.local:8080$request_uri;
but moved it to caddy while switching to nginx on purpose. I am not sure.

@akosyakov akosyakov force-pushed the ak/fix_web_sockets branch from e001a06 to 6370ef8 Compare June 8, 2021 10:23
@aledbf
Copy link
Member

aledbf commented Jun 8, 2021

/werft run

👍 started the job as gitpod-build-ak-fix-web-sockets.5

@aledbf
Copy link
Member

aledbf commented Jun 8, 2021

@akosyakov this change LGTM but can you split the change in two different PRs?
One for the Caddyfile, to route everything through ws-proxy and other change headers in ws-proxy?

@akosyakov
Copy link
Member Author

akosyakov commented Jun 8, 2021

Do you mean commits? I’m offline till tomorrow morning if it is critical and should go in tomorrow deployment. Feel free to split, rebase and merge yourself.

@aledbf
Copy link
Member

aledbf commented Jun 8, 2021

Do you mean commits?

No, two PRs. The caddy change has no relation with the one in ws-proxy. Just to not assume in the future that are related in any way.

@svenefftinge
Copy link
Member

Aren't those changes related, i.e. would the fix work without the caddy change?

@aledbf
Copy link
Member

aledbf commented Jun 8, 2021

would the fix work without the caddy change?

Yes.

The change to Caddy is for core-dev to behave similarly to production (all traffic through ws-proxy)

@csweichel
Copy link
Contributor

Those two changes are separate indeed. One is to bring core-dev closer to ws-proxy, the other is fixing ws-proxy itself.
While we indeed have two separate changes robed into one commit - which might create confusion in the future - I'd hope that this PR will act as a reminder that those changes should not have been conflated in the first place.

All that said, I'd propose we merge those changes because they make a whole lot of sense :)

@svenefftinge
Copy link
Member

Thanks for the clarification, Alejandro. So I guess my confusion is good proof of your concern. That said, I agree we should merge it as is to be able to get it in front of users ASAP.

It's for core-dev to behave similarly to production.
@akosyakov akosyakov force-pushed the ak/fix_web_sockets branch from 6370ef8 to 5d92f84 Compare June 9, 2021 02:13
@akosyakov
Copy link
Member Author

I split into 2 commits with detailed explanation from this PR.

@aledbf aledbf self-requested a review June 9, 2021 02:14
Copy link
Member

@aledbf aledbf left a comment

Choose a reason for hiding this comment

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

LGTM

a work-around for servers which does not respect case-insensitive headers, see #4047 (comment)
@akosyakov akosyakov force-pushed the ak/fix_web_sockets branch from 5d92f84 to de8cb0a Compare June 9, 2021 02:52
@akosyakov akosyakov merged commit 46d1a4d into main Jun 9, 2021
@akosyakov akosyakov deleted the ak/fix_web_sockets branch June 9, 2021 02:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Websocket connections no longer work
4 participants