Skip to content

Commit 98bc977

Browse files
[backport] Testing queryable built-in role synchronization (#119178)
Backport of #118964
1 parent ae92ed1 commit 98bc977

File tree

5 files changed

+558
-18
lines changed

5 files changed

+558
-18
lines changed

muted-tests.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,6 @@ tests:
317317
- class: org.elasticsearch.xpack.inference.DefaultEndPointsIT
318318
method: testMultipleInferencesTriggeringDownloadAndDeploy
319319
issue: https://github.com/elastic/elasticsearch/issues/117208
320-
- class: org.elasticsearch.xpack.security.QueryableReservedRolesIT
321-
method: testDeletingAndCreatingSecurityIndexTriggersSynchronization
322-
issue: https://github.com/elastic/elasticsearch/issues/118806
323320

324321
# Examples:
325322
#
@@ -438,4 +435,4 @@ tests:
438435
issue: https://github.com/elastic/elasticsearch/issues/119159
439436
- class: org.elasticsearch.versioning.ConcurrentSeqNoVersioningIT
440437
method: testSeqNoCASLinearizability
441-
issue: https://github.com/elastic/elasticsearch/issues/117249
438+
issue: https://github.com/elastic/elasticsearch/issues/117249

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/support/QueryableBuiltInRolesSynchronizer.java

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -201,20 +201,33 @@ public void clusterChanged(ClusterChangedEvent event) {
201201
}
202202
}
203203

204+
/**
205+
* @return {@code true} if the synchronization of built-in roles is in progress, {@code false} otherwise
206+
*/
207+
public boolean isSynchronizationInProgress() {
208+
return synchronizationInProgress.get();
209+
}
210+
204211
private void syncBuiltInRoles(final QueryableBuiltInRoles roles) {
205212
if (synchronizationInProgress.compareAndSet(false, true)) {
206-
final Map<String, String> indexedRolesDigests = readIndexedBuiltInRolesDigests(clusterService.state());
207-
if (roles.rolesDigest().equals(indexedRolesDigests)) {
208-
logger.debug("Security index already contains the latest built-in roles indexed, skipping synchronization");
209-
return;
210-
}
211-
executor.execute(() -> doSyncBuiltinRoles(indexedRolesDigests, roles, ActionListener.wrap(v -> {
212-
logger.info("Successfully synced [" + roles.roleDescriptors().size() + "] built-in roles to .security index");
213-
synchronizationInProgress.set(false);
214-
}, e -> {
215-
handleException(e);
213+
try {
214+
final Map<String, String> indexedRolesDigests = readIndexedBuiltInRolesDigests(clusterService.state());
215+
if (roles.rolesDigest().equals(indexedRolesDigests)) {
216+
logger.debug("Security index already contains the latest built-in roles indexed, skipping roles synchronization");
217+
synchronizationInProgress.set(false);
218+
} else {
219+
executor.execute(() -> doSyncBuiltinRoles(indexedRolesDigests, roles, ActionListener.wrap(v -> {
220+
logger.info("Successfully synced [" + roles.roleDescriptors().size() + "] built-in roles to .security index");
221+
synchronizationInProgress.set(false);
222+
}, e -> {
223+
handleException(e);
224+
synchronizationInProgress.set(false);
225+
})));
226+
}
227+
} catch (Exception e) {
228+
logger.error("Failed to sync built-in roles", e);
216229
synchronizationInProgress.set(false);
217-
})));
230+
}
218231
}
219232
}
220233

@@ -466,6 +479,10 @@ static class MarkRolesAsSyncedTask implements ClusterStateTaskListener {
466479
this.newRoleDigests = newRoleDigests;
467480
}
468481

482+
public Map<String, String> getNewRoleDigests() {
483+
return newRoleDigests;
484+
}
485+
469486
Tuple<ClusterState, Map<String, String>> execute(ClusterState state) {
470487
IndexMetadata indexMetadata = state.metadata().index(concreteSecurityIndexName);
471488
if (indexMetadata == null) {

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/support/QueryableReservedRolesProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
* The reserved roles are static and do not change during runtime, hence this provider will never notify any listeners.
2424
* </p>
2525
*/
26-
public final class QueryableReservedRolesProvider implements QueryableBuiltInRoles.Provider {
26+
public class QueryableReservedRolesProvider implements QueryableBuiltInRoles.Provider {
2727

2828
private final Supplier<QueryableBuiltInRoles> reservedRolesSupplier;
2929

0 commit comments

Comments
 (0)