Skip to content

Commit 5e4fec8

Browse files
jeanp413mustard-mh
authored andcommitted
Read GITPOD_CODE_HOST variable
1 parent 9a24b5b commit 5e4fec8

File tree

9 files changed

+96
-56
lines changed

9 files changed

+96
-56
lines changed

src/vs/gitpod/browser/workbench/workbench-dev.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,12 @@
146146
<script src="{{WORKBENCH_WEB_BASE_URL}}/out/vs/loader.js" onerror="onVsCodeWorkbenchError(event)" crossorigin="anonymous"></script>
147147
<script src="{{WORKBENCH_WEB_BASE_URL}}/out/vs/webPackagePaths.js" onerror="onVsCodeWorkbenchError(event)" crossorigin="anonymous"></script>
148148
<script>
149+
// Important: this is required to evaluate product config values internally
150+
// See src/vs/gitpod/platform/product/common/product.ts
151+
globalThis.env = {
152+
GITPOD_CODE_HOST: window.location.host.split('.').splice(2).join('.')
153+
};
154+
149155
const baseUrl = new URL('{{WORKBENCH_WEB_BASE_URL}}', window.location.origin).toString();
150156
Object.keys(self.webPackagePaths).map(function (key, index) {
151157
self.webPackagePaths[key] = `${baseUrl}/remote/web/node_modules/${key}/${self.webPackagePaths[key]}`;

src/vs/gitpod/browser/workbench/workbench.html

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@
129129
<meta name="mobile-web-app-capable" content="yes" />
130130
<meta name="apple-mobile-web-app-capable" content="yes" />
131131
<meta name="apple-mobile-web-app-title" content="Code">
132-
<link rel="apple-touch-icon" href="/code-192.png" />
132+
<link rel="apple-touch-icon" href="{{WORKBENCH_WEB_BASE_URL}}/code-192.png" />
133133

134134
<!-- Disable pinch zooming -->
135135
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
@@ -142,7 +142,7 @@
142142

143143
<!-- Workbench Icon/Manifest/CSS -->
144144
<link rel="icon" href="/favicon.ico" type="image/x-icon" />
145-
<link rel="manifest" href="/manifest.json" />
145+
<link rel="manifest" href="{{WORKBENCH_WEB_BASE_URL}}/manifest.json" />
146146
<link data-name="vs/workbench/workbench.web.main" rel="stylesheet" href="{{WORKBENCH_WEB_BASE_URL}}/out/vs/workbench/workbench.web.main.css" onerror="onVsCodeWorkbenchError(event)">
147147

148148
<style>
@@ -166,6 +166,10 @@
166166
<script src="{{WORKBENCH_WEB_BASE_URL}}/out/vs/loader.js" onerror="onVsCodeWorkbenchError(event)" crossorigin="anonymous"></script>
167167
<script src="{{WORKBENCH_WEB_BASE_URL}}/out/vs/webPackagePaths.js" onerror="onVsCodeWorkbenchError(event)" crossorigin="anonymous"></script>
168168
<script>
169+
globalThis.env = {
170+
GITPOD_CODE_HOST: window.location.host.split('.').splice(2).join('.')
171+
};
172+
169173
const baseUrl = new URL('{{WORKBENCH_WEB_BASE_URL}}', window.location.origin).toString();
170174
Object.keys(self.webPackagePaths).map(function (key, index) {
171175
self.webPackagePaths[key] = `${baseUrl}/node_modules/${key}/${self.webPackagePaths[key]}`;
@@ -175,7 +179,10 @@
175179
recordStats: true,
176180
trustedTypesPolicy: window.trustedTypes?.createPolicy('amdLoader', {
177181
createScriptURL(value) {
178-
return value;
182+
if (value.startsWith(window.location.origin) || value.startsWith('{{WORKBENCH_WEB_BASE_URL}}')) {
183+
return value;
184+
}
185+
throw new Error(`Invalid script url: ${value}`);
179186
}
180187
}),
181188
paths: {

src/vs/gitpod/browser/workbench/workbench.ts

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,6 @@ async function doStart(): Promise<IDisposable> {
520520

521521
const gitpodHostURL = new URL(info.gitpodHost);
522522
const gitpodDomain = gitpodHostURL.protocol + '//*.' + gitpodHostURL.host;
523-
const syncStoreURL = info.gitpodHost + '/code-sync';
524523

525524
const secretStorageProvider = new LocalStorageSecretStorageProvider();
526525
interface GetTokenResponse {
@@ -918,34 +917,9 @@ async function doStart(): Promise<IDisposable> {
918917
},
919918
urlCallbackProvider: new LocalStorageURLCallbackProvider('/vscode-extension-auth-callback'),
920919
secretStorageProvider,
920+
additionalTrustedDomains: [gitpodDomain],
921921
productConfiguration: {
922-
linkProtectionTrustedDomains: [
923-
...(product.linkProtectionTrustedDomains || []),
924-
gitpodDomain
925-
],
926-
'configurationSync.store': {
927-
url: syncStoreURL,
928-
stableUrl: syncStoreURL,
929-
insidersUrl: syncStoreURL,
930-
canSwitch: false,
931-
authenticationProviders: {
932-
gitpod: {
933-
scopes: ['function:accessCodeSyncStorage']
934-
}
935-
}
936-
},
937-
'editSessions.store': {
938-
url: syncStoreURL,
939-
canSwitch: false,
940-
authenticationProviders: {
941-
gitpod: {
942-
scopes: ['function:accessCodeSyncStorage']
943-
}
944-
}
945-
},
946922
webEndpointUrlTemplate,
947-
commit: product.commit,
948-
quality: product.quality
949923
},
950924
settingsSyncOptions: {
951925
enabled: true,
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/* eslint-disable local/code-import-patterns */
2+
/* eslint-disable header/header */
3+
/*---------------------------------------------------------------------------------------------
4+
* Copyright (c) Gitpod. All rights reserved.
5+
*--------------------------------------------------------------------------------------------*/
6+
7+
import { isWeb } from 'vs/base/common/platform';
8+
import { IProductConfiguration } from 'vs/base/common/product';
9+
10+
// This is required so that webview resources load sucessfully in firefox
11+
// Firefox is more strict regarding CSP rules and it will complain if we left
12+
// the `webviewResourceBaseHost` set to 'vscode-cdn.net' as the service worker
13+
// is served from a different domain in this case `baseHost`.
14+
export let baseHost: string | undefined;
15+
if (isWeb) {
16+
baseHost = (globalThis as any).env?.['GITPOD_CODE_HOST'];
17+
} else {
18+
baseHost = process.env['GITPOD_CODE_HOST'];
19+
}
20+
baseHost ??= 'gitpod.io';
21+
if (/^https?:\/\//.test(baseHost)) {
22+
try {
23+
baseHost = new URL(baseHost).host;
24+
} catch { }
25+
}
26+
27+
export function addCustomGitpodProductProperties(product: IProductConfiguration): IProductConfiguration {
28+
const openvsxUrl = atob('aHR0cHM6Ly9vcGVuLXZzeC5vcmc='); // Hack to avoid being replaced by blobserve, remove in the future
29+
return {
30+
...product,
31+
linkProtectionTrustedDomains: [
32+
// ...(product.linkProtectionTrustedDomains || []),
33+
`https://open-vsx.${baseHost}`,
34+
openvsxUrl
35+
],
36+
extensionsGallery: {
37+
serviceUrl: `https://open-vsx.${baseHost}/vscode/gallery`,
38+
itemUrl: `${openvsxUrl}/vscode/item`,
39+
resourceUrlTemplate: `${openvsxUrl}/vscode/unpkg/{publisher}/{name}/{version}/{path}`, // Hardcoded for now until open-vsx proxy is fixed
40+
controlUrl: `https://ide.${baseHost}/code/marketplace.json`,
41+
publisherUrl: '',
42+
nlsBaseUrl: '',
43+
},
44+
'configurationSync.store': {
45+
url: `https://${baseHost}/code-sync`,
46+
stableUrl: `https://${baseHost}/code-sync`,
47+
insidersUrl: `https://${baseHost}/code-sync`,
48+
canSwitch: false,
49+
authenticationProviders: {
50+
gitpod: {
51+
scopes: ['function:accessCodeSyncStorage']
52+
}
53+
}
54+
},
55+
'editSessions.store': {
56+
url: `https://${baseHost}/code-sync`,
57+
canSwitch: false,
58+
authenticationProviders: {
59+
gitpod: {
60+
scopes: ['function:accessCodeSyncStorage']
61+
}
62+
}
63+
},
64+
};
65+
}

src/vs/server/node/extensionHostConnection.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,7 @@ export async function buildUserEnvironment(startParamsEnv: { [key: string]: stri
4545
VSCODE_HANDLES_UNCAUGHT_ERRORS: 'true',
4646
VSCODE_NLS_CONFIG: JSON.stringify(nlsConfig, undefined, 0)
4747
},
48-
...startParamsEnv,
49-
...{
50-
GITPOD_CODE_HOST: environmentService.isBuilt ? processEnv['GITPOD_HOST'] : undefined
51-
}
48+
...startParamsEnv
5249
};
5350

5451
const binFolder = environmentService.isBuilt ? join(environmentService.appRoot, 'bin') : join(environmentService.appRoot, 'resources', 'server', 'bin-dev');

src/vs/server/node/serverServices.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,19 @@ import { RemoteExtensionsScannerChannel, RemoteExtensionsScannerService } from '
7777
import { RemoteExtensionsScannerChannelName } from 'vs/platform/remote/common/remoteExtensionsScanner';
7878
import { RemoteUserDataProfilesServiceChannel } from 'vs/platform/userDataProfile/common/userDataProfileIpc';
7979
import { NodePtyHostStarter } from 'vs/platform/terminal/node/nodePtyHostStarter';
80+
import { DownloadService } from 'vs/platform/download/common/downloadService';
8081
// eslint-disable-next-line local/code-import-patterns
8182
import { GitpodInsightsAppender } from 'vs/gitpod/node/gitpodInsightsAppender';
82-
import { DownloadService } from 'vs/platform/download/common/downloadService';
83+
// eslint-disable-next-line local/code-import-patterns
84+
import { addCustomGitpodProductProperties } from 'vs/gitpod/platform/product/common/product';
8385

8486
// const eventPrefix = 'monacoworkbench';
8587

8688
export async function setupServerServices(connectionToken: ServerConnectionToken, args: ServerParsedArgs, REMOTE_DATA_FOLDER: string, disposables: DisposableStore) {
8789
const services = new ServiceCollection();
8890
const socketServer = new SocketServer<RemoteAgentConnectionContext>();
8991

90-
const productService: IProductService = { _serviceBrand: undefined, ...product };
92+
const productService: IProductService = { _serviceBrand: undefined, ...addCustomGitpodProductProperties(product) };
9193
services.set(IProductService, productService);
9294

9395
const environmentService = new ServerEnvironmentService(args, productService);

src/vs/server/node/webClientServer.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ import { isString } from 'vs/base/common/types';
3030
import { CharCode } from 'vs/base/common/charCode';
3131
import { getRemoteServerRootPath } from 'vs/platform/remote/common/remoteHosts';
3232
import { IExtensionManifest } from 'vs/platform/extensions/common/extensions';
33+
// eslint-disable-next-line local/code-import-patterns
34+
import { baseHost } from 'vs/gitpod/platform/product/common/product';
3335

3436
const textMimeType = {
3537
'.html': 'text/html',
@@ -370,7 +372,7 @@ export class WebClientServer {
370372
'media-src \'self\';',
371373
`script-src 'self' 'unsafe-eval' ${this._getScriptCspHashes(data).join(' ')} 'sha256-fh3TwPMflhsEIpR8g1OYTIMVWhXTLcjQ9kh2tIpmv54=' ${useTestResolver ? '' : `http://${remoteAuthority}`};`, // the sha is the same as in src/vs/workbench/services/extensions/worker/webWorkerExtensionHostIframe.html
372374
'child-src \'self\';',
373-
`frame-src 'self' https://*.vscode-cdn.net https://*.gitpod.io https://*.gitpod-dev.com https://*.gitpod-staging.com data:;`,
375+
`frame-src 'self' https://*.vscode-cdn.net https://*.${baseHost} https://*.gitpod-dev.com https://*.gitpod-staging.com data:;`,
374376
'worker-src \'self\' data: blob:;',
375377
'style-src \'self\' \'unsafe-inline\';',
376378
'connect-src \'self\' ws: wss: https:;',

src/vs/workbench/browser/web.main.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ import { EncryptionService } from 'vs/workbench/services/encryption/browser/encr
9595
import { IEncryptionService } from 'vs/platform/encryption/common/encryptionService';
9696
import { ISecretStorageService } from 'vs/platform/secrets/common/secrets';
9797
import { TunnelSource } from 'vs/workbench/services/remote/common/tunnelModel';
98+
// eslint-disable-next-line local/code-import-patterns
99+
import { addCustomGitpodProductProperties } from 'vs/gitpod/platform/product/common/product';
98100

99101
export class BrowserMain extends Disposable {
100102

@@ -250,7 +252,7 @@ export class BrowserMain extends Disposable {
250252
const workspace = this.resolveWorkspace();
251253

252254
// Product
253-
const productService: IProductService = mixin({ _serviceBrand: undefined, ...product }, this.configuration.productConfiguration);
255+
const productService: IProductService = { _serviceBrand: undefined, ...addCustomGitpodProductProperties(mixin({ ...product }, this.configuration.productConfiguration)) };
254256
serviceCollection.set(IProductService, productService);
255257

256258
// Environment

src/vs/workbench/contrib/webview/common/webview.ts

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,23 @@
55

66
import { CharCode } from 'vs/base/common/charCode';
77
import { Schemas } from 'vs/base/common/network';
8-
import { isWeb } from 'vs/base/common/platform';
98
import { URI } from 'vs/base/common/uri';
9+
// eslint-disable-next-line local/code-import-patterns
10+
import { baseHost } from 'vs/gitpod/platform/product/common/product';
1011

1112
export interface WebviewRemoteInfo {
1213
readonly isRemote: boolean;
1314
readonly authority: string | undefined;
1415
}
1516

16-
// This is required so that webview resources load sucessfully in firefox
17-
// Firefox is more strict regarding CSP rules and it will complain if we left
18-
// the `webviewResourceBaseHost` set to 'vscode-cdn.net' as the service worker
19-
// is served from a different domain in this case `gitpodHost`.
20-
// This change only affects the server part as it uses `process.env`,
21-
// for the front end there are some replace rules in gitpod blobserve config
22-
// that will replace 'vscode-cdn.net' with the proper host value
23-
// See https://github.com/gitpod-io/gitpod/blob/8c7cb822ed5c670c102335f76b269f00895c8876/chart/templates/blobserve-configmap.yaml#L28-L39
24-
// and https://github.com/gitpod-io/gitpod/blob/8c7cb822ed5c670c102335f76b269f00895c8876/installer/pkg/components/blobserve/configmap.go#L41-L61
25-
let gitpodHost;
26-
if (!isWeb) {
27-
gitpodHost = process.env['GITPOD_CODE_HOST'];
28-
try {
29-
gitpodHost = gitpodHost && new URL(gitpodHost).host;
30-
} catch { }
31-
}
3217

3318
/**
3419
* Root from which resources in webviews are loaded.
3520
*
3621
* This is hardcoded because we never expect to actually hit it. Instead these requests
3722
* should always go to a service worker.
3823
*/
39-
export const webviewResourceBaseHost = gitpodHost || 'vscode-cdn.net';
24+
export const webviewResourceBaseHost = baseHost || 'vscode-cdn.net';
4025

4126
export const webviewRootResourceAuthority = `vscode-resource.${webviewResourceBaseHost}`;
4227

0 commit comments

Comments
 (0)