@@ -90,9 +90,10 @@ public ActionPrivileges(
90
90
Settings settings ,
91
91
ImmutableSet <String > wellKnownClusterActions ,
92
92
ImmutableSet <String > wellKnownIndexActions ,
93
- ImmutableSet <String > explicitlyRequiredIndexActions
93
+ ImmutableSet <String > explicitlyRequiredIndexActions ,
94
+ Map <String , Set <String >> pluginToClusterActions
94
95
) {
95
- this .cluster = new ClusterPrivileges (roles , actionGroups , wellKnownClusterActions );
96
+ this .cluster = new ClusterPrivileges (roles , actionGroups , wellKnownClusterActions , pluginToClusterActions );
96
97
this .index = new IndexPrivileges (roles , actionGroups , wellKnownIndexActions , explicitlyRequiredIndexActions );
97
98
this .roles = roles ;
98
99
this .actionGroups = actionGroups ;
@@ -115,7 +116,27 @@ public ActionPrivileges(
115
116
settings ,
116
117
WellKnownActions .CLUSTER_ACTIONS ,
117
118
WellKnownActions .INDEX_ACTIONS ,
118
- WellKnownActions .EXPLICITLY_REQUIRED_INDEX_ACTIONS
119
+ WellKnownActions .EXPLICITLY_REQUIRED_INDEX_ACTIONS ,
120
+ Map .of ()
121
+ );
122
+ }
123
+
124
+ public ActionPrivileges (
125
+ SecurityDynamicConfiguration <RoleV7 > roles ,
126
+ FlattenedActionGroups actionGroups ,
127
+ Supplier <Map <String , IndexAbstraction >> indexMetadataSupplier ,
128
+ Settings settings ,
129
+ Map <String , Set <String >> pluginToClusterActions
130
+ ) {
131
+ this (
132
+ roles ,
133
+ actionGroups ,
134
+ indexMetadataSupplier ,
135
+ settings ,
136
+ WellKnownActions .CLUSTER_ACTIONS ,
137
+ WellKnownActions .INDEX_ACTIONS ,
138
+ WellKnownActions .EXPLICITLY_REQUIRED_INDEX_ACTIONS ,
139
+ pluginToClusterActions
119
140
);
120
141
}
121
142
@@ -297,6 +318,8 @@ static class ClusterPrivileges {
297
318
*/
298
319
private final ImmutableMap <String , WildcardMatcher > rolesToActionMatcher ;
299
320
321
+ private final ImmutableMap <String , WildcardMatcher > usersToActionMatcher ;
322
+
300
323
private final ImmutableSet <String > wellKnownClusterActions ;
301
324
302
325
/**
@@ -310,14 +333,16 @@ static class ClusterPrivileges {
310
333
ClusterPrivileges (
311
334
SecurityDynamicConfiguration <RoleV7 > roles ,
312
335
FlattenedActionGroups actionGroups ,
313
- ImmutableSet <String > wellKnownClusterActions
336
+ ImmutableSet <String > wellKnownClusterActions ,
337
+ Map <String , Set <String >> pluginToClusterActions
314
338
) {
315
339
DeduplicatingCompactSubSetBuilder <String > roleSetBuilder = new DeduplicatingCompactSubSetBuilder <>(
316
340
roles .getCEntries ().keySet ()
317
341
);
318
342
Map <String , DeduplicatingCompactSubSetBuilder .SubSetBuilder <String >> actionToRoles = new HashMap <>();
319
343
ImmutableSet .Builder <String > rolesWithWildcardPermissions = ImmutableSet .builder ();
320
344
ImmutableMap .Builder <String , WildcardMatcher > rolesToActionMatcher = ImmutableMap .builder ();
345
+ ImmutableMap .Builder <String , WildcardMatcher > usersToActionMatcher = ImmutableMap .builder ();
321
346
322
347
for (Map .Entry <String , RoleV7 > entry : roles .getCEntries ().entrySet ()) {
323
348
try {
@@ -367,13 +392,22 @@ static class ClusterPrivileges {
367
392
}
368
393
}
369
394
395
+ if (pluginToClusterActions != null ) {
396
+ for (String pluginIdentifier : pluginToClusterActions .keySet ()) {
397
+ Set <String > clusterActions = pluginToClusterActions .get (pluginIdentifier );
398
+ WildcardMatcher matcher = WildcardMatcher .from (clusterActions );
399
+ usersToActionMatcher .put (pluginIdentifier , matcher );
400
+ }
401
+ }
402
+
370
403
DeduplicatingCompactSubSetBuilder .Completed <String > completedRoleSetBuilder = roleSetBuilder .build ();
371
404
372
405
this .actionToRoles = actionToRoles .entrySet ()
373
406
.stream ()
374
407
.collect (ImmutableMap .toImmutableMap (Map .Entry ::getKey , entry -> entry .getValue ().build (completedRoleSetBuilder )));
375
408
this .rolesWithWildcardPermissions = rolesWithWildcardPermissions .build ();
376
409
this .rolesToActionMatcher = rolesToActionMatcher .build ();
410
+ this .usersToActionMatcher = usersToActionMatcher .build ();
377
411
this .wellKnownClusterActions = wellKnownClusterActions ;
378
412
}
379
413
@@ -407,6 +441,14 @@ PrivilegesEvaluatorResponse providesPrivilege(PrivilegesEvaluationContext contex
407
441
}
408
442
}
409
443
444
+ // 4: If plugin is performing the action, check if plugin has permission
445
+ if (context .getUser ().isPluginUser () && this .usersToActionMatcher .containsKey (context .getUser ().getName ())) {
446
+ WildcardMatcher matcher = this .usersToActionMatcher .get (context .getUser ().getName ());
447
+ if (matcher != null && matcher .test (action )) {
448
+ return PrivilegesEvaluatorResponse .ok ();
449
+ }
450
+ }
451
+
410
452
return PrivilegesEvaluatorResponse .insufficient (action );
411
453
}
412
454
@@ -476,6 +518,16 @@ PrivilegesEvaluatorResponse providesAnyPrivilege(PrivilegesEvaluationContext con
476
518
}
477
519
}
478
520
521
+ // 4: If plugin is performing the action, check if plugin has permission
522
+ if (this .usersToActionMatcher .containsKey (context .getUser ().getName ())) {
523
+ WildcardMatcher matcher = this .usersToActionMatcher .get (context .getUser ().getName ());
524
+ for (String action : actions ) {
525
+ if (matcher != null && matcher .test (action )) {
526
+ return PrivilegesEvaluatorResponse .ok ();
527
+ }
528
+ }
529
+ }
530
+
479
531
if (actions .size () == 1 ) {
480
532
return PrivilegesEvaluatorResponse .insufficient (actions .iterator ().next ());
481
533
} else {
0 commit comments