Skip to content

Commit e9fcb45

Browse files
authored
[server] Remove admin OTS create/use flow (#16761)
1 parent 9f9c9ae commit e9fcb45

File tree

6 files changed

+1
-128
lines changed

6 files changed

+1
-128
lines changed

components/server/src/config.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ export type Config = Omit<
2828
| "stripeConfigFile"
2929
| "licenseFile"
3030
| "patSigningKeyFile"
31-
| "adminLoginKeyFile"
3231
> & {
3332
hostUrl: GitpodHostUrl;
3433
workspaceDefaults: WorkspaceDefaults;
@@ -151,7 +150,6 @@ export interface ConfigSerialized {
151150

152151
showSetupModal: boolean;
153152

154-
adminLoginKeyFile?: string;
155153
admin: {
156154
grantFirstUserAdminRole: boolean;
157155
credentialsPath: string;
@@ -331,15 +329,6 @@ export namespace ConfigFile {
331329
}
332330
}
333331

334-
let adminLoginKey: string | undefined = undefined;
335-
if (config.adminLoginKeyFile) {
336-
try {
337-
adminLoginKey = fs.readFileSync(filePathTelepresenceAware(config.adminLoginKeyFile), "utf-8").trim();
338-
} catch (error) {
339-
log.error("Could not load admin login key", error);
340-
}
341-
}
342-
343332
return {
344333
...config,
345334
hostUrl,
@@ -359,7 +348,6 @@ export namespace ConfigFile {
359348
patSigningKey,
360349
admin: {
361350
...config.admin,
362-
loginKey: adminLoginKey,
363351
credentialsPath: config.admin.credentialsPath,
364352
},
365353
};

components/server/src/installation-admin/installation-admin-controller.ts

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -4,31 +4,16 @@
44
* See License.AGPL.txt in the project root for license information.
55
*/
66

7-
import * as crypto from "crypto";
87
import { injectable, inject } from "inversify";
98
import * as express from "express";
109
import * as opentracing from "opentracing";
1110
import { InstallationAdminTelemetryDataProvider } from "./telemetry-data-provider";
12-
import { log } from "@gitpod/gitpod-protocol/lib/util/logging";
13-
import { OneTimeSecretServer } from "../one-time-secret-server";
14-
import { TraceContext } from "@gitpod/gitpod-protocol/lib/util/tracing";
15-
import { BUILTIN_INSTLLATION_ADMIN_USER_ID, UserDB } from "@gitpod/gitpod-db/lib/user-db";
16-
import { Config } from "../config";
1711

1812
@injectable()
1913
export class InstallationAdminController {
2014
@inject(InstallationAdminTelemetryDataProvider)
2115
protected readonly telemetryDataProvider: InstallationAdminTelemetryDataProvider;
2216

23-
@inject(OneTimeSecretServer)
24-
protected readonly otsServer: OneTimeSecretServer;
25-
26-
@inject(Config)
27-
protected readonly config: Config;
28-
29-
@inject(UserDB)
30-
protected readonly userDb: UserDB;
31-
3217
public create(): express.Application {
3318
const app = express();
3419

@@ -43,46 +28,6 @@ export class InstallationAdminController {
4328
}
4429
});
4530

46-
const adminUserCreateLoginTokenRoute = "/admin-user/login-token/create";
47-
app.post(adminUserCreateLoginTokenRoute, async (req: express.Request, res: express.Response) => {
48-
const span = TraceContext.startSpan(adminUserCreateLoginTokenRoute);
49-
const ctx = { span };
50-
51-
log.info(`${adminUserCreateLoginTokenRoute} received.`);
52-
try {
53-
// In case there is no/an empty key specified: Nobody should be able to call this so they are not able to guess values here
54-
if (!this.config.admin.loginKey) {
55-
throw new Error("Cannot handle request");
56-
}
57-
58-
// Unblock the admin-user: it's blocked initially!
59-
const user = await this.userDb.findUserById(BUILTIN_INSTLLATION_ADMIN_USER_ID);
60-
if (!user) {
61-
throw new Error("Cannot find builtin admin-user");
62-
}
63-
user.blocked = false;
64-
await this.userDb.storeUser(user);
65-
66-
// Create a fresh token
67-
// TODO(gpl): Would be nice if we could invalidate all other tokens here!
68-
const secretHash = crypto
69-
.createHash("sha256")
70-
.update(BUILTIN_INSTLLATION_ADMIN_USER_ID + this.config.admin.loginKey)
71-
.digest("hex");
72-
const oneDay = new Date();
73-
oneDay.setDate(oneDay.getDate() + 1);
74-
const ots = await this.otsServer.serveToken(ctx, secretHash, oneDay);
75-
76-
res.send(ots.token).status(200);
77-
log.info(`${adminUserCreateLoginTokenRoute} done.`);
78-
} catch (err) {
79-
TraceContext.setError(ctx, err);
80-
span.finish();
81-
log.error(`${adminUserCreateLoginTokenRoute} error`, err);
82-
res.sendStatus(500);
83-
}
84-
});
85-
8631
return app;
8732
}
8833
}

components/server/src/user/user-controller.ts

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -190,38 +190,6 @@ export class UserController {
190190
}
191191
});
192192

193-
router.get(
194-
"/login/ots/admin-user/:key",
195-
loginUserWithOts(async (req: express.Request, res: express.Response, user: User, secret: string) => {
196-
// In case there is no/an empty key specified: Nobody should be able to call this so they are not able to guess values here
197-
if (!this.config.admin.loginKey) {
198-
throw new ResponseError(500, "No admin login key configured, cannot login as admin-user");
199-
}
200-
201-
// Counterpart is here: https://github.com/gitpod-io/gitpod/blob/478a75e744a642d9b764de37cfae655bc8b29dd5/components/server/src/installation-admin/installation-admin-controller.ts#L38
202-
const secretHash = crypto
203-
.createHash("sha256")
204-
.update(user.id + this.config.admin.loginKey)
205-
.digest("hex");
206-
if (secretHash !== secret) {
207-
throw new ResponseError(401, "OTS secret not verified");
208-
}
209-
210-
// Login this user (sets cookie as side-effect)
211-
await new Promise<void>((resolve, reject) => {
212-
req.login(user, (err) => {
213-
if (err) {
214-
reject(err);
215-
} else {
216-
resolve();
217-
}
218-
});
219-
});
220-
221-
// Simply redirect to the app for now
222-
res.redirect("/orgs/new", 307);
223-
}, BUILTIN_INSTLLATION_ADMIN_USER_ID),
224-
);
225193
router.get(
226194
"/login/ots/:userId/:key",
227195
loginUserWithOts(async (req: express.Request, res: express.Response, user: User, secret: string) => {

install/installer/pkg/components/server/configmap.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,7 @@ func configmap(ctx *common.RenderContext) ([]runtime.Object, error) {
303303
GrantFirstUserAdminRole: true, // existing default
304304
CredentialsPath: adminCredentialsPath,
305305
},
306-
AdminLoginKeyFile: AdminLoginKeyFile(ctx),
307-
ShowSetupModal: showSetupModal,
306+
ShowSetupModal: showSetupModal,
308307
}
309308

310309
fc, err := common.ToJSONString(scfg)
@@ -328,13 +327,6 @@ func configmap(ctx *common.RenderContext) ([]runtime.Object, error) {
328327
}, nil
329328
}
330329

331-
func AdminLoginKeyFile(ctx *common.RenderContext) string {
332-
if ctx.Config.AdminLoginSecret == nil {
333-
return ""
334-
}
335-
return fmt.Sprintf("%s/%s", AdminSecretMountPath, AdminSecretLoginKeyName)
336-
}
337-
338330
func getPersonalAccessTokenSigningKey(cfg *experimental.Config) (corev1.Volume, corev1.VolumeMount, string, bool) {
339331
var volume corev1.Volume
340332
var mount corev1.VolumeMount

install/installer/pkg/components/server/constants.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ const (
2525
DebugNodePortName = "debugnode"
2626
ServicePort = 3000
2727
personalAccessTokenSigningKeyMountPath = "/secrets/personal-access-token-signing-key"
28-
AdminSecretName = "server-admin-secret"
29-
AdminSecretLoginKeyName = "login-key"
30-
AdminSecretMountPath = "/admin"
3128

3229
AdminCredentialsSecretName = "admin-credentials"
3330
AdminCredentialsSecretMountPath = "/credentials/admin"

install/installer/pkg/components/server/deployment.go

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -318,23 +318,6 @@ func deployment(ctx *common.RenderContext) ([]runtime.Object, error) {
318318
})
319319
}
320320

321-
// admin secret
322-
if ctx.Config.AdminLoginSecret != nil {
323-
volumes = append(volumes, corev1.Volume{
324-
Name: "admin-login-key",
325-
VolumeSource: corev1.VolumeSource{
326-
Secret: &corev1.SecretVolumeSource{
327-
SecretName: ctx.Config.AdminLoginSecret.Name,
328-
},
329-
},
330-
})
331-
volumeMounts = append(volumeMounts, corev1.VolumeMount{
332-
Name: "admin-login-key",
333-
MountPath: AdminSecretMountPath,
334-
ReadOnly: true,
335-
})
336-
}
337-
338321
adminCredentialsVolume, adminCredentialsMount, _ := getAdminCredentials()
339322
volumes = append(volumes, adminCredentialsVolume)
340323
volumeMounts = append(volumeMounts, adminCredentialsMount)

0 commit comments

Comments
 (0)