9393import org .opensearch .security .resolver .IndexResolverReplacer ;
9494import org .opensearch .security .resolver .IndexResolverReplacer .Resolved ;
9595import org .opensearch .security .securityconf .ConfigModel ;
96- import org .opensearch .security .securityconf .DynamicConfigFactory ;
9796import org .opensearch .security .securityconf .DynamicConfigModel ;
9897import org .opensearch .security .securityconf .FlattenedActionGroups ;
9998import org .opensearch .security .securityconf .impl .CType ;
10099import org .opensearch .security .securityconf .impl .DashboardSignInOption ;
101100import org .opensearch .security .securityconf .impl .SecurityDynamicConfiguration ;
102101import org .opensearch .security .securityconf .impl .v7 .ActionGroupsV7 ;
103102import org .opensearch .security .securityconf .impl .v7 .RoleV7 ;
103+ import org .opensearch .security .securityconf .impl .v7 .TenantV7 ;
104104import org .opensearch .security .support .ConfigConstants ;
105105import org .opensearch .security .support .WildcardMatcher ;
106106import org .opensearch .security .user .User ;
@@ -157,6 +157,7 @@ public class PrivilegesEvaluator {
157157 private final Settings settings ;
158158 private final Map <String , Set <String >> pluginToClusterActions ;
159159 private final AtomicReference <ActionPrivileges > actionPrivileges = new AtomicReference <>();
160+ private final AtomicReference <TenantPrivileges > tenantPrivileges = new AtomicReference <>();
160161
161162 public PrivilegesEvaluator (
162163 final ClusterService clusterService ,
@@ -200,16 +201,13 @@ public PrivilegesEvaluator(
200201
201202 if (configurationRepository != null ) {
202203 configurationRepository .subscribeOnChange (configMap -> {
203- try {
204- SecurityDynamicConfiguration <ActionGroupsV7 > actionGroupsConfiguration = configurationRepository .getConfiguration (
205- CType .ACTIONGROUPS
206- );
207- SecurityDynamicConfiguration <RoleV7 > rolesConfiguration = configurationRepository .getConfiguration (CType .ROLES );
208-
209- this .updateConfiguration (actionGroupsConfiguration , rolesConfiguration );
210- } catch (Exception e ) {
211- log .error ("Error while updating ActionPrivileges object with {}" , configMap , e );
212- }
204+ SecurityDynamicConfiguration <ActionGroupsV7 > actionGroupsConfiguration = configurationRepository .getConfiguration (
205+ CType .ACTIONGROUPS
206+ );
207+ SecurityDynamicConfiguration <RoleV7 > rolesConfiguration = configurationRepository .getConfiguration (CType .ROLES );
208+ SecurityDynamicConfiguration <TenantV7 > tenantConfiguration = configurationRepository .getConfiguration (CType .TENANTS );
209+
210+ this .updateConfiguration (actionGroupsConfiguration , rolesConfiguration , tenantConfiguration );
213211 });
214212 }
215213
@@ -226,15 +224,15 @@ public PrivilegesEvaluator(
226224
227225 void updateConfiguration (
228226 SecurityDynamicConfiguration <ActionGroupsV7 > actionGroupsConfiguration ,
229- SecurityDynamicConfiguration <RoleV7 > rolesConfiguration
227+ SecurityDynamicConfiguration <RoleV7 > rolesConfiguration ,
228+ SecurityDynamicConfiguration <TenantV7 > tenantConfiguration
230229 ) {
231- if (rolesConfiguration != null ) {
232- SecurityDynamicConfiguration <ActionGroupsV7 > actionGroupsWithStatics = actionGroupsConfiguration != null
233- ? DynamicConfigFactory .addStatics (actionGroupsConfiguration .clone ())
234- : DynamicConfigFactory .addStatics (SecurityDynamicConfiguration .empty (CType .ACTIONGROUPS ));
235- FlattenedActionGroups flattenedActionGroups = new FlattenedActionGroups (actionGroupsWithStatics );
230+ FlattenedActionGroups flattenedActionGroups = new FlattenedActionGroups (actionGroupsConfiguration .withStaticConfig ());
231+ rolesConfiguration = rolesConfiguration .withStaticConfig ();
232+ tenantConfiguration = tenantConfiguration .withStaticConfig ();
233+ try {
236234 ActionPrivileges actionPrivileges = new ActionPrivileges (
237- DynamicConfigFactory . addStatics ( rolesConfiguration . clone ()) ,
235+ rolesConfiguration ,
238236 flattenedActionGroups ,
239237 () -> clusterStateSupplier .get ().metadata ().getIndicesLookup (),
240238 settings ,
@@ -247,6 +245,14 @@ void updateConfiguration(
247245 if (oldInstance != null ) {
248246 oldInstance .shutdown ();
249247 }
248+ } catch (Exception e ) {
249+ log .error ("Error while updating ActionPrivileges" , e );
250+ }
251+
252+ try {
253+ this .tenantPrivileges .set (new TenantPrivileges (rolesConfiguration , tenantConfiguration , flattenedActionGroups ));
254+ } catch (Exception e ) {
255+ log .error ("Error while updating TenantPrivileges" , e );
250256 }
251257 }
252258
@@ -455,7 +461,8 @@ public PrivilegesEvaluatorResponse evaluate(PrivilegesEvaluationContext context)
455461 user ,
456462 dcm ,
457463 requestedResolved ,
458- mapTenants (context )
464+ context ,
465+ this .tenantPrivileges .get ()
459466 );
460467
461468 if (isDebugEnabled ) {
@@ -517,7 +524,8 @@ public PrivilegesEvaluatorResponse evaluate(PrivilegesEvaluationContext context)
517524 user ,
518525 dcm ,
519526 requestedResolved ,
520- mapTenants (context )
527+ context ,
528+ this .tenantPrivileges .get ()
521529 );
522530
523531 if (isDebugEnabled ) {
@@ -594,19 +602,8 @@ public Set<String> mapRoles(final User user, final TransportAddress caller) {
594602 return this .configModel .mapSecurityRoles (user , caller );
595603 }
596604
597- public Map <String , Boolean > mapTenants (PrivilegesEvaluationContext privilegesEvaluationContext ) {
598- return this .configModel .mapTenants (privilegesEvaluationContext );
599- }
600-
601- public Map <String , Boolean > mapTenants (User user , Set <String > mappedRoles ) {
602- return this .configModel .mapTenants (
603- new PrivilegesEvaluationContext (user , ImmutableSet .copyOf (mappedRoles ), null , null , null , irr , resolver , clusterStateSupplier )
604- );
605- }
606-
607- public Set <String > getAllConfiguredTenantNames () {
608-
609- return configModel .getAllConfiguredTenantNames ();
605+ public TenantPrivileges tenantPrivileges () {
606+ return this .tenantPrivileges .get ();
610607 }
611608
612609 public boolean multitenancyEnabled () {
0 commit comments