Skip to content

Commit 74e60f0

Browse files
committed
[code] fix #4529: serve each webview from own origin
decoupled from workpace origin (also extension host origin)
1 parent c060c81 commit 74e60f0

File tree

14 files changed

+271
-83
lines changed

14 files changed

+271
-83
lines changed

chart/templates/ws-manager-configmap.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ data:
6161
},
6262
"heartbeatInterval": "30s",
6363
"hostURL": "https://{{ $.Values.hostname }}",
64+
"workspaceClusterHost": "ws{{- if $gp.installation.shortname -}}-{{ $.Values.installation.shortname }}{{- end -}}.{{ $.Values.hostname }}",
6465
"initProbe": {
6566
"timeout": "1s"
6667
},

components/ide/code/leeway.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ RUN curl -fsSL https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh |
4242
&& npm install -g yarn node-gyp
4343
ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH
4444

45-
ENV GP_CODE_COMMIT a17670ba5af14e0faf3a6927983468d28fda235b
45+
ENV GP_CODE_COMMIT 6cf68cedd9ab62af8e426a364d97ed206bbe0a02
4646
RUN mkdir gp-code \
4747
&& cd gp-code \
4848
&& git init \

components/proxy/conf/Caddyfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ https://*.*.{$GITPOD_DOMAIN} {
243243
}
244244
}
245245

246+
# remove (webview-|browser-|extensions-) after Theia removed and new VS Code is used by all workspaces
246247
@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}
247248
handle @workspace_port {
248249
reverse_proxy https://ws-proxy.{$KUBE_NAMESPACE}.{$KUBE_DOMAIN}:9090 {
@@ -255,6 +256,7 @@ https://*.*.{$GITPOD_DOMAIN} {
255256
}
256257
}
257258

259+
# remove (webview-|browser-|extensions-) after Theia removed and new VS Code is used by all workspaces
258260
@workspace header_regexp host Host ^(webview-|browser-|extensions-)?(?P<workspaceID>[a-z0-9][0-9a-z\-]+).ws(?P<location>-[a-z0-9]+)?.{$GITPOD_DOMAIN}
259261
handle @workspace {
260262
reverse_proxy https://ws-proxy.{$KUBE_NAMESPACE}.{$KUBE_DOMAIN}:9090 {
@@ -266,6 +268,17 @@ https://*.*.{$GITPOD_DOMAIN} {
266268
}
267269
}
268270

271+
# foreign content origin should be decoupled from the workspace (port) origin but the workspace (port) prefix should be the path root for routing
272+
@foreign_content header_regexp host Host ^(.*)(foreign).ws(-[a-z0-9]+)?.{$GITPOD_DOMAIN}
273+
handle @foreign_content {
274+
reverse_proxy https://ws-proxy.{$KUBE_NAMESPACE}.{$KUBE_DOMAIN}:9090 {
275+
import workspace_transport
276+
import upstream_headers
277+
278+
header_up X-WSProxy-Host {http.request.host}
279+
}
280+
}
281+
269282
respond "Not found" 404
270283
}
271284

components/supervisor-api/go/info.pb.go

Lines changed: 35 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components/supervisor-api/info.proto

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,7 @@ message WorkspaceInfoResponse {
6565
}
6666
// repository is a repository from which this workspace was created
6767
Repository repository = 10;
68+
69+
// workspace_cluster_host provides the cluster host under which this workspace is served, e.g. ws-eu11.gitpod.io
70+
string workspace_cluster_host = 11;
6871
}

components/supervisor/pkg/supervisor/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ type WorkspaceConfig struct {
205205

206206
// WorkspaceContext is a context for this workspace
207207
WorkspaceContext string `env:"GITPOD_WORKSPACE_CONTEXT"`
208+
209+
// WorkspaceClusterHost is a host under which this workspace is served, e.g. ws-eu11.gitpod.io
210+
WorkspaceClusterHost string `env:"GITPOD_WORKSPACE_CLUSTER_HOST"`
208211
}
209212

210213
// WorkspaceGitpodToken is a list of tokens that should be added to supervisor's token service

components/supervisor/pkg/supervisor/services.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -585,11 +585,12 @@ func (is *InfoService) RegisterREST(mux *runtime.ServeMux, grpcEndpoint string)
585585
// WorkspaceInfo provides information about the workspace
586586
func (is *InfoService) WorkspaceInfo(context.Context, *api.WorkspaceInfoRequest) (*api.WorkspaceInfoResponse, error) {
587587
resp := &api.WorkspaceInfoResponse{
588-
CheckoutLocation: is.cfg.RepoRoot,
589-
InstanceId: is.cfg.WorkspaceInstanceID,
590-
WorkspaceId: is.cfg.WorkspaceID,
591-
GitpodHost: is.cfg.GitpodHost,
592-
WorkspaceContextUrl: is.cfg.WorkspaceContextURL,
588+
CheckoutLocation: is.cfg.RepoRoot,
589+
InstanceId: is.cfg.WorkspaceInstanceID,
590+
WorkspaceId: is.cfg.WorkspaceID,
591+
GitpodHost: is.cfg.GitpodHost,
592+
WorkspaceContextUrl: is.cfg.WorkspaceContextURL,
593+
WorkspaceClusterHost: is.cfg.WorkspaceClusterHost,
593594
}
594595

595596
commit, err := is.cfg.getCommit()

components/ws-manager/pkg/manager/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ type Configuration struct {
7979
WorkspaceDaemon WorkspaceDaemonConfiguration `json:"wsdaemon"`
8080
// RegistryFacadeHost is the host (possibly including port) on which the registry facade resolves
8181
RegistryFacadeHost string `json:"registryFacadeHost"`
82+
// Cluster host under which workspaces are served, e.g. ws-eu11.gitpod.io
83+
WorkspaceClusterHost string `json:"workspaceClusterHost"`
8284
}
8385

8486
// AllContainerConfiguration contains the configuration for all container in a workspace pod

components/ws-manager/pkg/manager/create.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,9 @@ func (m *Manager) createWorkspaceEnvironment(startContext *startWorkspaceContext
512512
result = append(result, corev1.EnvVar{Name: "THEIA_WORKSPACE_ROOT", Value: getWorkspaceRelativePath(spec.WorkspaceLocation)})
513513
result = append(result, corev1.EnvVar{Name: "GITPOD_HOST", Value: m.Config.GitpodHostURL})
514514
result = append(result, corev1.EnvVar{Name: "GITPOD_WORKSPACE_URL", Value: startContext.WorkspaceURL})
515+
result = append(result, corev1.EnvVar{Name: "GITPOD_WORKSPACE_CLUSTER_HOST", Value: m.Config.WorkspaceClusterHost})
515516
result = append(result, corev1.EnvVar{Name: "THEIA_SUPERVISOR_ENDPOINT", Value: fmt.Sprintf(":%d", startContext.SupervisorPort)})
517+
// TODO(ak) remove THEIA_WEBVIEW_EXTERNAL_ENDPOINT and THEIA_MINI_BROWSER_HOST_PATTERN when Theia is removed
516518
result = append(result, corev1.EnvVar{Name: "THEIA_WEBVIEW_EXTERNAL_ENDPOINT", Value: "webview-{{hostname}}"})
517519
result = append(result, corev1.EnvVar{Name: "THEIA_MINI_BROWSER_HOST_PATTERN", Value: "browser-{{hostname}}"})
518520

components/ws-proxy/pkg/proxy/pass.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"syscall"
1414
"time"
1515

16+
"github.com/gorilla/mux"
1617
"github.com/sirupsen/logrus"
1718
"golang.org/x/xerrors"
1819

@@ -187,3 +188,22 @@ func withXFrameOptionsFilter() proxyPassOpt {
187188
})
188189
}
189190
}
191+
192+
type workspaceTransport struct {
193+
transport http.RoundTripper
194+
}
195+
196+
func (t *workspaceTransport) RoundTrip(req *http.Request) (resp *http.Response, err error) {
197+
vars := mux.Vars(req)
198+
if vars[foreignPathIdentifier] != "" {
199+
req = req.Clone(req.Context())
200+
req.URL.Path = vars[foreignPathIdentifier]
201+
}
202+
return t.transport.RoundTrip(req)
203+
}
204+
205+
func withWorkspaceTransport() proxyPassOpt {
206+
return func(h *proxyPassConfig) {
207+
h.Transport = &workspaceTransport{h.Transport}
208+
}
209+
}

0 commit comments

Comments
 (0)