@@ -34,7 +34,7 @@ export class CedarAuthorizationService implements ICedarAuthorizationService, On
3434 }
3535
3636 async validate ( request : CedarValidationRequest ) : Promise < boolean > {
37- const { userId, action, groupId, tableName, dashboardId } = request ;
37+ const { userId, action, groupId, tableName, dashboardId, panelId } = request ;
3838 let { connectionId } = request ;
3939
4040 const actionPrefix = action . split ( ':' ) [ 0 ] ;
@@ -61,13 +61,20 @@ export class CedarAuthorizationService implements ICedarAuthorizationService, On
6161 const needsSentinel = action === CedarAction . DashboardCreate || ! dashboardId ;
6262 const effectiveDashboardId = needsSentinel ? '__new__' : dashboardId ;
6363 resourceId = `${ connectionId } /${ effectiveDashboardId } ` ;
64- return this . evaluate ( userId , connectionId , action , resourceType , resourceId , tableName , effectiveDashboardId ) ;
64+ return this . evaluate ( userId , connectionId , action , resourceType , resourceId , tableName , effectiveDashboardId , undefined ) ;
65+ }
66+ case 'panel' : {
67+ resourceType = CedarResourceType . Panel ;
68+ const needsSentinel = action === CedarAction . PanelCreate || ! panelId ;
69+ const effectivePanelId = needsSentinel ? '__new__' : panelId ;
70+ resourceId = `${ connectionId } /${ effectivePanelId } ` ;
71+ return this . evaluate ( userId , connectionId , action , resourceType , resourceId , tableName , undefined , effectivePanelId ) ;
6572 }
6673 default :
6774 return false ;
6875 }
6976
70- return this . evaluate ( userId , connectionId , action , resourceType , resourceId , tableName , dashboardId ) ;
77+ return this . evaluate ( userId , connectionId , action , resourceType , resourceId , tableName , dashboardId , undefined ) ;
7178 }
7279
7380 invalidatePolicyCacheForConnection ( connectionId : string ) : void {
@@ -169,6 +176,7 @@ export class CedarAuthorizationService implements ICedarAuthorizationService, On
169176 resourceId : string ,
170177 tableName ?: string ,
171178 dashboardId ?: string ,
179+ panelId ?: string ,
172180 ) : Promise < boolean > {
173181 await this . assertUserNotSuspended ( userId ) ;
174182
@@ -178,7 +186,7 @@ export class CedarAuthorizationService implements ICedarAuthorizationService, On
178186 const groupPolicies = this . loadPoliciesPerGroup ( userGroups ) ;
179187 if ( groupPolicies . length === 0 ) return false ;
180188
181- const entities = buildCedarEntities ( userId , userGroups , connectionId , tableName , dashboardId ) ;
189+ const entities = buildCedarEntities ( userId , userGroups , connectionId , tableName , dashboardId , panelId ) ;
182190
183191 for ( const policy of groupPolicies ) {
184192 const call = {
@@ -303,6 +311,19 @@ export class CedarAuthorizationService implements ICedarAuthorizationService, On
303311 ) ;
304312 }
305313 }
314+
315+ const panelResourceIds = [ ...cedarPolicy . matchAll ( / r e s o u r c e \s * = = \s * R o c k e t A d m i n : : P a n e l : : " ( [ ^ " ] + ) " / g) ] . map (
316+ ( m ) => m [ 1 ] ,
317+ ) ;
318+
319+ for ( const panelRef of panelResourceIds ) {
320+ if ( ! panelRef . startsWith ( `${ connectionId } /` ) ) {
321+ throw new HttpException (
322+ { message : Messages . CEDAR_POLICY_REFERENCES_FOREIGN_CONNECTION } ,
323+ HttpStatus . BAD_REQUEST ,
324+ ) ;
325+ }
326+ }
306327 }
307328
308329}
0 commit comments