Skip to content

Commit 0833bd4

Browse files
committed
[server] Remove OTS use for env vars
1 parent 53a064c commit 0833bd4

File tree

1 file changed

+11
-52
lines changed

1 file changed

+11
-52
lines changed

components/server/src/workspace/workspace-starter.ts

Lines changed: 11 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,7 @@ export class WorkspaceStarter {
897897
// TODO(se): we cannot change this initializer structure now because it is part of how baserefs are computed in image-builder.
898898
// Image builds should however just use the initialization if the workspace they are running for (i.e. the one from above).
899899
checkoutLocation = ".";
900-
const { initializer, disposable } = await this.createCommitInitializer(
900+
const { initializer } = await this.createCommitInitializer(
901901
{ span },
902902
workspace,
903903
{
@@ -908,7 +908,6 @@ export class WorkspaceStarter {
908908
},
909909
user,
910910
);
911-
disp.push(disposable);
912911
let git: GitInitializer;
913912
if (initializer instanceof CompositeInitializer) {
914913
// we use the first git initializer for image builds only
@@ -1189,23 +1188,7 @@ export class WorkspaceStarter {
11891188
allEnvVars = allEnvVars.concat(context.envvars);
11901189
}
11911190

1192-
// we copy the envvars to a stable format so that things don't break when someone changes the
1193-
// EnvVarWithValue shape. The JSON.stringify(envvars) will be consumed by supervisor and we
1194-
// need to make sure we're speaking the same language.
1195-
const stableEnvvars = allEnvVars.map((e) => {
1196-
return { name: e.name, value: e.value };
1197-
});
1198-
1199-
// we ship the user-specific env vars as OTS because they might contain secrets
1200-
const envvarOTSExpirationTime = new Date();
1201-
envvarOTSExpirationTime.setMinutes(envvarOTSExpirationTime.getMinutes() + 30);
1202-
const envvarOTS = await this.otsServer.serve(traceCtx, JSON.stringify(stableEnvvars), envvarOTSExpirationTime);
1203-
12041191
const envvars: EnvironmentVariable[] = [];
1205-
const ev = new EnvironmentVariable();
1206-
ev.setName("SUPERVISOR_ENVVAR_OTS");
1207-
ev.setValue(envvarOTS.token);
1208-
envvars.push(ev);
12091192

12101193
// TODO(cw): for the time being we're still pushing the env vars as we did before.
12111194
// Once everything is running with the latest supervisor, we can stop doing that.
@@ -1272,19 +1255,15 @@ export class WorkspaceStarter {
12721255
};
12731256
await this.userDB.trace(traceCtx).storeGitpodToken(dbToken);
12741257

1275-
const otsExpirationTime = new Date();
1276-
otsExpirationTime.setMinutes(otsExpirationTime.getMinutes() + 30);
12771258
const tokenExpirationTime = new Date();
12781259
tokenExpirationTime.setMinutes(tokenExpirationTime.getMinutes() + 24 * 60);
1279-
const ots = await this.otsServer.serve(traceCtx, token, otsExpirationTime);
12801260

12811261
const ev = new EnvironmentVariable();
12821262
ev.setName("THEIA_SUPERVISOR_TOKENS");
12831263
ev.setValue(
12841264
JSON.stringify([
12851265
{
1286-
tokenOTS: ots.token,
1287-
token: "ots",
1266+
token: token,
12881267
kind: "gitpod",
12891268
host: this.config.hostUrl.url.host,
12901269
scope: scopes,
@@ -1554,8 +1533,7 @@ export class WorkspaceStarter {
15541533
} else if (WorkspaceProbeContext.is(context)) {
15551534
// workspace probes have no workspace initializer as they need no content
15561535
} else if (CommitContext.is(context)) {
1557-
const { initializer, disposable } = await this.createCommitInitializer(traceCtx, workspace, context, user);
1558-
disp.push(disposable);
1536+
const { initializer } = await this.createCommitInitializer(traceCtx, workspace, context, user);
15591537
if (initializer instanceof CompositeInitializer) {
15601538
result.setComposite(initializer);
15611539
} else {
@@ -1607,7 +1585,7 @@ export class WorkspaceStarter {
16071585
workspace: Workspace,
16081586
context: CommitContext,
16091587
user: User,
1610-
): Promise<{ initializer: GitInitializer | CompositeInitializer; disposable: Disposable }> {
1588+
): Promise<{ initializer: GitInitializer | CompositeInitializer }> {
16111589
const span = TraceContext.startSpan("createInitializerForCommit", ctx);
16121590
try {
16131591
const mainGit = this.createGitInitializer({ span }, workspace, context, user);
@@ -1620,16 +1598,13 @@ export class WorkspaceStarter {
16201598
}
16211599
const inits = await Promise.all(subRepoInitializers);
16221600
const compositeInit = new CompositeInitializer();
1623-
const compositeDisposable = new DisposableCollection();
16241601
for (const r of inits) {
16251602
const wsinit = new WorkspaceInitializer();
16261603
wsinit.setGit(r.initializer);
16271604
compositeInit.addInitializer(wsinit);
1628-
compositeDisposable.push(r.disposable);
16291605
}
16301606
return {
16311607
initializer: compositeInit,
1632-
disposable: compositeDisposable,
16331608
};
16341609
} catch (e) {
16351610
TraceContext.setError({ span }, e);
@@ -1644,7 +1619,7 @@ export class WorkspaceStarter {
16441619
workspace: Workspace,
16451620
context: GitCheckoutInfo,
16461621
user: User,
1647-
): Promise<{ initializer: GitInitializer; disposable: Disposable }> {
1622+
): Promise<{ initializer: GitInitializer }> {
16481623
const host = context.repository.host;
16491624
const hostContext = this.hostContextProvider.get(host);
16501625
if (!hostContext) {
@@ -1656,25 +1631,6 @@ export class WorkspaceStarter {
16561631
throw new Error("User is unauthorized!");
16571632
}
16581633

1659-
const tokenExpirationTime = new Date();
1660-
tokenExpirationTime.setMinutes(tokenExpirationTime.getMinutes() + 30);
1661-
let tokenOTS: string | undefined;
1662-
let disposable: Disposable | undefined;
1663-
try {
1664-
const token = await this.tokenProvider.getTokenForHost(user, host);
1665-
const username = token.username || "oauth2";
1666-
const res = await this.otsServer.serve(traceCtx, `${username}:${token.value}`, tokenExpirationTime);
1667-
tokenOTS = res.token;
1668-
disposable = res.disposable;
1669-
} catch (error) {
1670-
// no token
1671-
log.error(
1672-
{ workspaceId: workspace.id, userId: workspace.ownerId },
1673-
"cannot authenticate user for Git initializer",
1674-
error,
1675-
);
1676-
throw new Error("User is unauthorized!");
1677-
}
16781634
const cloneUrl = context.repository.cloneUrl;
16791635

16801636
var cloneTarget: string | undefined;
@@ -1695,9 +1651,13 @@ export class WorkspaceStarter {
16951651
targetMode = CloneTargetMode.REMOTE_HEAD;
16961652
}
16971653

1654+
const gitToken = await this.tokenProvider.getTokenForHost(user, host);
1655+
const username = gitToken.username || "oauth2";
1656+
16981657
const gitConfig = new GitConfig();
1699-
gitConfig.setAuthentication(GitAuthMethod.BASIC_AUTH_OTS);
1700-
gitConfig.setAuthOts(tokenOTS);
1658+
gitConfig.setAuthentication(GitAuthMethod.BASIC_AUTH);
1659+
gitConfig.setAuthUser(username);
1660+
gitConfig.setAuthPassword(gitToken.value);
17011661

17021662
if (this.config.insecureNoDomain) {
17031663
const token = await this.tokenProvider.getTokenForHost(user, host);
@@ -1727,7 +1687,6 @@ export class WorkspaceStarter {
17271687

17281688
return {
17291689
initializer: result,
1730-
disposable,
17311690
};
17321691
}
17331692

0 commit comments

Comments
 (0)