@@ -134,9 +134,14 @@ export class WorkspaceService {
134
134
135
135
// Internal method for allowing for additional DBs to be passed in
136
136
private async doGetWorkspace ( userId : string , workspaceId : string , db : WorkspaceDB = this . db ) : Promise < Workspace > {
137
- await this . auth . checkPermissionOnWorkspace ( userId , "access" , workspaceId ) ;
138
-
139
137
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
+
140
145
// TODO(gpl) We might want to add || !!workspace.softDeleted here in the future, but we were unsure how that would affect existing clients
141
146
// In order to reduce risk, we leave it for a future changeset.
142
147
if ( ! workspace || workspace . deleted ) {
@@ -678,9 +683,13 @@ export class WorkspaceService {
678
683
) : Promise < HeadlessLogUrls > {
679
684
const workspace = await this . db . findByInstanceId ( instanceId ) ;
680
685
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` ) ;
682
687
}
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 ) ;
684
693
685
694
const wsiPromise = this . db . findInstanceById ( instanceId ) ;
686
695
await check ( workspace ) ;
@@ -703,8 +712,8 @@ export class WorkspaceService {
703
712
workspaceId : string ,
704
713
client : Pick < GitpodClient , "onWorkspaceImageBuildLogs" > ,
705
714
) : Promise < void > {
706
- await this . auth . checkPermissionOnWorkspace ( userId , " access" , workspaceId ) ;
707
-
715
+ // check access
716
+ await this . getWorkspace ( userId , workspaceId ) ;
708
717
const logCtx : LogContext = { userId, workspaceId } ;
709
718
let instance = await this . db . findCurrentInstance ( workspaceId ) ;
710
719
if ( ! instance || instance . status . phase === "stopped" ) {
0 commit comments