Skip to content

WebSocket Support for Apps with Route-Services #474

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

Merged

Conversation

Dariquest
Copy link
Contributor

@Dariquest Dariquest commented May 5, 2025

Summary

Route services should be able to handle web socket requests.

The Gorouter flag "route_services.enable_websockets" is introduced to enable web socket communication for apps with route services. The default value is true.

 router.route_services.enable_websockets:
    description: Enable websocket connections for application routes bound to Route Services.
    default: true

Web socket upgrades on routes with an attached route service were prevented previously.
This issue has been brought up by one of our customers, who needed a route service to rate-limit their app.

GitHub Issue

Backward Compatibility

Breaking Change? No

Test

Scenario: A web socket app needs rate limiting via a route service.
Given

cf push websocket-app
cf push ratelimiter
cf create-user-provided-service ratelimiter-service -r https://ratelimiter.cfapps.xxx.sapcloud.io
cf bind-route-service cfapps.xxx.sapcloud.io ratelimiter-service --hostname websocket-app

When I connect to wss://websocket-app.cfapps.xxx.sapcloud.io using a web socket client or simply curl it with the corresponding websocket request headers
Then The connection will work through the route service as expected

@Dariquest
Copy link
Contributor Author

Dariquest commented May 16, 2025

Performed a test of this Routing-release Gorouter change on a dev landscape with a sample websocket-app to show that the apps with bound route services support web sockets:

cf push websocket-app
cf push ratelimiter
cf create-user-provided-service ratelimiter-service -r https://ratelimiter.cfapps.xxx.sapcloud.io
cf bind-route-service cfapps.xxx.sapcloud.io ratelimiter-service --hostname websocket-app
  1. Using a web socket client wss:

wscat -c wss://websocket-app.cfapps.xxx.sapcloud.io/ws
Connected (press CTRL+C to quit)

test
< test

  1. Curling the sample app with the corresponding websocket connection headers:
$ curl -i -N -H "Connection: Upgrade"      -H "Upgrade: websocket"      -H "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ=="      -H "Sec-WebSocket-Version: 13"      -H "Origin: https://websocket-app.cfapps.xxx.sapcloud.io"      https://websocket-app.cfapps.xxx.sapcloud.io/ws --http1.1
HTTP/1.1 101 Switching Protocols
connection: Upgrade
sec-websocket-accept: xxx
upgrade: websocket
x-vcap-request-id: 0237d2fc-72f6-4905-71c3-88a2419fd40e
strict-transport-security: max-age=31536000; includeSubDomains; preload;

@Dariquest Dariquest force-pushed the websock_route_srv branch from ca97cc6 to e88e6b1 Compare May 16, 2025 13:31
@Dariquest Dariquest marked this pull request as ready for review May 16, 2025 13:31
@maxmoehl maxmoehl requested a review from a team May 17, 2025 08:41
Copy link
Contributor

@geofffranks geofffranks left a comment

Choose a reason for hiding this comment

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

Requested default change

@Dariquest Dariquest requested a review from geofffranks May 20, 2025 08:20
@maxmoehl
Copy link
Member

GitHub seems confused about workflows being there while also not being there on this branch. @Dariquest can you rebase once more?

@geofffranks
Copy link
Contributor

GitHub seems confused about workflows being there while also not being there on this branch. @Dariquest can you rebase once more?

Everything looks good to me. Once the rebasing + GH actions are sorted out feel free to approve + merge.n

@Dariquest Dariquest force-pushed the websock_route_srv branch from 0ebd0ac to 6918d99 Compare May 21, 2025 07:57
@maxmoehl
Copy link
Member

The workflow uses secrets, e.g. ${{ secrets.GCP_SERVICE_ACCOUNT_TAS_RUNTIME_BUILD_IMAGE_READER }} and those are inaccessible if your PR is coming from a fork due to security policies.

We will ignore the validation for now but can have a discussion on how to fix this for future contributions.

/fyi @geofffranks @kart2bc

Add new spec for gorouter.route_services.enable_websockets
Default value is true
Unit & Integration tests with a websocket client
@Dariquest Dariquest force-pushed the websock_route_srv branch from 6918d99 to be0152d Compare May 21, 2025 08:21
@Dariquest Dariquest requested a review from maxmoehl May 21, 2025 11:12
@github-project-automation github-project-automation bot moved this from Inbox to Pending Merge | Prioritized in Application Runtime Platform Working Group May 21, 2025
@geofffranks geofffranks merged commit 7cf89dc into cloudfoundry:develop May 21, 2025
2 of 7 checks passed
@github-project-automation github-project-automation bot moved this from Pending Merge | Prioritized to Done in Application Runtime Platform Working Group May 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

3 participants