Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,13 @@ public class PrivilegesConfiguration {
);
private final PrivilegesInterceptorImpl privilegesInterceptor;

/**
* Tracks the sequence numbers of roles and action groups configurations to detect changes.
* Only rebuild ActionPrivileges when these actually change.
*/
private volatile long lastRolesSeqNo = -1;
private volatile long lastActionGroupsSeqNo = -1;

/**
* The pure static action groups should be ONLY used by action privileges for plugins; only those cannot and should
* not have knowledge of any action groups defined in the dynamic configuration. All other functionality should
Expand Down Expand Up @@ -109,6 +116,12 @@ public PrivilegesConfiguration(
.withStaticConfig();
ConfigV7 generalConfiguration = configurationRepository.getConfiguration(CType.CONFIG).getCEntry(CType.CONFIG.name());

// Check if roles or action groups actually changed
long currentRolesSeqNo = rolesConfiguration.getSeqNo();
long currentActionGroupsSeqNo = actionGroupsConfiguration.getSeqNo();
boolean rolesOrActionGroupsChanged = currentRolesSeqNo != lastRolesSeqNo
|| currentActionGroupsSeqNo != lastActionGroupsSeqNo;

FlattenedActionGroups flattenedActionGroups = new FlattenedActionGroups(actionGroupsConfiguration.withStaticConfig());
this.actionGroups.set(flattenedActionGroups);

Expand Down Expand Up @@ -142,8 +155,28 @@ public PrivilegesConfiguration(
if (oldInstance != null) {
oldInstance.shutdown();
}
} else {
lastRolesSeqNo = currentRolesSeqNo;
lastActionGroupsSeqNo = currentActionGroupsSeqNo;
} else if (rolesOrActionGroupsChanged) {
// Only rebuild ActionPrivileges when roles or action groups changed
log.debug(
"Roles or action groups changed (roles seqNo: {} -> {}, actionGroups seqNo: {} -> {}), rebuilding ActionPrivileges",
lastRolesSeqNo,
currentRolesSeqNo,
lastActionGroupsSeqNo,
currentActionGroupsSeqNo
);
privilegesEvaluator.get().updateConfiguration(flattenedActionGroups, rolesConfiguration, generalConfiguration);
lastRolesSeqNo = currentRolesSeqNo;
lastActionGroupsSeqNo = currentActionGroupsSeqNo;
} else {
// Only update general configuration settings (dnfof, filtered alias mode) without rebuilding ActionPrivileges
log.debug(
"Roles and action groups unchanged (seqNo: roles={}, actionGroups={}), skipping ActionPrivileges rebuild",
currentRolesSeqNo,
currentActionGroupsSeqNo
);
privilegesEvaluator.get().updateGeneralConfiguration(generalConfiguration);
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ void updateConfiguration(
ConfigV7 generalConfiguration
);

/**
* Updates only the general configuration settings (like dnfof, filtered alias mode) without
* rebuilding ActionPrivileges. Use this when roles and action groups haven't changed.
*/
void updateGeneralConfiguration(ConfigV7 generalConfiguration);

void updateClusterStateMetadata(ClusterService clusterService);

/**
Expand Down Expand Up @@ -129,6 +135,11 @@ public void updateConfiguration(

}

@Override
public void updateGeneralConfiguration(ConfigV7 generalConfiguration) {

}

@Override
public void updateClusterStateMetadata(ClusterService clusterService) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,7 @@ public void updateConfiguration(
SecurityDynamicConfiguration<RoleV7> rolesConfiguration,
ConfigV7 generalConfiguration
) {
this.dnfofEnabled = isDnfofEnabled(generalConfiguration);
this.dnfofForEmptyResultsEnabled = isDnfofEmptyEnabled(generalConfiguration);
this.filteredAliasMode = getFilteredAliasMode(generalConfiguration);
updateGeneralConfiguration(generalConfiguration);

try {
RoleBasedActionPrivileges actionPrivileges = new RoleBasedActionPrivileges(rolesConfiguration, flattenedActionGroups, settings);
Expand All @@ -232,6 +230,13 @@ public void updateConfiguration(

}

@Override
public void updateGeneralConfiguration(ConfigV7 generalConfiguration) {
this.dnfofEnabled = isDnfofEnabled(generalConfiguration);
this.dnfofForEmptyResultsEnabled = isDnfofEmptyEnabled(generalConfiguration);
this.filteredAliasMode = getFilteredAliasMode(generalConfiguration);
}

@Override
public void updateClusterStateMetadata(ClusterService clusterService) {
RoleBasedActionPrivileges actionPrivileges = this.actionPrivileges.get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ public void updateConfiguration(

}

@Override
public void updateGeneralConfiguration(ConfigV7 generalConfiguration) {

}

@Override
public void updateClusterStateMetadata(ClusterService clusterService) {

Expand Down
Loading