@@ -1988,7 +1988,7 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
1988
1988
1989
1989
// we use the workspacService which checks if the requesting user has access to the workspace. If that is the case they have access to snapshots as well.
1990
1990
// below is the old permission check which would also check if the user has access to the snapshot itself. This is not the case anymore.
1991
- const workspace = await this . workspaceService . getWorkspace ( user . id , workspaceId ) ;
1991
+ const { workspace } = await this . workspaceService . getWorkspace ( user . id , workspaceId ) ;
1992
1992
if ( workspace . ownerId !== user . id ) {
1993
1993
throw new ApplicationError ( ErrorCodes . NOT_FOUND , `Workspace ${ workspaceId } does not exist.` ) ;
1994
1994
}
@@ -2785,9 +2785,9 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
2785
2785
) : Promise < AdminGetListResult < WorkspaceAndInstance > > {
2786
2786
traceAPIParams ( ctx , { req } ) ;
2787
2787
2788
- await this . guardAdminAccess ( "adminGetWorkspaces" , { req } , Permission . ADMIN_WORKSPACES ) ;
2788
+ const admin = await this . guardAdminAccess ( "adminGetWorkspaces" , { req } , Permission . ADMIN_WORKSPACES ) ;
2789
2789
2790
- return await this . workspaceDb
2790
+ const wss = await this . workspaceDb
2791
2791
. trace ( ctx )
2792
2792
. findAllWorkspaceAndInstances (
2793
2793
req . offset ,
@@ -2796,12 +2796,27 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
2796
2796
req . orderDir === "asc" ? "ASC" : "DESC" ,
2797
2797
req ,
2798
2798
) ;
2799
+
2800
+ await Promise . all (
2801
+ wss . rows . map ( async ( row ) => {
2802
+ if ( ! ( await this . auth . hasPermissionOnWorkspace ( admin . id , "access" , row . workspaceId ) ) ) {
2803
+ wss . total -- ;
2804
+ wss . rows = wss . rows . filter ( ( ws ) => ws . workspaceId !== row . workspaceId ) ;
2805
+ }
2806
+ } ) ,
2807
+ ) ;
2808
+ return wss ;
2799
2809
}
2800
2810
2801
2811
async adminGetWorkspace ( ctx : TraceContext , workspaceId : string ) : Promise < WorkspaceAndInstance > {
2802
2812
traceAPIParams ( ctx , { workspaceId } ) ;
2803
2813
2804
- await this . guardAdminAccess ( "adminGetWorkspace" , { id : workspaceId } , Permission . ADMIN_WORKSPACES ) ;
2814
+ const admin = await this . guardAdminAccess (
2815
+ "adminGetWorkspace" ,
2816
+ { id : workspaceId } ,
2817
+ Permission . ADMIN_WORKSPACES ,
2818
+ ) ;
2819
+ await this . auth . checkPermissionOnWorkspace ( admin . id , "access" , workspaceId ) ;
2805
2820
2806
2821
const result = await this . workspaceDb . trace ( ctx ) . findWorkspaceAndInstance ( workspaceId ) ;
2807
2822
if ( ! result ) {
@@ -2813,7 +2828,12 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
2813
2828
async adminGetWorkspaceInstances ( ctx : TraceContext , workspaceId : string ) : Promise < WorkspaceInstance [ ] > {
2814
2829
traceAPIParams ( ctx , { workspaceId } ) ;
2815
2830
2816
- await this . guardAdminAccess ( "adminGetWorkspaceInstances" , { id : workspaceId } , Permission . ADMIN_WORKSPACES ) ;
2831
+ const admin = await this . guardAdminAccess (
2832
+ "adminGetWorkspaceInstances" ,
2833
+ { id : workspaceId } ,
2834
+ Permission . ADMIN_WORKSPACES ,
2835
+ ) ;
2836
+ await this . auth . checkPermissionOnWorkspace ( admin . id , "access" , workspaceId ) ;
2817
2837
2818
2838
const result = await this . workspaceDb . trace ( ctx ) . findInstances ( workspaceId ) ;
2819
2839
return result || [ ] ;
@@ -2827,6 +2847,7 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
2827
2847
{ id : workspaceId } ,
2828
2848
Permission . ADMIN_WORKSPACES ,
2829
2849
) ;
2850
+ await this . auth . checkPermissionOnWorkspace ( admin . id , "admin_control" , workspaceId ) ;
2830
2851
2831
2852
const workspace = await this . workspaceDb . trace ( ctx ) . findById ( workspaceId ) ;
2832
2853
if ( workspace ) {
@@ -2844,11 +2865,12 @@ export class GitpodServerImpl implements GitpodServerWithTracing, Disposable {
2844
2865
async adminRestoreSoftDeletedWorkspace ( ctx : TraceContext , workspaceId : string ) : Promise < void > {
2845
2866
traceAPIParams ( ctx , { workspaceId } ) ;
2846
2867
2847
- await this . guardAdminAccess (
2868
+ const admin = await this . guardAdminAccess (
2848
2869
"adminRestoreSoftDeletedWorkspace" ,
2849
2870
{ id : workspaceId } ,
2850
2871
Permission . ADMIN_WORKSPACES ,
2851
2872
) ;
2873
+ await this . auth . checkPermissionOnWorkspace ( admin . id , "admin_control" , workspaceId ) ;
2852
2874
2853
2875
await this . workspaceDb . trace ( ctx ) . transaction ( async ( db ) => {
2854
2876
const ws = await db . findById ( workspaceId ) ;
0 commit comments