Skip to content

Commit 6f549ea

Browse files
committed
Revert "Use index setting to track migration version index created on"
This reverts commit 9533f6f.
1 parent 9533f6f commit 6f549ea

File tree

7 files changed

+8
-87
lines changed

7 files changed

+8
-87
lines changed

server/src/main/java/org/elasticsearch/index/IndexVersions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ private static IndexVersion def(int id, Version luceneVersion) {
118118
public static final IndexVersion MERGE_ON_RECOVERY_VERSION = def(8_515_00_0, Version.LUCENE_9_11_1);
119119
public static final IndexVersion UPGRADE_TO_LUCENE_9_12 = def(8_516_00_0, Version.LUCENE_9_12_0);
120120
public static final IndexVersion ENABLE_IGNORE_ABOVE_LOGSDB = def(8_517_00_0, Version.LUCENE_9_12_0);
121-
121+
public static final IndexVersion ADD_ROLE_MAPPING_CLEANUP_MIGRATION = def(8_518_00_0, Version.LUCENE_9_12_0);
122122
/*
123123
* STOP! READ THIS FIRST! No, really,
124124
* ____ _____ ___ ____ _ ____ _____ _ ____ _____ _ _ ___ ____ _____ ___ ____ ____ _____ _

x-pack/plugin/security/src/internalClusterTest/java/org/elasticsearch/xpack/security/support/CleanupRoleMappingDuplicatesMigrationIT.java

Lines changed: 2 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88
package org.elasticsearch.xpack.security.support;
99

1010
import org.elasticsearch.action.ActionFuture;
11-
import org.elasticsearch.cluster.ClusterChangedEvent;
12-
import org.elasticsearch.cluster.ClusterState;
13-
import org.elasticsearch.cluster.ClusterStateListener;
1411
import org.elasticsearch.cluster.metadata.IndexMetadata;
1512
import org.elasticsearch.cluster.service.ClusterService;
1613
import org.elasticsearch.core.TimeValue;
@@ -34,9 +31,7 @@
3431
import java.util.Arrays;
3532
import java.util.Collections;
3633
import java.util.List;
37-
import java.util.concurrent.CountDownLatch;
3834
import java.util.concurrent.TimeUnit;
39-
import java.util.concurrent.atomic.AtomicInteger;
4035
import java.util.concurrent.atomic.AtomicLong;
4136

4237
import static org.elasticsearch.integration.RoleMappingFileSettingsIT.setupClusterStateListener;
@@ -48,7 +43,6 @@
4843
import static org.hamcrest.Matchers.equalTo;
4944
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
5045
import static org.hamcrest.Matchers.lessThan;
51-
import static org.hamcrest.Matchers.lessThanOrEqualTo;
5246

5347
@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, numDataNodes = 0, autoManageMasterNodes = false)
5448
public class CleanupRoleMappingDuplicatesMigrationIT extends SecurityIntegTestCase {
@@ -261,20 +255,6 @@ public void testSkipMigrationNoFileBasedMappings() throws Exception {
261255
assertAllRoleMappings("everyone_kibana_alone", "everyone_fleet_alone");
262256
}
263257

264-
public void testNewIndexSkipMigration() {
265-
internalCluster().setBootstrapMasterNodeIndex(0);
266-
final String masterNode = internalCluster().getMasterName();
267-
ensureGreen();
268-
CountDownLatch awaitMigrations = awaitMigrationVersionUpdates(
269-
masterNode,
270-
SecurityMigrations.CLEANUP_ROLE_MAPPING_DUPLICATES_MIGRATION_VERSION
271-
);
272-
// Create a native role mapping to create security index and trigger migration
273-
createNativeRoleMapping("everyone_kibana_alone");
274-
// Make sure no migration ran (set to current version without applying prior migrations)
275-
safeAwait(awaitMigrations);
276-
}
277-
278258
private void assertAllRoleMappings(String... roleMappingNames) {
279259
GetRoleMappingsResponse response = client().execute(GetRoleMappingsAction.INSTANCE, new GetRoleMappingsRequest()).actionGet();
280260

@@ -290,34 +270,6 @@ private void assertAllRoleMappings(String... roleMappingNames) {
290270
);
291271
}
292272

293-
/**
294-
* Make sure all versions are applied to cluster state sequentially
295-
*/
296-
private CountDownLatch awaitMigrationVersionUpdates(String node, final int... versions) {
297-
final ClusterService clusterService = internalCluster().clusterService(node);
298-
final CountDownLatch allVersionsCountDown = new CountDownLatch(1);
299-
final AtomicInteger currentVersionIdx = new AtomicInteger(0);
300-
clusterService.addListener(new ClusterStateListener() {
301-
@Override
302-
public void clusterChanged(ClusterChangedEvent event) {
303-
int currentMigrationVersion = getCurrentMigrationVersion(event.state());
304-
if (currentMigrationVersion > 0) {
305-
assertThat(versions[currentVersionIdx.get()], lessThanOrEqualTo(currentMigrationVersion));
306-
if (versions[currentVersionIdx.get()] == currentMigrationVersion) {
307-
currentVersionIdx.incrementAndGet();
308-
}
309-
310-
if (currentVersionIdx.get() >= versions.length) {
311-
clusterService.removeListener(this);
312-
allVersionsCountDown.countDown();
313-
}
314-
}
315-
}
316-
});
317-
318-
return allVersionsCountDown;
319-
}
320-
321273
private void awaitFileSettingsWatcher() throws Exception {
322274
final String masterNode = internalCluster().getMasterName();
323275
FileSettingsService masterFileSettingsService = internalCluster().getInstance(FileSettingsService.class, masterNode);
@@ -359,11 +311,8 @@ private void assertMigrationLessThan(int expectedVersion) {
359311
}
360312

361313
private int getCurrentMigrationVersion() {
362-
return getCurrentMigrationVersion(internalCluster().getInstance(ClusterService.class).state());
363-
}
364-
365-
private int getCurrentMigrationVersion(ClusterState state) {
366-
IndexMetadata indexMetadata = state.metadata().getIndices().get(INTERNAL_SECURITY_MAIN_INDEX_7);
314+
ClusterService clusterService = internalCluster().getInstance(ClusterService.class);
315+
IndexMetadata indexMetadata = clusterService.state().metadata().getIndices().get(INTERNAL_SECURITY_MAIN_INDEX_7);
367316
if (indexMetadata == null || indexMetadata.getCustomData(MIGRATION_VERSION_CUSTOM_KEY) == null) {
368317
return 0;
369318
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1444,7 +1444,6 @@ public static List<Setting<?>> getSettings(List<SecurityExtension> securityExten
14441444
settingsList.add(CachingServiceAccountTokenStore.CACHE_MAX_TOKENS_SETTING);
14451445
settingsList.add(SimpleRole.CACHE_SIZE_SETTING);
14461446
settingsList.add(NativeRoleMappingStore.LAST_LOAD_CACHE_ENABLED_SETTING);
1447-
settingsList.add(SecuritySystemIndices.MAIN_INDEX_CREATED_ON_MIGRATION_VERSION);
14481447

14491448
// hide settings
14501449
settingsList.add(Setting.stringListSetting(SecurityField.setting("hide_settings"), Property.NodeScope, Property.Filtered));

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

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -271,19 +271,10 @@ private SystemIndexDescriptor.MappingsVersion getMinSecurityIndexMappingVersion(
271271
* Check if the index was created on the latest index version available in the cluster
272272
*/
273273
private static boolean isCreatedOnLatestVersion(IndexMetadata indexMetadata) {
274-
if (indexMetadata == null) {
275-
return false;
276-
}
277-
278-
final Integer indexCreatedOnMigrationVersion = SecuritySystemIndices.MAIN_INDEX_CREATED_ON_MIGRATION_VERSION.get(
279-
indexMetadata.getSettings()
280-
);
281-
282-
// 1 is the first migration, before the MAIN_INDEX_CREATED_ON_MIGRATION_VERSION was introduced
283-
if (indexCreatedOnMigrationVersion > 1) {
284-
return indexCreatedOnMigrationVersion.equals(SecurityMigrations.MIGRATIONS_BY_VERSION.lastKey());
285-
}
286-
return SETTING_INDEX_VERSION_CREATED.get(indexMetadata.getSettings()).onOrAfter(IndexVersion.current());
274+
final IndexVersion indexVersionCreated = indexMetadata != null
275+
? SETTING_INDEX_VERSION_CREATED.get(indexMetadata.getSettings())
276+
: null;
277+
return indexVersionCreated != null && indexVersionCreated.onOrAfter(IndexVersion.current());
287278
}
288279

289280
/**

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@
4545
import static org.elasticsearch.xpack.security.support.SecuritySystemIndices.SecurityMainIndexMappingVersion.ADD_MANAGE_ROLES_PRIVILEGE;
4646
import static org.elasticsearch.xpack.security.support.SecuritySystemIndices.SecurityMainIndexMappingVersion.ADD_REMOTE_CLUSTER_AND_DESCRIPTION_FIELDS;
4747

48-
/**
49-
* Interface for creating SecurityMigrations that will be automatically applied once to existing .security indices
50-
*/
5148
public class SecurityMigrations {
5249

5350
/**

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import org.elasticsearch.cluster.routing.allocation.DataTier;
1717
import org.elasticsearch.cluster.service.ClusterService;
1818
import org.elasticsearch.common.VersionId;
19-
import org.elasticsearch.common.settings.Setting;
2019
import org.elasticsearch.common.settings.Settings;
2120
import org.elasticsearch.features.FeatureService;
2221
import org.elasticsearch.features.NodeFeature;
@@ -64,16 +63,6 @@ public class SecuritySystemIndices {
6463
public static final NodeFeature SECURITY_ROLES_METADATA_FLATTENED = new NodeFeature("security.roles_metadata_flattened");
6564
public static final NodeFeature SECURITY_ROLE_MAPPING_CLEANUP = new NodeFeature("security.role_mapping_cleanup");
6665

67-
/**
68-
* The latest version of the security migration when the main security index was created
69-
*/
70-
public static final Setting<Integer> MAIN_INDEX_CREATED_ON_MIGRATION_VERSION = Setting.intSetting(
71-
"index.security.migration.version",
72-
0,
73-
Setting.Property.IndexScope,
74-
Setting.Property.Final
75-
);
76-
7766
/**
7867
* Security managed index mappings used to be updated based on the product version. They are now updated based on per-index mappings
7968
* versions. However, older nodes will still look for a product version in the mappings metadata, so we have to put <em>something</em>
@@ -170,7 +159,6 @@ private static Settings getMainIndexSettings() {
170159
.put(DataTier.TIER_PREFERENCE, "data_hot,data_content")
171160
.put(IndexMetadata.SETTING_PRIORITY, 1000)
172161
.put(IndexMetadata.INDEX_FORMAT_SETTING.getKey(), INTERNAL_MAIN_INDEX_FORMAT)
173-
.put(MAIN_INDEX_CREATED_ON_MIGRATION_VERSION.getKey(), SecurityMigrations.MIGRATIONS_BY_VERSION.lastKey())
174162
.put("analysis.filter.email.type", "pattern_capture")
175163
.put("analysis.filter.email.preserve_original", true)
176164
.putList("analysis.filter.email.patterns", List.of("([^@]+)", "(\\p{L}+)", "(\\d+)", "@(.+)"))

x-pack/plugin/security/src/test/java/org/elasticsearch/xpack/security/SecurityTests.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,7 @@ private Collection<Object> createComponentsUtil(Settings settings) throws Except
209209
settings = Security.additionalSettings(settings, true);
210210
Set<Setting<?>> allowedSettings = new HashSet<>(Security.getSettings(null));
211211
allowedSettings.addAll(ClusterSettings.BUILT_IN_CLUSTER_SETTINGS);
212-
ClusterSettings clusterSettings = new ClusterSettings(
213-
settings,
214-
allowedSettings.stream().filter(Setting::hasNodeScope).collect(Collectors.toSet())
215-
);
212+
ClusterSettings clusterSettings = new ClusterSettings(settings, allowedSettings);
216213
when(clusterService.getClusterSettings()).thenReturn(clusterSettings);
217214
when(threadPool.relativeTimeInMillis()).thenReturn(1L);
218215
threadContext = new ThreadContext(Settings.EMPTY);

0 commit comments

Comments
 (0)