Skip to content

Commit 0b49b53

Browse files
committed
[fga] prebuild access
1 parent 4bf139e commit 0b49b53

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

components/server/src/workspace/gitpod-server-impl.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1197,12 +1197,16 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
11971197
public async isPrebuildDone(ctx: TraceContext, pwsId: string): Promise<boolean> {
11981198
traceAPIParams(ctx, { pwsId });
11991199

1200+
const user = await this.checkUser("isPrebuildDone");
1201+
12001202
const pws = await this.workspaceDb.trace(ctx).findPrebuildByID(pwsId);
1201-
if (!pws) {
1203+
if (!pws || !pws.projectId) {
12021204
// there is no prebuild - that's as good one being done
12031205
return true;
12041206
}
12051207

1208+
await this.auth.checkPermissionOnProject(user.id, "read_prebuild", pws.projectId);
1209+
12061210
return PrebuiltWorkspace.isDone(pws);
12071211
}
12081212

@@ -1486,6 +1490,7 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
14861490

14871491
const project = await this.projectsService.getProject(user.id, projectId);
14881492
await this.guardProjectOperation(user, projectId, "get");
1493+
await this.auth.checkPermissionOnProject(user.id, "read_prebuild", projectId);
14891494

14901495
const events = await this.projectsService.getPrebuildEvents(user.id, project.cloneUrl);
14911496
return events;

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,14 @@ export class WorkspaceService {
134134

135135
// Internal method for allowing for additional DBs to be passed in
136136
private async doGetWorkspace(userId: string, workspaceId: string, db: WorkspaceDB = this.db): Promise<Workspace> {
137-
await this.auth.checkPermissionOnWorkspace(userId, "access", workspaceId);
138-
139137
const workspace = await db.findById(workspaceId);
138+
139+
if (workspace?.type === "prebuild" && workspace.projectId) {
140+
await this.auth.checkPermissionOnProject(userId, "read_prebuild", workspace.projectId);
141+
} else {
142+
await this.auth.checkPermissionOnWorkspace(userId, "access", workspaceId);
143+
}
144+
140145
// TODO(gpl) We might want to add || !!workspace.softDeleted here in the future, but we were unsure how that would affect existing clients
141146
// In order to reduce risk, we leave it for a future changeset.
142147
if (!workspace || workspace.deleted) {
@@ -678,9 +683,13 @@ export class WorkspaceService {
678683
): Promise<HeadlessLogUrls> {
679684
const workspace = await this.db.findByInstanceId(instanceId);
680685
if (!workspace) {
681-
throw new ApplicationError(ErrorCodes.NOT_FOUND, `Workspace for instanceId ${instanceId} not found`);
686+
throw new ApplicationError(ErrorCodes.NOT_FOUND, `Prebuild for instanceId ${instanceId} not found`);
682687
}
683-
await this.auth.checkPermissionOnWorkspace(userId, "access", workspace.id);
688+
if (workspace.type !== "prebuild" || !workspace.projectId) {
689+
throw new ApplicationError(ErrorCodes.CONFLICT, `Workspace is not a prebuild`);
690+
}
691+
692+
await this.auth.checkPermissionOnProject(userId, "read_prebuild", workspace.projectId);
684693

685694
const wsiPromise = this.db.findInstanceById(instanceId);
686695
await check(workspace);
@@ -703,8 +712,8 @@ export class WorkspaceService {
703712
workspaceId: string,
704713
client: Pick<GitpodClient, "onWorkspaceImageBuildLogs">,
705714
): Promise<void> {
706-
await this.auth.checkPermissionOnWorkspace(userId, "access", workspaceId);
707-
715+
// check access
716+
await this.getWorkspace(userId, workspaceId);
708717
const logCtx: LogContext = { userId, workspaceId };
709718
let instance = await this.db.findCurrentInstance(workspaceId);
710719
if (!instance || instance.status.phase === "stopped") {

0 commit comments

Comments
 (0)