Skip to content

Commit a43054a

Browse files
Fix permissions checks for stopping prebuilds (#20043)
1 parent a03f193 commit a43054a

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

components/server/src/prebuilds/prebuild-manager.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,13 +213,14 @@ export class PrebuildManager {
213213

214214
async cancelPrebuild(ctx: TraceContext, userId: string, prebuildId: string): Promise<void> {
215215
const prebuild = await this.workspaceDB.trace(ctx).findPrebuildByID(prebuildId);
216-
if (prebuild) {
217-
await this.auth.checkPermissionOnProject(userId, "write_prebuild", prebuild.projectId!);
218-
}
219216
if (!prebuild) {
220217
throw new ApplicationError(ErrorCodes.NOT_FOUND, `prebuild ${prebuildId} not found`);
221218
}
222-
await this.workspaceService.stopWorkspace(userId, prebuild.buildWorkspaceId, "stopped via API");
219+
220+
await this.auth.checkPermissionOnProject(userId, "write_prebuild", prebuild.projectId!);
221+
await this.workspaceService.stopWorkspace(userId, prebuild.buildWorkspaceId, "stopped via API", undefined, {
222+
skipPermissionCheck: true,
223+
});
223224
}
224225

225226
async getPrebuild(

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,8 +333,11 @@ export class WorkspaceService {
333333
workspaceId: string,
334334
reason: string,
335335
policy?: StopWorkspacePolicy,
336+
options: { skipPermissionCheck?: boolean } = {},
336337
): Promise<void> {
337-
await this.auth.checkPermissionOnWorkspace(userId, "stop", workspaceId);
338+
if (!options.skipPermissionCheck) {
339+
await this.auth.checkPermissionOnWorkspace(userId, "stop", workspaceId);
340+
}
338341

339342
const workspace = await this.doGetWorkspace(userId, workspaceId);
340343
const instance = await this.db.findRunningInstance(workspace.id);

components/supervisor/pkg/supervisor/tasks.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func (sub *tasksSubscription) Updates() <-chan []*api.TaskStatus {
3434
return sub.updates
3535
}
3636

37-
const maxSubscriptions = 10
37+
const maxSubscriptions = 100
3838

3939
func (tm *tasksManager) Subscribe() *tasksSubscription {
4040
tm.mu.Lock()

0 commit comments

Comments
 (0)