Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Google Cloud Workstation - CORS headers on workstation generated 302 redirect

When using cloud workstation for my multi-service development, I ran into a CORs issue on the followingCloud Workstation location, which generates a 302 redirect response 

```https://ssh.cloud.google.com/devshell/gateway```.

Upon investigation, the required http headers are not being duplicated, the primary one in question is:
```Access-Control-Allow-Origin```
My question:

Is there a command for cloud workstations, which can define required headers for my services, similar to the response for Google Cloud Run found here:

https://www.googlecloudcommunity.com/gc/Serverless/Cloud-run-cors-policy/m-p/512265/highlight/true#M...

2 7 2,240
7 REPLIES 7

Hi @amaxwell01 ,

Welcome to the Google Cloud Community!

Try to perform the following troubleshoot options:

  1. Check this Stack Overflow Post about redirects. When a request gets redirected across origins, the browser changes the Origin to null. Because of this, the Origin won't match configured values. What you can do here is to set Access-Control-Allow-Origin: * 
  2. You can also get in touch with Google Cloud Support to look into your case.

let me know if it helped, thanks!

Hello Marramirez,

These steps don't resolve the issue of my public HTTP making to my cloud workstation . Google has a form of authentication setup which is blocking the requests from making it to my cloud workstation. I've tried the steps described:

https://cloud.google.com/workstations/docs/authentication but these still fail to make it to the cloud workstation.

I am having a similar issue to this. Did you ever resolve your problem?

What they don't include in the documentation is that the URL provided is for only 1 service. In order to run multiple services you need to use the TCP/SSH tunnel support and run your services on your localhost.

Thanks for the answer. I got it to mostly work, except after a couple of seconds it seems like the Cloud Workstation host terminates the connection and I get a `gcloud` error in their python code:

websocket._exceptions.WebSocketConnectionClosedException: Connection is already closed.

Since this happens so quickly and so often, it does not seem like a feasible solution for us. Did you encounter this and/or were you able to find a workaround for it?

Same here! Faced this situation before on my own Coder OSS server, now GCP Workstation.

Thanks to GCP Support, I've been able to call API on a Workstation when the React frontend is on another different Workstation.

The command that they asked me to execute is the following (replace placeholders):

curl -X PATCH  https://workstations.googleapis.com/v1alpha/projects/$PROJECT/locations/$LOCATION/workstationClusters/$CLUSTER/workstationConfigs/$CONFIG?update_mask=http_options.allowed_unauthenticated_cors_preflight_requests  \
  -H "Authorization: Bearer $(gcloud auth print-access-token)"  \
  -H "Content-Type: application/json" \
  -d  '{"http_options": {"allowed_unauthenticated_cors_preflight_requests": true}}'  

I think is a yet undocumented feature.