Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test queryable built-in role synchronization #118964

Merged
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
3 changes: 0 additions & 3 deletions muted-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,6 @@ tests:
- class: org.elasticsearch.xpack.ccr.rest.ShardChangesRestIT
method: testShardChangesNoOperation
issue: https://github.com/elastic/elasticsearch/issues/118800
- class: org.elasticsearch.xpack.security.QueryableReservedRolesIT
method: testDeletingAndCreatingSecurityIndexTriggersSynchronization
issue: https://github.com/elastic/elasticsearch/issues/118806
- class: org.elasticsearch.smoketest.DocsClientYamlTestSuiteIT
method: test {yaml=reference/indices/shard-stores/line_150}
issue: https://github.com/elastic/elasticsearch/issues/118896
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,20 +199,33 @@ public void clusterChanged(ClusterChangedEvent event) {
}
}

/**
* @return {@code true} if the synchronization of built-in roles is in progress, {@code false} otherwise
*/
public boolean isSynchronizationInProgress() {
return synchronizationInProgress.get();
}

private void syncBuiltInRoles(final QueryableBuiltInRoles roles) {
if (synchronizationInProgress.compareAndSet(false, true)) {
final Map<String, String> indexedRolesDigests = readIndexedBuiltInRolesDigests(clusterService.state());
if (roles.rolesDigest().equals(indexedRolesDigests)) {
logger.debug("Security index already contains the latest built-in roles indexed, skipping synchronization");
return;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bug fix where this method would return without calling synchronizationInProgress.set(false);.

}
executor.execute(() -> doSyncBuiltinRoles(indexedRolesDigests, roles, ActionListener.wrap(v -> {
logger.info("Successfully synced [" + roles.roleDescriptors().size() + "] built-in roles to .security index");
synchronizationInProgress.set(false);
}, e -> {
handleException(e);
try {
final Map<String, String> indexedRolesDigests = readIndexedBuiltInRolesDigests(clusterService.state());
if (roles.rolesDigest().equals(indexedRolesDigests)) {
logger.debug("Security index already contains the latest built-in roles indexed, skipping roles synchronization");
synchronizationInProgress.set(false);
} else {
executor.execute(() -> doSyncBuiltinRoles(indexedRolesDigests, roles, ActionListener.wrap(v -> {
logger.info("Successfully synced [" + roles.roleDescriptors().size() + "] built-in roles to .security index");
synchronizationInProgress.set(false);
}, e -> {
handleException(e);
synchronizationInProgress.set(false);
})));
}
} catch (Exception e) {
logger.error("Failed to sync built-in roles", e);
synchronizationInProgress.set(false);
})));
}
}
}

Expand Down Expand Up @@ -452,6 +465,10 @@ static class MarkRolesAsSyncedTask implements ClusterStateTaskListener {
this.newRoleDigests = newRoleDigests;
}

public Map<String, String> getNewRoleDigests() {
return newRoleDigests;
}

Tuple<ClusterState, Map<String, String>> execute(ClusterState state) {
IndexMetadata indexMetadata = state.metadata().index(concreteSecurityIndexName);
if (indexMetadata == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
* The reserved roles are static and do not change during runtime, hence this provider will never notify any listeners.
* </p>
*/
public final class QueryableReservedRolesProvider implements QueryableBuiltInRoles.Provider {
public class QueryableReservedRolesProvider implements QueryableBuiltInRoles.Provider {

private final Supplier<QueryableBuiltInRoles> reservedRolesSupplier;

Expand Down
Loading