-
Notifications
You must be signed in to change notification settings - Fork 25.8k
Fix internal cluster and single node security tests #121466
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
Merged
slobodanadamovic
merged 28 commits into
elastic:main
from
slobodanadamovic:sa-fix-internal-cluster-tests
Feb 16, 2025
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
6572e47
Fix internal cluster tests
slobodanadamovic 25eacc0
Merge branch 'main' into sa-fix-internal-cluster-tests
slobodanadamovic ce30661
[CI] Auto commit changes from spotless
71d4960
Merge branch 'main' of github.com:elastic/elasticsearch into sa-fix-i…
slobodanadamovic e0703e7
unmute tests
slobodanadamovic 82704bc
Merge branch 'sa-fix-internal-cluster-tests' of github.com:slobodanad…
slobodanadamovic d288305
Merge branch 'main' of github.com:elastic/elasticsearch into sa-fix-i…
slobodanadamovic 8c629d0
fix merge conflict
slobodanadamovic 042de75
revert draft changes
slobodanadamovic 974703d
revert new line change
slobodanadamovic 2fca9c8
fix security single note tests by cleaning up and creating security i…
slobodanadamovic 112d9d8
increase timeout
slobodanadamovic 3fd7f4c
Merge branch 'main' of github.com:elastic/elasticsearch into sa-fix-i…
slobodanadamovic 43d62b4
revert TestCluster changes
slobodanadamovic df96e0d
Merge branch 'main' into sa-fix-internal-cluster-tests
slobodanadamovic b22b781
ensure no initializing shards before wiping the cluster during setup
slobodanadamovic 5401a0d
Merge branch 'main' into sa-fix-internal-cluster-tests
slobodanadamovic 08b6f1c
Merge branch 'main' into sa-fix-internal-cluster-tests
slobodanadamovic e83611f
revert adding ensureNoInitializingShardsBeforeWipingCluster
slobodanadamovic a0feb24
avoid assigning anonymous role with app privileges to the root user
slobodanadamovic 92f7469
Merge branch 'sa-fix-internal-cluster-tests' of github.com:slobodanad…
slobodanadamovic 0314186
Merge branch 'main' of github.com:elastic/elasticsearch into sa-fix-i…
slobodanadamovic d2587b1
Merge branch 'main' into sa-fix-internal-cluster-tests
slobodanadamovic dd587d1
Merge branch 'main' into sa-fix-internal-cluster-tests
slobodanadamovic f677c7b
Merge branch 'main' into sa-fix-internal-cluster-tests
slobodanadamovic 7ba289f
Merge branch 'main' into sa-fix-internal-cluster-tests
slobodanadamovic 09588d0
Merge branch 'main' into sa-fix-internal-cluster-tests
slobodanadamovic 294aaf1
Merge branch 'main' into sa-fix-internal-cluster-tests
slobodanadamovic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,17 +8,10 @@ | |
| package org.elasticsearch.xpack.security.authc.esnative; | ||
|
|
||
| import org.elasticsearch.action.admin.cluster.settings.ClusterUpdateSettingsRequest; | ||
| import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; | ||
| import org.elasticsearch.action.admin.indices.get.GetIndexRequest; | ||
| import org.elasticsearch.action.admin.indices.get.GetIndexResponse; | ||
| import org.elasticsearch.action.support.IndicesOptions; | ||
| import org.elasticsearch.client.Request; | ||
| import org.elasticsearch.client.RequestOptions; | ||
| import org.elasticsearch.client.ResponseException; | ||
| import org.elasticsearch.cluster.ClusterState; | ||
| import org.elasticsearch.cluster.metadata.IndexMetadata; | ||
| import org.elasticsearch.cluster.metadata.Metadata; | ||
| import org.elasticsearch.cluster.service.ClusterService; | ||
| import org.elasticsearch.common.Strings; | ||
| import org.elasticsearch.common.settings.MockSecureSettings; | ||
| import org.elasticsearch.common.settings.SecureString; | ||
|
|
@@ -29,14 +22,9 @@ | |
| import org.elasticsearch.xpack.core.security.action.user.PutUserRequest; | ||
| import org.elasticsearch.xpack.core.security.authc.support.Hasher; | ||
| import org.elasticsearch.xpack.core.security.authc.support.UsernamePasswordToken; | ||
| import org.elasticsearch.xpack.core.security.test.TestRestrictedIndices; | ||
| import org.junit.BeforeClass; | ||
|
|
||
| import java.util.concurrent.CountDownLatch; | ||
|
|
||
| import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; | ||
| import static org.elasticsearch.xpack.core.security.action.UpdateIndexMigrationVersionAction.MIGRATION_VERSION_CUSTOM_KEY; | ||
| import static org.elasticsearch.xpack.security.support.SecuritySystemIndices.SECURITY_MAIN_ALIAS; | ||
| import static org.hamcrest.Matchers.is; | ||
|
|
||
| public class ReservedRealmElasticAutoconfigIntegTests extends SecuritySingleNodeTestCase { | ||
|
|
@@ -70,46 +58,10 @@ protected SecureString getBootstrapPassword() { | |
| return null; // no bootstrap password for this test | ||
| } | ||
|
|
||
| private boolean isMigrationComplete(ClusterState state) { | ||
| IndexMetadata indexMetadata = state.metadata().getIndices().get(TestRestrictedIndices.INTERNAL_SECURITY_MAIN_INDEX_7); | ||
| return indexMetadata != null && indexMetadata.getCustomData(MIGRATION_VERSION_CUSTOM_KEY) != null; | ||
| } | ||
|
|
||
| private void awaitSecurityMigrationRanOnce() { | ||
| final var latch = new CountDownLatch(1); | ||
| ClusterService clusterService = getInstanceFromNode(ClusterService.class); | ||
| clusterService.addListener((event) -> { | ||
| if (isMigrationComplete(event.state())) { | ||
| latch.countDown(); | ||
| } | ||
| }); | ||
| if (isMigrationComplete(clusterService.state())) { | ||
| latch.countDown(); | ||
| } | ||
| safeAwait(latch); | ||
| } | ||
|
|
||
| private void deleteSecurityIndex() { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Renamed this one and moved it into |
||
| // delete the security index, if it exist | ||
| GetIndexRequest getIndexRequest = new GetIndexRequest(TEST_REQUEST_TIMEOUT); | ||
| getIndexRequest.indices(SECURITY_MAIN_ALIAS); | ||
| getIndexRequest.indicesOptions(IndicesOptions.lenientExpandOpen()); | ||
| GetIndexResponse getIndexResponse = client().admin().indices().getIndex(getIndexRequest).actionGet(); | ||
| if (getIndexResponse.getIndices().length > 0) { | ||
| assertThat(getIndexResponse.getIndices().length, is(1)); | ||
| assertThat(getIndexResponse.getIndices()[0], is(TestRestrictedIndices.INTERNAL_SECURITY_MAIN_INDEX_7)); | ||
|
|
||
| // Security migration needs to finish before deleting the index | ||
| awaitSecurityMigrationRanOnce(); | ||
| DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(getIndexResponse.getIndices()); | ||
| assertAcked(client().admin().indices().delete(deleteIndexRequest).actionGet()); | ||
| } | ||
| } | ||
|
|
||
| public void testAutoconfigFailedPasswordPromotion() throws Exception { | ||
| try { | ||
| // .security index is created automatically on node startup so delete the security index first | ||
| deleteSecurityIndex(); | ||
| deleteSecurityIndexIfExists(); | ||
| // prevents the .security index from being created automatically (after elastic user authentication) | ||
| ClusterUpdateSettingsRequest updateSettingsRequest = new ClusterUpdateSettingsRequest( | ||
| TEST_REQUEST_TIMEOUT, | ||
|
|
@@ -176,7 +128,7 @@ public void testAutoconfigSucceedsAfterPromotionFailure() throws Exception { | |
| putUserRequest.roles(Strings.EMPTY_ARRAY); | ||
| client().execute(PutUserAction.INSTANCE, putUserRequest).get(); | ||
| // Security migration needs to finish before making the cluster read only | ||
| awaitSecurityMigrationRanOnce(); | ||
| awaitSecurityMigration(); | ||
|
|
||
| // but then make the cluster read-only | ||
| ClusterUpdateSettingsRequest updateSettingsRequest = new ClusterUpdateSettingsRequest( | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed these as they are somewhat duplicates of existing methods in
SecuritySingleNodeTestCaseclass.