Rancher - how to enable CORS

we deployed large k8s cluster 9 +nodes.

i believe that we are running into issues where CORS is not allowed between pods etc.

would you let us know how can we enable CORS?

XMLHttpRequest cannot load https://35.160.xx.xx:8080/r/projects/1a7/kubernetes/api/v1/namespaces/default/secrets. No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://myapp.35.161.2xx.xx.nip.io’ is therefore not allowed access.

XMLHttpRequest cannot load https://35.160.xx.xx:8080/r/projects/1a7/kubernetes/oapi/v1/namespaces/default/buildconfigs. No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://myapp.35.161.2xx.xx.nip.io’ is therefore not allowed access. The response had HTTP status code 503.

Did you find a way to enable this? I believe it would be a custom config in the haproxy load balancer, but I am having trouble finding the right way to specify Access-Control-Allow-Origin

no never could do so. let me know if you can figure it out.

I just got it working, but I am using cattle, and the basic “Add Load Balancer” they provide. All I needed to do is add this line to the haproxy.cfg customization:
http-response set-header ‘Access-Control-Allow-Origin’ ‘*’

1 Like

@vthyng don’t you have a 'http-response' not allowed in 'defaults' section. error ?
If you config is more complex, can you please share it ?

My haproxy.cfg is now working:

backend
__ mode http
__ http-response set-header ‘Access-Control-Allow-Origin’ ‘*’

“__” are 4 spaces indent.

frontend - Where HAProxy listens to connections
backend - Where HAPoxy sends incoming connections
stats - Optionally, setup HAProxy web tool for monitoring the load balancer and its nodes

(Rancher 1.6.9)

I thought that is all I had in there. Looking at it now, I see:

backend
   http-response set-header 'Access-Control-Allow-Origin' '*'

defaults
        timeout connect 5000
        timeout client  300000
        timeout server  300000