@@ -108,9 +108,18 @@ func TestDataSourceProxy_routeRule(t *testing.T) {
108
108
Path : "mypath" ,
109
109
URL : "https://example.com/api/v1/" ,
110
110
},
111
+ {
112
+ Path : "api/rbac-home" ,
113
+ ReqAction : "datasources:read" ,
114
+ },
115
+ {
116
+ Path : "api/rbac-restricted" ,
117
+ ReqAction : "test-app.settings:read" ,
118
+ },
111
119
}
112
120
113
121
ds := & datasources.DataSource {
122
+ UID : "dsUID" ,
114
123
JsonData : simplejson .NewFromAny (map [string ]any {
115
124
"clientId" : "asd" ,
116
125
"dynamicUrl" : "https://dynamic.grafana.com" ,
@@ -249,6 +258,51 @@ func TestDataSourceProxy_routeRule(t *testing.T) {
249
258
require .NoError (t , err )
250
259
})
251
260
})
261
+
262
+ t .Run ("plugin route with RBAC protection user is allowed" , func (t * testing.T ) {
263
+ ctx , _ := setUp ()
264
+ ctx .SignedInUser .OrgID = int64 (1 )
265
+ ctx .SignedInUser .OrgRole = identity .RoleNone
266
+ ctx .SignedInUser .Permissions = map [int64 ]map [string ][]string {1 : {"test-app.settings:read" : nil }}
267
+ proxy , err := setupDSProxyTest (t , ctx , ds , routes , "api/rbac-restricted" )
268
+ require .NoError (t , err )
269
+ err = proxy .validateRequest ()
270
+ require .NoError (t , err )
271
+ })
272
+
273
+ t .Run ("plugin route with RBAC protection user is not allowed" , func (t * testing.T ) {
274
+ ctx , _ := setUp ()
275
+ ctx .SignedInUser .OrgID = int64 (1 )
276
+ ctx .SignedInUser .OrgRole = identity .RoleNone
277
+ ctx .SignedInUser .Permissions = map [int64 ]map [string ][]string {1 : {"test-app:read" : nil }}
278
+ proxy , err := setupDSProxyTest (t , ctx , ds , routes , "api/rbac-restricted" )
279
+ require .NoError (t , err )
280
+ err = proxy .validateRequest ()
281
+ require .Error (t , err )
282
+ })
283
+
284
+ t .Run ("plugin route with dynamic RBAC protection user is allowed" , func (t * testing.T ) {
285
+ ctx , _ := setUp ()
286
+ ctx .SignedInUser .OrgID = int64 (1 )
287
+ ctx .SignedInUser .OrgRole = identity .RoleNone
288
+ ctx .SignedInUser .Permissions = map [int64 ]map [string ][]string {1 : {"datasources:read" : {"datasources:uid:dsUID" }}}
289
+ proxy , err := setupDSProxyTest (t , ctx , ds , routes , "api/rbac-home" )
290
+ require .NoError (t , err )
291
+ err = proxy .validateRequest ()
292
+ require .NoError (t , err )
293
+ })
294
+
295
+ t .Run ("plugin route with dynamic RBAC protection user is not allowed" , func (t * testing.T ) {
296
+ ctx , _ := setUp ()
297
+ ctx .SignedInUser .OrgID = int64 (1 )
298
+ ctx .SignedInUser .OrgRole = identity .RoleNone
299
+ // Has access but to another app
300
+ ctx .SignedInUser .Permissions = map [int64 ]map [string ][]string {1 : {"datasources:read" : {"datasources:uid:notTheDsUID" }}}
301
+ proxy , err := setupDSProxyTest (t , ctx , ds , routes , "api/rbac-home" )
302
+ require .NoError (t , err )
303
+ err = proxy .validateRequest ()
304
+ require .Error (t , err )
305
+ })
252
306
})
253
307
254
308
t .Run ("Plugin with multiple routes for token auth" , func (t * testing.T ) {
@@ -1021,7 +1075,7 @@ func setupDSProxyTest(t *testing.T, ctx *contextmodel.ReqContext, ds *datasource
1021
1075
cfg := setting .NewCfg ()
1022
1076
secretsService := secretsmng .SetupTestService (t , fakes .NewFakeSecretsStore ())
1023
1077
secretsStore := secretskvs .NewSQLSecretsKVStore (dbtest .NewFakeDB (), secretsService , log .NewNopLogger ())
1024
- features := featuremgmt .WithFeatures ()
1078
+ features := featuremgmt .WithFeatures (featuremgmt . FlagAccessControlOnCall )
1025
1079
dsService , err := datasourceservice .ProvideService (nil , secretsService , secretsStore , cfg , features , acimpl .ProvideAccessControl (features , zanzana .NewNoopClient ()),
1026
1080
& actest.FakePermissionsService {}, quotatest .New (false , nil ), & pluginstore.FakePluginStore {}, & pluginfakes.FakePluginClient {},
1027
1081
plugincontext .ProvideBaseService (cfg , pluginconfig .NewFakePluginRequestConfigProvider ()))
0 commit comments