Ambassador is throwing a 403 while trying to access a websocket endpoint within the cluster. Here are the steps to recreate the issue:
[Kube Environment: Docker for Desktop on Mac]
Install Ambassador and the Echo Service
helm repo add datawire https://getambassador.io
helm install ambassador datawire/ambassador
---
apiVersion: v1
kind: Service
metadata:
name: websocket-echo
namespace: default
spec:
ports:
- name: http
port: 80
targetPort: 8080
selector:
app: websocket-echo
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: websocket-echo
namespace: default
spec:
replicas: 1
selector:
matchLabels:
app: websocket-echo
template:
metadata:
labels:
app: websocket-echo
spec:
containers:
- name: backend
image: jmalloc/echo-server
ports:
- name: http
containerPort: 8080
---
apiVersion: getambassador.io/v2
kind: Mapping
metadata:
name: websocket-echo
namespace: default
spec:
prefix: /websocket/
service: websocket-echo
allow_upgrade:
- websocket
✅ Verify the echo server can be reached from a pod within the cluster
kubectl run my-shell --rm -i --tty --image node:12 -- bash
wscat
npm i -g wscat
wscat -c websocket-echo.default.svc.cluster.local
❌ Verify the echo server cannot be reach from outside the cluster
wscat
on you local machinenpm i -g wscat
wscat -c localhost/websocket-echo/
error: Unexpected server response: 403
Am I missing something simple?
Ambassador will redirect incoming request froms http to https.
You can verify by
$ curl localhost/websocket/ -v
* Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 80 (#0)
> GET /websocket/ HTTP/1.1
> Host: localhost
> User-Agent: curl/7.54.0
> Accept: */*
>
< HTTP/1.1 301 Moved Permanently
< location: https://localhost/websocket/
< date: Fri, 07 Aug 2020 08:25:38 GMT
< server: envoy
< content-length: 0
<
* Connection #0 to host localhost left intact
So, you will need to add this config to disable redirection on localhost
apiVersion: getambassador.io/v2
kind: Host
metadata:
name: localhost
namespace: default
spec:
hostname: localhost
acmeProvider:
authority: none
requestPolicy:
insecure:
action: Route