Skip to content

Commit 2192fa6

Browse files
committed
[server] Fix bogus permission check in stopWorkspace
1 parent 93d01d1 commit 2192fa6

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ import { PublicAPIConverter } from "@gitpod/public-api-common/lib/public-api-con
7676
import { WatchWorkspaceStatusResponse } from "@gitpod/public-api/lib/gitpod/v1/workspace_pb";
7777
import { ContextParser } from "./context-parser-service";
7878
import { scrubber, TrustedValue } from "@gitpod/gitpod-protocol/lib/util/scrubbing";
79+
import { WorkspacePermission } from "../authorization/definitions";
7980

8081
export const GIT_STATUS_LENGTH_CAP_BYTES = 4096;
8182

@@ -304,13 +305,22 @@ export class WorkspaceService {
304305
}
305306

306307
// Internal method for allowing for additional DBs to be passed in
307-
private async doGetWorkspace(userId: string, workspaceId: string, db: WorkspaceDB = this.db): Promise<Workspace> {
308+
private async doGetWorkspace(
309+
userId: string,
310+
workspaceId: string,
311+
db: WorkspaceDB = this.db,
312+
stopOnly: boolean = false,
313+
): Promise<Workspace> {
308314
const workspace = await db.findById(workspaceId);
309315

310316
if (workspace?.type === "prebuild" && workspace.projectId) {
311317
await this.auth.checkPermissionOnProject(userId, "read_prebuild", workspace.projectId);
312318
} else {
313-
await this.auth.checkPermissionOnWorkspace(userId, "access", workspaceId);
319+
let effectivePermission: WorkspacePermission = "access";
320+
if (stopOnly) {
321+
effectivePermission = "stop";
322+
}
323+
await this.auth.checkPermissionOnWorkspace(userId, effectivePermission, workspaceId);
314324
}
315325

316326
// TODO(gpl) We might want to add || !!workspace.softDeleted here in the future, but we were unsure how that would affect existing clients
@@ -366,12 +376,13 @@ export class WorkspaceService {
366376
await this.auth.checkPermissionOnWorkspace(userId, "stop", workspaceId);
367377
}
368378

369-
const workspace = await this.doGetWorkspace(userId, workspaceId);
379+
const workspace = await this.doGetWorkspace(userId, workspaceId, this.db, true);
370380
const instance = await this.db.findRunningInstance(workspace.id);
371381
if (!instance) {
372382
// there's no instance running - we're done
373383
return;
374384
}
385+
375386
await this.workspaceStarter.stopWorkspaceInstance({}, instance.id, instance.region, reason, policy);
376387
this.asyncUpdateDeletionEligibilityTime(userId, workspaceId, true);
377388
}

0 commit comments

Comments
 (0)